Jump to content

[SOLVED] myql query help


clanstyles

Recommended Posts

mysql_query("UPDATE (`name`, `email`, `aim`, `msn`, `yahoo`,`icq`)

VALUES('".$_POST['name']."',

'".cleanStr($_POST['email'])."',

'".cleanStr($_POST['aim'])."',

'".cleanStr($_POST['msn'])."',

'".cleanStr($_POST['yahoo'])."',

'".cleanStr($_POST['icq'])."'") or die(mysql_error());

produces:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES('Peter', 'xxxxxxxxxxxxxxxxxxxxxxx', '', '', '', ' at line 2

Link to comment
https://forums.phpfreaks.com/topic/60619-solved-myql-query-help/
Share on other sites

You havn't provided a table name. You have only listed the columns to be updated. UPDATE requires a table name followed by the columns and their values, eg:

UPDATE tbl_name ('col1', 'col2', 'col3' etc) VALUES ('value1', 'value2', 'value3' etc)

Dude i have no idea what i was thinking when I posted this lol. I was missnig like 5 things. Im missing a ) at the end and like to chose what row ect... Thanks though forgot that also.

 

But heres what i have now and it wont work.

 

mysql_query("UPDATE `accounts` SET(`name`, `email`, `aim`, `msn`, `yahoo`,`icq`) values('$value1','$value2','$value3','$value4','$value5','$value6') WHERE `id`='".$_SESSION['id']."'") or die(mysql_error());

ahh sorry heres the table ill just giv eu it

 

CREATE TABLE `accounts` (

  `id` int(11) NOT NULL auto_increment,

  `name` varchar(255) NOT NULL,

  `username` varchar(255) NOT NULL,

  `password` varchar(255) NOT NULL,

  `email` varchar(255) NOT NULL,

  `aim` varchar(255) NOT NULL,

  `msn` varchar(255) NOT NULL,

  `yahoo` varchar(255) NOT NULL,

  `icq` varchar(255) NOT NULL,

  `ip` varchar(255) NOT NULL,

  `hash` varchar(255) NOT NULL,

  `verified` int(11) NOT NULL,

  `rank` varchar(255) NOT NULL,

  PRIMARY KEY  (`id`)

) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;

this is the code i came up with:

 

$id = $_SESSION['id'];

if($_POST['update']){
$value1 = $_POST['name'];
$value2 = $_POST['email'];
$value3 = $_POST['aim'];
$value4 = $_POST['msn'];
$value5 = $_POST['yahoo'];
$value6 = $_POST['icq'];
$update = "UPDATE `test`.`accounts` SET `name` = '$value1',
`email` = '$value2',
`aim` = '$value3',
`msn` = '$value4',
`yahoo` = '$value5',
`icq` = '$value6' WHERE `accounts`.`id` = '$id'";
$updateCheck = mysql_query("SELECT * FROM `accounts` WHERE `id` = '$id");
if(mysql_num_rows(mysql_query("SELECT * FROM `accounts` WHERE `id` = '$id'")) == "0"){
	mysql_query("INSERT INTO `accounts` (`id`,`name`, `email`, `aim`, `msn`, `yahoo`,`icq`)VALUES('$id','$value1','$value2','$value3','$value4','$value5','$value6');");
	echo "User inserted properly";
}
else
{
	$zz = mysql_query($update);
	if(!$zz){
		echo "Error: Cannot update row";
	}
	else
	{
		echo "Update sucessfull";
	}
}
}
?>

 

worked on PHP 5.2.2 and mysql 5.0.41

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.