I am struggling, yes struggling, with Kevin Yanks Build Your Own Database Driven Web Site Using PHP & MySQL, and I have stumbled uopn something that seems to be a problem with my INSERT statement.
<?php
if (isset($_POST[‘namn’]) . isset($_POST[‘titel’]) . isset($_POST[‘polid’]))
{
$namn = mysqli_real_escape_string($link,$_POST[‘namn’]);
$polid = mysqli_real_escape_string($link,$_POST[‘polid’]);
$titel = mysqli_real_escape_string($link,$_POST[‘titel’]);
$sql = ‘INSERT INTO namn SET
namn="’ . $namn . ‘“,
polid=”’ . $polid . ‘"’;
$sql = ‘INSERT INTO titel SET
titel="’ . $titel . ‘"’;
if (!mysqli_query($link, $sql))
{
$error = 'Error adding submitted joke: ’ . mysqli_error($link);
include ‘includes_error.php’;
exit();
}
header(‘Location: .’);
exit();
}
?>
If I remove the INSERT INTO titel statement it works, but if I don’t it breaks. Anybody who can see what I am doing wrong? namn and titel are two separate tables.
The insert only happens why you tell it to mysqli_query.
Here’s what your script does:
Set $sql to “INSERT INTO namn …”
Set $sql to “INSERT INTO titel …” (At this point, the old value of $sql is lost)
Execute $sql.