petenaylor Posted June 18, 2009 Share Posted June 18, 2009 Hi all I am in the process of creating a PHP / mySQL based survey. It consists of 4 pages each with a form that sends information to a mySQL database. The first record adds perfectly and the next 3 pages add into the same record as they should using the update function. But when the survey is filled in from the start again, the second page results are added to all of the records in the database not just the last inserted one. Here's the code: @$pfw_strQuery = "UPDATE `29052009` SET `page2`='$page2_info'"; Can anyone help? Thanks Pete Quote Link to comment https://forums.phpfreaks.com/topic/162732-php-updates-all-records-in-mysql-database/ Share on other sites More sharing options...
Adam Posted June 18, 2009 Share Posted June 18, 2009 You need to add a 'WHERE' clause to the end so you can control which records are updated: http://www.w3schools.com/php/php_mysql_update.asp (take a look at first example) Quote Link to comment https://forums.phpfreaks.com/topic/162732-php-updates-all-records-in-mysql-database/#findComment-858770 Share on other sites More sharing options...
petenaylor Posted June 18, 2009 Author Share Posted June 18, 2009 Hi there I've tried this: @$pfw_strQuery = "UPDATE `29052009` SET `page2`='$page2_info' WHERE `id` = LAST_INSERT_ID()"; But no data is sent into the database, is the syntax incorrect? My database does have an 'id' field which is auto increment and the primary key. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/162732-php-updates-all-records-in-mysql-database/#findComment-858780 Share on other sites More sharing options...
Adam Posted June 18, 2009 Share Posted June 18, 2009 Why do you have an @ before a variable? They suppress errors. You are running the query after aren't you? If so, after the mysql_query function add: or trigger_error('Query failed: ' . mysql_error($db), E_USER_ERROR); So it would look something like: $var = mysql_query(...) or trigger_error('Query failed: ' . mysql_error($db), E_USER_ERROR); Quote Link to comment https://forums.phpfreaks.com/topic/162732-php-updates-all-records-in-mysql-database/#findComment-858785 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.