clanstyles Posted July 18, 2007 Share Posted July 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 18, 2007 Share Posted July 18, 2007 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) Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 18, 2007 Author Share Posted July 18, 2007 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()); Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 18, 2007 Author Share Posted July 18, 2007 BuMP! Quote Link to comment Share on other sites More sharing options...
lewis987 Posted July 18, 2007 Share Posted July 18, 2007 hang on, ill test it on my server with dummy data Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 18, 2007 Author Share Posted July 18, 2007 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 ; Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 18, 2007 Share Posted July 18, 2007 i was under the impression you need to explicitly state each UPDATE action. i don't think the (columns) VALUES (values) syntax is supported for an UPDATE statement. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 18, 2007 Author Share Posted July 18, 2007 rofl am i like so tired that im combing two differen't things? Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 18, 2007 Share Posted July 18, 2007 the manual is usually the first place you should look: http://dev.mysql.com/doc/refman/4.1/en/update.html Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 18, 2007 Share Posted July 18, 2007 I believe it should be like this UPDATE table SET value1 = '" . $variable1 . "', value2 = '" . $variable2 . "' WHERE value = '" . $x . "' and so on Quote Link to comment Share on other sites More sharing options...
lewis987 Posted July 18, 2007 Share Posted July 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 18, 2007 Author Share Posted July 18, 2007 thx a lot..Yeah i was messing up bad. lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.