Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5132

Re: combobox

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: combobox
Date 2012-03-08 08:58 -0500
Organization A noiseless patient Spider
Message-ID <jjadu2$lhp$1@dont-email.me> (permalink)
References <aba0a15d-4c4c-47fa-a1a2-9073b9a5802e@j5g2000yqm.googlegroups.com> <jj9jiu$h4h$1@dont-email.me> <39c3d4ef-dbc4-480f-8e28-5a8ecd5401cd@y17g2000yqg.googlegroups.com>

Show all headers | View raw


On 3/8/2012 8:27 AM, ecu_jon wrote:
> here is page5
> there is the first 6 lines that set up stuff to connect to db.
> the 4 if isset's get the Post variables from inputpage(above)
> then the mysql insert into db command.
> and it looks like it mangled the longer lines. the sql statement will
> probably come out weird.
> <html>
> <head>
> <link rel="stylesheet" type="text/css" href="mystyle.css" />
> <?php
> $Status = $_POST["Status"];
> $host="localhost"; // Host name
> $username="user"; // Mysql username
> $password="password"; // Mysql password
> $db_name="name"; // Database name
> $tbl_name="name"; // Table name
> mysql_connect("$host", "$username", "$password")or die("cannot
> connect"); //sql connection to db
> mysql_select_db("$db_name")or die("cannot select DB"); //select db sql
> command
> if(isset($_POST['Client'])) $Client = $_POST['Client']; //check if
> value from POST, sev variable to value
> if(isset($_POST["Site"])) $Site = $_POST["Site"];
> if(isset($_POST["Uname"])) $Uname = $_POST["Uname"];
> if(isset($_POST["Uid"])) $Uid = $_POST["Uid"];
> if(isset($_POST["Password"]))	$Password = $_POST["Password"];
> mysql_query("INSERT INTO client
> (client, site, user, userid, password, status) VALUES('$Client',
> '$Site', '$Uname', '$Uid', '$Password', '$Status') ")
> or die(mysql_error());  //insert above variables into db
> echo "user added".$Client;
> mysql_close();
> ?>
> <br><br>
> <a href="./login_success.php">Back Home</a>
> </body>
> </html>
>

What a mess.

First of all, as Scott indicated, if you want help, make the effort to 
clean up your code.  This may mean you actually have to do something 
other than cut and paste - that is, you might have to actually put a 
little effort into formatting your test.

Also, you never posted the contents of the $_POST superglobal like Scott 
asked.

As to your problems.  First of all, don't use "or die('message')" in 
production code.  This will send invalid HTML to the browser (i.e. it 
terminates all output in the middle of the page).  If the query fails, 
handle it gracefully (and perhaps log the error so you can see what 
happened later).

Your select box has a name of "option", but you are never referring to 
that item on your second page.  That's why you're not getting anything.

You're checking to see if $_POST('Client') is set, which is good.  But 
what happens if it's not set (the same for the rest of your values)? 
You're still going to try to insert the data into the database, which 
will result in an invalid SQL statement.

Also, try to insert the name "O'Casey".  It will fail.  ALL strings used 
in SQL statements need to be processed by mysql_real_escape_string().

That's a place for you to start, anyway.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

combobox ecu_jon <hayesjonathand@gmail.com> - 2012-03-07 13:15 -0800
  Re: combobox Scott Johnson <noonehome@chalupasworld.com> - 2012-03-07 22:28 -0800
    Re: combobox ecu_jon <hayesjonathand@gmail.com> - 2012-03-08 05:27 -0800
      Re: combobox Jerry Stuckle <jstucklex@attglobal.net> - 2012-03-08 08:58 -0500
      Re: combobox ecu_jon <hayesjonathand@gmail.com> - 2012-03-08 06:21 -0800
        Re: combobox Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-03-09 11:06 +0100

csiph-web