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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ibanezrg770
Forum Newbie
Posts: 4
Joined: Tue May 20, 2003 9:05 pm

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

Post 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!!!
Last edited by ibanezrg770 on Wed May 21, 2003 7:47 am, edited 2 times in total.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

clutter indeed. :o
User avatar
Wayne Herbert
Forum Commoner
Posts: 34
Joined: Tue Apr 29, 2003 3:13 pm
Location: Houston, Texas

That's a Gawd Awfull Mess!

Post 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>">.
tr3s
Forum Newbie
Posts: 17
Joined: Mon May 19, 2003 10:29 am
Location: Philippines
Contact:

Post 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, ...)";
?>
ibanezrg770
Forum Newbie
Posts: 4
Joined: Tue May 20, 2003 9:05 pm

Post 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!!!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
ibanezrg770
Forum Newbie
Posts: 4
Joined: Tue May 20, 2003 9:05 pm

Post 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!!!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Yes, all of the superglobals $_POST, $_GET, $_SERVER et. al. are arrays.

Mac
Post Reply