Forum Moderators: coopster

Message Too Old, No Replies

help!

writeing html form data to mysql db

         

neonerz

10:49 pm on Oct 29, 2003 (gmt 0)

10+ Year Member



ok this is gonna prob sound like such a simple problem but i'm new to php so i'm trying

i have a html form with 3 simple text boxes, "user, addy, webpage" when i hit submit i wanna have the info in the boxes saved in my db members under "name,email,website" i've noticed if i name the form elements the same as the coloum names it will pose a problem.

i'm not asking for the code, but for someone to look at my code and point me in the right direction

<!---html code---!>
<form action="mysql2.php" method="POST">
Your name: <input type="text" name="user" value="user"/>
Your emailput type="text" name="addy" value="addy" />
Your webpaget type="text" name="webpage" value="webpage"/>
<input type="submit">
</form>
<!---end html code---!>

<!---php code---!>
<?php
$connection = mysql_connect("localhost", "neonerz", "password") or die("Error connecting to database");
mysql_select_db("neonerz_members", $connection);
$query = "INSERT INTO members (name , email , website ) VALUES ( $_GET["user"] , $_GET["addy"] , $_GET["webpage"] )";
/*`*/
$result = MYSQL_QUERY($query);

?>
<!---end php code---!>

thanx for any help you might be able to offer me

bcolflesh

10:51 pm on Oct 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are POSTing the form, yet asking for GET variables in your script.

neonerz

11:40 pm on Oct 29, 2003 (gmt 0)

10+ Year Member



i'm sorry i should of changed that i'm using POST but i just tried GET just to see if it would work sorry about that

NickCoons

8:54 am on Oct 30, 2003 (gmt 0)

10+ Year Member



neonerz,

<$query = "INSERT INTO members (name , email , website ) VALUES ( $_GET["user"] , $_GET["addy"] , $_GET["webpage"] )";>

I think you may need to put tick-marks around your inserted values. Something like this may work better in the above statement:

('" . $_GET["user"] . "','" . $_GET["addy"] . "','" . $_GET["webpage"] . "')

Not sure.. just a thought. I just started using MySQL about two months ago, so I haven't yet learned all of the ins-and-outs of what formatting quirks may or may not exist :-).

neonerz

10:38 am on Oct 30, 2003 (gmt 0)

10+ Year Member



nickcoons,

thanx ALOT, but u mind explaining to me why this worked. i'm assumeing that '" . and ."' tells it not to use it as a string and /' and /' tells it to be a string?

coopster

1:32 pm on Oct 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



String and date values are specified as quoted strings. Your statement, if it were being keyed into a command line, would look like this, if your 3 fields were all string values:

INSERT INTO members (name, email, website) VALUES ('uservalue', 'addyvalue', 'webpagevalue');

So, by using the statement as NickCoons specified, you are going to get that effect:

$query = "INSERT INTO members (name , email , website ) VALUES ('" . $_GET["user"] . "','" . $_GET["addy"] . "','" . $_GET["webpage"] . "')";

The simplest way to look at that $query statement being built is to remove all the double quotes (except those inside the $_GET brackets []), replace the concatenated (.) $_GET[] variables with your data, and you'll see how the statement should look, same as the way it would being entered into a command line.

coopster

1:49 pm on Oct 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



neonerz, there are some examples in the PHP Manual regarding string types [us3.php.net] and the Array do's and don'ts [us3.php.net] will help as well.

Regards -- coopster

neonerz

2:45 pm on Oct 30, 2003 (gmt 0)

10+ Year Member



thanx alot everyone!

coopster i'm gonna look thru that page, thanx for pointing me into the right direction -=]