Can't update new data into table.
My Tables Structure:
Table book:
-id (Primary, Auto Increment, INT)
-title
-publisher_id (Foreign key to Table publisher.pub_id, INT)
Table publisher:
-pub_id (Primary, Auto Increment, INT)
-pub_name
What I want to do is update new data into TABLE book, but can't. I couldn't find where is wrong.
Code:
<?php
if($_POST){
$uid = $_GET['id'];
$title = mysqli_real_escape_string($mysqli, $_POST['title']);
$publisher = mysqli_real_escape_string($mysqli, $_POST['publisher']);
// Update publisher
$queryid = "SELECT pub_id FROM publisher WHERE pub_name = '$publisher' ";
$result = $mysqli->query($queryid);
$pub_id = $result->fetch_assoc();
//4Update book
$query = "UPDATE book
SET
title = '$title',
publisher_id = 1
WHERE id = $uid";
$mysqli->query($query) or die();
$msg ='bookinfo updated';
header('Location: index.php?msg=' . urlencode($msg) . '');
exit;
}
?>
when I changed '$pub_id['pub_id']'
to '".$pub_id['pub_id']."'
, the "WHERE" line became yellow like the picture, ...
Changing Code like this didn't work,either:
$query = "UPDATE book
SET
title='$title',
publisher_id= 1
WHERE id= $uid";