When we try to update, all the outputs ("Successful step") 1,2,4,5 are shown. But when we try to check the database, only the 1st database was able to do the update.
$host = "172.16.1.16";
$user = "root";
$password = "root";
$dbname1 = "nocs";
$dbname2 = "nocs_backup";
Here is the first database
$db1 = new mysqli($host, $user, $password, $dbname1);
if($db1->connect_errno > 0){
die('Unable to connect to database' . $db1->connect_error);
}
else
{
$updateComponentSql = "UPDATE component
SET `Component_name`='$name', `Brand`='$brand',
`Model`='$model', `Type`='$type',
`Capacity`='$capacity',`Serial_no`='$serial',
`Description`='Installed'
WHERE `Component_id`='$d_id'
AND `computer_id`='$c_id'";
if (mysqli_query($db1, $updateComponentSql))
{
echo "<script type='text/javascript'>
alert('Succesful step 1');
</script>";
}
Here is the second
$db2 = mysqli_connect($host, $user, $password, $dbname2);
echo "<script type='text/javascript'>alert('Succesful step 2');</script>";
if($db2->connect_errno > 0)
{
die('Unable to connect to database' . $db2->connect_error);
echo "<script type='text/javascript'>alert('Successful step 3');</script>";
}
else
{
echo "<script type='text/javascript'>alert('Succesful step 4');</script>";
if (mysqli_query($db2, "UPDATE component
SET (`Component_name`='$name',
`Brand`='$brand', `Model`='$model',
`Type`='$type',`Capacity`='$capacity',
`Serial_no`='$serial',
`Description`='Installed'
WHERE `Component_id`='$d_id'
AND `computer_id`='$c_id)" ))
{
echo "<script type='text/javascript'>
alert('Succesful step 5');
</script>";
}
}
}
We're at our wit's end. Please help us :(
You have extraneous parentheses in the second UPDATE
query.
if (mysqli_query($db2, "UPDATE component
SET `Component_name`='$name', `Brand`='$brand', `Model`='$model',
`Type`='$type', `Capacity`='$capacity', `Serial_no`='$serial',
`Description`='Installed'
WHERE `Component_id`='$d_id' AND `computer_id`='$c_id" ))
{
echo "<script type='text/javascript'>alert('Succesful step 5');</script>";
} else {
echo "<script type='text/javascript'>alert(" . json_encode(mysqli_error($db2)) . ");</script>";
}