Jump to content

PHP updates all records in mySQL database.


petenaylor

Recommended Posts

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

 

 

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

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);

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.