1

I want to update two fields in to tables at the same time but it is not work any one can help me please

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
    $updateSQL = sprintf(
        "UPDATE child,list SET child.list_num = list.list_id  WHERE child.user_id = list.user_id",
        GetSQLValueString($_POST['list_num'], "int"),
        GetSQLValueString($_POST['id'], "int")
    );

    mysql_select_db($database_amar, $amar);
    $Result1 = mysql_query($updateSQL, $amar) or die(mysql_error());

    $updateGoTo = "list_child.php";
    if (isset($_SERVER['QUERY_STRING'])) {
        $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
        $updateGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $updateGoTo));
}

$colname_edit = "-1";
if (isset($_GET['id'])) {
    $colname_edit = $_GET['id'];
}

mysql_select_db($database_amar, $amar);
$query_edit = sprintf(
    "SELECT * FROM child, list WHERE id= %s",              
    GetSQLValueString($colname_edit, "int")
);
$edit = mysql_query($query_edit, $amar) or die(mysql_error());
$row_edit = mysql_fetch_assoc($edit);
$totalRows_edit = mysql_num_rows($edit);
helmbert
  • 35,797
  • 13
  • 82
  • 95
vivi
  • 21
  • 1
  • Not working means ? Can you post the error you have ? – Sulthan Allaudeen Jun 21 '15 at 09:57
  • 6
    [Please, don't use mysql_* functions in new code.](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) They are no longer maintained and are officially deprecated. Use mysqli or PDO – PHPhil Jun 21 '15 at 10:00

1 Answers1

0

I have tried your query and its working perfect as

"UPDATE child,list SET child.list_num = list.list_id  WHERE child.user_id = list.user_id"

But i have a doubt on your implementation that why are you using sprintf here?

$updateSQL = sprintf("UPDATE child,list SET child.list_num =                      list.list_id  WHERE child.user_id = list.user_id ",
                     GetSQLValueString($_POST['list_num'], "int"),
                   GetSQLValueString($_POST['id'], "int"));

It shows that your requirements are a little different from your implementation. Either you are missing some place in your query where you want to use parameters

GetSQLValueString($_POST['list_num'], "int") and GetSQLValueString($_POST['id'], "int").

At the moment your query will update the tables without any check, it is not obeying sprintf thing. Try to

$query_edit = sprintf("SELECT * FROM child, list WHERE id= %s",               GetSQLValueString($colname_edit, "int"));