Jump to content

Update fields across multiple tables


WAMFT1

Recommended Posts

I am trying to setup so that I select a name from the dropdown menu (already works) then taking the ID number and using it to update multiple tables. I cannot get it to update anything. I don't really know what I am doing here, I thought based on other coding I have used that this would be simple. Please Help??

<?
require('../edb.php');
$aid =$_REQUEST['aid'];

if (isset($_POST['Submit'])) { 
    $mysql_query1("UPDATE `adocs_ar_cert` SET Current='N' WHERE AdviserCode='$aid'");
    $mysql_query2("UPDATE `adocs_cpd` SET Current='N' WHERE AdviserCode='$aid'");
    $mysql_query3("UPDATE `adocs_fds` SET Current='N' WHERE AdviserCode='$aid'");
    $mysql_query4("UPDATE `adocs_fsg_profile` SET Current='N' WHERE AdviserCode='$aid'");
    $mysql_query5("UPDATE `adocs_sapl` SET Current='N' WHERE AdviserCode='$aid'");
}?>
Link to comment
https://forums.phpfreaks.com/topic/294575-update-fields-across-multiple-tables/
Share on other sites

You'll want to review the documentation for the mysql_query() function:

http://php.net/manual/en/function.mysql-query.php

 

Basically, your queries should look more like the following:

mysql_query("UPDATE `adocs_ar_cert` SET Current='N' WHERE AdviserCode='$aid'");

Note that I removed the dollar sign and number from the call to mysql_query().

 

 

Also note that your queries are vulnerable to SQL injection attacks. Since it looks like $aid is a string, you want to escape the value with the following function:

http://php.net/manual/en/function.mysql-real-escape-string.php

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.