PDA

View Full Version : MySQL Sorry to ask again but...



smith.myles
August 4th, 2008, 06:07 AM
Hi.

I am having another issue with my MySQL database. I dont seem to be able to get form data to update the database. The form passes php variables using GET to an external edit file (edit.php). This file seems to be able to read the GET variables, but unable to pass on the data to the database.

The form can be found here (http://www.nardoo.co.uk/justfloating/userpageedit.php?user=test1), and the edit page here (http://www.nardoo.co.uk/justfloating/edit.php).

The code from the edit page (without my server details and user + pass or connect functions) is below:

//Define data variables
$username = $_GET['username'];
$userid = $_GET['uid'];
$name = $_GET['name'];
$aboutyou = $_GET['aboutyou'];
$doingnow = $_GET['doingnow'];
$location = $_GET['location'];
//Define SQL Action
$sql = 'UPDATE `nardooco_users`.`members` SET `name` = "$name", `doingnow` = "$doingnow", `aboutyou` = "$aboutyou", `flag` = "$flag" WHERE `members`.`id` = "$userid" LIMIT 1;';
//The following is to check the variables are being read
echo $username;
echo $doingnow;
echo $userid;
//End of Script

Any help would be greatly appreciated

simplistik
August 4th, 2008, 08:43 AM
because you're parsing the variables literally by putting them in quotes


//Define SQL Action
$sql = 'UPDATE `nardooco_users`.`members` SET `name` = "'.$name.'", `doingnow` = "'.$doingnow.'", `aboutyou` = "'.$aboutyou.'", `flag` = "'.$flag.'" WHERE `members`.`id` = '.$userid.' LIMIT 1;';

smith.myles
August 4th, 2008, 11:11 AM
Thanks, I have changed that line, but it still isnt working.

I have notice that the $sql is formatted like a variable, with the $ infront. Do I have to execute that SQL somehow then, or just let it lie?

agnus
August 5th, 2008, 03:52 AM
The content stored in $sql is simply a string. To make a MySQL query, you use mysql_query($sql). Check the php manual for more instructions and examples.