Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can not modify more than 1 field at a time! 2

Status
Not open for further replies.

overyde

Programmer
Joined
May 27, 2003
Messages
226
Location
ZA
Hi,
I want to be able to update my info on a database. I do it by going through a form I created with the values filled in it already. My problem is when I write the SQL statement I can not get the structure right. So the database only has one field modified. How do I get the rest of the statment to be executed. It is only a basic language structure problem.

<?php
session_start();


// open the connection
$conn = mysql_connect(&quot;localhost&quot;,&quot;&quot;,&quot;&quot;);

// pick the database to use
mysql_select_db(&quot;database1&quot;, $conn);

// create the SQL statement
$sql = [&quot;UPDATE place SET address = '$_POST[address]' where specials= '$_SESSION[idno]'&quot;;
&quot;UPDATE place SET f_name = '$_POST[f_name]' where f_name= '$_SESSION[idno2]'&quot;;
&quot;UPDATE place SET l_name = '$_POST[l_name]' where l_name= '$_SESSION[idno3]'&quot;;]

// execute the SQL statment
if (mysql_query($sql, $conn)) {
echo &quot;special changed!&quot;;
}else{
echo &quot;something went wrong&quot;;
}
?>
 
have you tried putting a semicolon after every statement?

Code:
$sql = [&quot;UPDATE place SET address = '$_POST[address]' where specials= '$_SESSION[idno]';&quot;;
&quot;UPDATE place SET f_name = '$_POST[f_name]' where f_name= '$_SESSION[idno2]';&quot;;
&quot;UPDATE place SET l_name = '$_POST[l_name]' where l_name= '$_SESSION[idno3]';&quot;;]
I have never tried this before

The only thing I can find in the mysql documentation is

Try the mysql forum otherwise?

Regards,

Namida
 
anyway why don't you put it in one statement after all it's one table. Just identify whether the record is the same record by using the primary key

eg
$sql = &quot;UPDATE place SET address = '$_POST[address]', SET f_name = '$_POST[f_name]', SET l_name = '$_POST[l_name]' where specials= '$_SESSION[idno]'&quot;;

I believe you are only updating one row of record ?

eg. my id = namida
so when I update my profile you know that the whole row of table place with the id namida should be updated. It is easier to identify the whole row just by namida... rather than compare every value?

of course unless you are allowing them to change the primary key then you need to change the id first and everything else refers to the new id


Regards,

Namida
 
You really are brilliant! Thanks.
 
Hi,
Thanks for the help. Just one thing. The correct syntax is:

$sql = &quot;UPDATE place SET address = '$_POST[address]', f_name = '$_POST[f_name]', l_name = '$_POST[l_name]' where specials= '$_SESSION[idno]'&quot;;

Cheers.
 
oh yes. I totally forgot. Thanks too!

Regards,

Namida
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top