Forum Moderators: coopster

Message Too Old, No Replies

PHP: passing variable to mysql

why doesnt this work?

         

benihana

10:54 pm on Mar 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi
I have a simple form to pass a single value to mysql database:

<form method="post" action="addemail.php">
<input type="text" name="address">
<input type="submit" value="submit">
</form>

addemail.php contains:

<?php
$sql="INSERT INTO table set email='$address'";

if (mysql_query($sql)){
echo("added");
};

When i submit anything it just adds a null value to the database.

if i surround $address with other charcters, these get added but the actual $address is ignored.

any ideas?
thanks

jatar_k

10:58 pm on Mar 10, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you have register_globals on it should work, if not it won't

try this way
$sql="INSERT INTO table set email='" . $_POST['address'] . "'";

I have had weird problems sometimes when the var is in between the quotes sometimes. I am not sure why but when it is cat'ed together it always works.

benihana

11:09 pm on Mar 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how do i switch register globals on?
its abrand new install of php and i havent changed anything
thanks

edit > using $_POST['address'] didnt work :(

[edited by: benihana at 11:12 pm (utc) on Mar. 10, 2003]

jatar_k

11:12 pm on Mar 10, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if it is a brand new install then register_globals will be off by default. You don't have to turn it on there are various security probs with it being on.

Did you try the little snippet to see if it worked?

Using Register Globals [php.net]

benihana

11:15 pm on Mar 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



no didnt work. not to wor\ried about security as its only needed for a one off conference - not going live on web.

thanks

benihana

11:21 pm on Mar 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SORRY!
ive been looking at the same 8 lines of code to long.
id missed the _ after POST

it works im saved!
thanks v much