Page 1 of 1

Newbie here!!! Need help with the "$_post"???

Posted: Tue May 20, 2003 9:05 pm
by ibanezrg770
Hey guys, great site!!!
First let me say that I have read this post, http://www.devnetwork.net/forums/viewtopic.php?t=511

I will try and specify the jist of things... I am making a form that a person can type in information and then submit it and it will put it in a database. I am using
<form action="post_member.php" method="POST"> to do this.

My fields have the variable names 'nickname',' f_name',' l_name',' city', 'state', etc.... Here is an example:

printf('<input type="text" size="20" name="nickname" ><input type="text" size="20" name="F_Name" ><input type="text" size="20" name="L_Name" >

If I call the variables up using echo $_post['nickname'], it will display the variable for 'nickname'. But when I use the variable with the Insert command ie;

$sql = "INSERT INTO members (nickname) VALUES ($_POST['nickname'])";

I get Notice: Undefined variable: _post in D:\Web\Tim\gonzo\post_member.php on line 6

I know there is something stupid and easy I am missing, I just can't figure out what. Thanks for your help and again, sorry for the clutter.
Timmay!!!

Posted: Tue May 20, 2003 9:42 pm
by m3mn0n
clutter indeed. :o

That's a Gawd Awfull Mess!

Posted: Tue May 20, 2003 9:48 pm
by Wayne Herbert
You think you could tidy that code up a tad, then put it into php headers so we could see the gist of the problem? I get bored after about 8 lines of <color = "<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>">.

Posted: Tue May 20, 2003 11:32 pm
by tr3s
try enclosing

Code: Select all

$_POST&#1111;'nickname']
with single quotes. note that string values should be always enclosed with quotes. check the mysql manual for further reference.

e.g.:

Code: Select all

<?php
   $sql="INSERT INTO tablename (fieldname1, fieldname2, ...) VALUES ('strvalue', numvalue, ...)";
?>

Posted: Wed May 21, 2003 7:30 am
by ibanezrg770
Hey guys, thanks for the replys, I will try and specify the jist of things... I am making a form that a person can type in information and then submit it and it will put it in a database. I am using
<form action="post_member.php" method="POST"> to do this.

My fields have the variable names 'nickname',' f_name',' l_name',' city', 'state', etc.... Here is an example:

printf('<input type="text" size="20" name="nickname" ><input type="text" size="20" name="F_Name" ><input type="text" size="20" name="L_Name" >

If I call the variables up using echo $_post['nickname'], it will display the variable for 'nickname'. But when I use the variable with the Insert command ie;

$sql = "INSERT INTO members (nickname) VALUES ($_POST['nickname'])";

I get Notice: Undefined variable: _post in D:\Web\Tim\gonzo\post_member.php on line 6

I know there is something stupid and easy I am missing, I just can't figure out what. Thanks for your help and again, sorry for the clutter. Timmay!!!

Posted: Wed May 21, 2003 8:03 am
by twigletmac
Instead of:

Code: Select all

$sql = "INSERT INTO members (nickname) VALUES ($_POST['nickname'])";
you can do

Code: Select all

$sql = "INSERT INTO members (nickname) VALUES ('{$_POST['nickname']}')";

or

Code: Select all

$sql = "INSERT INTO members (nickname) VALUES ('".$_POST['nickname']."')";
or

Code: Select all

$sql = "INSERT INTO members (nickname) VALUES ('$_POST[nickname]')";
Mac

Posted: Wed May 21, 2003 8:33 am
by ibanezrg770
THAT WORKED!!!!

Thanks Mac, I knew it was something easy. So would I be correct that basically the $_POST is am array variable? Thanks again!!! Timmay!!!

Posted: Wed May 21, 2003 9:18 am
by twigletmac
Yes, all of the superglobals $_POST, $_GET, $_SERVER et. al. are arrays.

Mac