...

View Full Version : $_Post variable not updating in table



cyborgoddess
07-13-2006, 07:15 PM
Hello - this should be an easy script, but for some reason the 'address' variable isn't getting input into the database where the hardcoded 'list' field is.
I'm running MySQL 4.1.10 on a unix box.

Thanks in advance.


<form action="reply.php" method="post">
E-mail:
<input name="address" type="text" id="address" />
<input name="Submit" type="submit" id="Submit" value="Submit" />
</form></font>
</p>




<?
include("/XX/XX/include/dbinfo.inc.php");
$address= $_POST['address'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO email (address, list) VALUES ('$address','registrar')";
mysql_query($query);

mysql_close();
?>

Brandoe85
07-13-2006, 07:20 PM
Hi,

echo $_POST['address']; and see if you get the correct value. If not, try echoing $address before you assign it.

Good luck;

cyborgoddess
07-13-2006, 07:35 PM
It comes back fine with
echo "address is $address";

Thanks for the tip though :-)

TheShaner
07-13-2006, 08:24 PM
It comes back fine with
echo "address is $address";

Thanks for the tip though :-)
So it displays the address that has been typed? If so, then try echoing your SQL and see what that looks like.

Post back with what you see in your browser for: echo $query;

-Shane

cyborgoddess
07-13-2006, 08:43 PM
<!-- email submit form -->
<form action="echo.php" method="post">
E-mail:
<input name="address" type="text" id="address" />
<input name="Submit" type="submit" id="Submit" value="Submit" />
</form>
<!-- php-mysql script BE SURE TO CHANGE line 24 ('$list')to department name -->





<?
include("/XXX/XXX/include/dbinfo.inc.php");
$address= $_POST['address'];
$list=$_POST['list'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO email VALUES ('','$email', 'registrar')";
mysql_query($query);
mysql_close();
echo $query
?>


now here is the interesting part:
this is what it echos back:
INSERT INTO email VALUES ('','', 'registrar')

So it is recognizing the insert of the first field (auto-number) and recognizing the last field (list ="registrar" but the query isn't posting the variable which PHP recognizes (I think?)

Fumigator
07-13-2006, 09:35 PM
$query = "INSERT INTO email VALUES ('','$email', 'registrar')";

That's not going to work. PHP doesn't parse out $email as a variable, but as part of the string. You need to break the variable out from the quoted part of the string.


$query = "INSERT INTO email VALUES ('','" . $email . "', 'registrar')";

Brandoe85
07-13-2006, 09:45 PM
$query = "INSERT INTO email VALUES ('','$email', 'registrar')";

That's not going to work. PHP doesn't parse out $email as a variable, but as part of the string. You need to break the variable out from the quoted part of the string.


$query = "INSERT INTO email VALUES ('','" . $email . "', 'registrar')";
Actually, that is perfectly valid. PHP will interpolate the variables inbetween double quotes. Now, if they were to use single quotes, it would be treated as a literal, and you would be correct. Problem I see is, you're using $email, when in fact I don't see that variable defined, I see $address.

Fumigator
07-14-2006, 07:01 AM
Ack! As I was finishing up that post I had a gut feeling I was wrong :) The $email vs. $address thing looked funny to me too but I forged ahead with my wrongness all the same!

cyborgoddess
07-14-2006, 02:03 PM
Good eyes everyone, - but I actually caught that when I posted it and went back and made the changes again and still no luck.

I think the problem isn't with the code but with the includes :



[client 134.241.55.28] PHP Warning: mysql_connect(): Access denied for user
'USER!'@'localhost' (using password: YES) in
/home/XXXX/htdocs/xxxx/Services/Registrar/index.php on line 38


USER! isn't the user I set up inside my dbinfo.inc.php

This is code is operating inside a crappy cms which has another set of includes which contain a different username and password.

When I reset my username to equal the one in the CMS include, it tells me the I can not connect to the database.

What I find odd is that I can post one part of the entry, but not the variable.

Thanks for your help everyone.

guelphdad
07-14-2006, 02:41 PM
cyborgoddess, welcome to the coding forums. May I offer two items?

1) use [ php] and [/php] tags around your php code or [ code] and [/code] tags around plain sql code. Leave the spaces out of course. These tags will help your code stand out more in the forums.

2) Please, please, please sanitize your data before inputting it into your database. Read in the php manual about using mysql_real_escape_string. If you don't use that then you are opening yourself to sql injection attacks as well as cross browser scripting attacks. You'll thank me later. :-)

cyborgoddess
07-14-2006, 02:57 PM
cyborgoddess, welcome to the coding forums. You'll thank me later. :-)

I'll thank you now, although I'm reading the manual and am not sure I totally understand the proper usage. I'm sure there must be at least 1 thread somewhere here where the finer points are debated, I'm off to find it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum