Problem with INSERT

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.

Here’s my form:

<form action=“?” method=“post”>
<input name=“namn” id=“namn” type=“text” /><br />
<input name=‘titel’ id=“titel” type=“text” /><br />
<input name=“polid” id=“polid” type=“text” /><br />
<input name=“lagg_till” type=“submit” value=“Skicka” />

Here’s the php code:

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’;
header(‘Location: .’);


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.

Thank you very much!

Please post code using the appropriate tags

<form action="?" method="post">
<input name="namn" id="namn" type="text" /><br />
<input name='titel' id="titel" type="text" /><br />
<input name="polid" id="polid" type="text" /><br />
<input name="lagg_till" type="submit" value="Skicka" />

Here's the php code:

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';
header('Location: .');


but if I don’t it breaks

What does this mean? Do you get an error? If so, what error?

While it should be:

Set $sql to “INSERT INTO namn …”
Execute $sql.
Set $sql to “INSERT INTO titel …”
Execute $sql.

Yes, that’s my two tables. What do you mean by “you’re not doing anything with your first query”?

It will not insert name.

well you’re not doing anything with your first query, for starters.

Let me see if i’m reading this right.

You’ve got two tables:
namn which has the structure:
namn VARCHAR(somenumber),
polid VARCHAR(somenumber)

and titel which has the structure:
titel VARCHAR(somenumber)


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.