Chris M. Chris M. - 3 months ago 7
PHP Question

SQL update statement shows emptie records

I am trying to add content to the database with this form. Everytime I submit I get an error that

$h_title
,
$b_title
,
$f_title
are
undefined
and my table shows up with empty records.

Does someone know why this occurs? And if so could you help me with the solution? Thank you!

The settings in my table match the ones written in the code.

<?php //header_title, title & footer_title
if (isset($_POST['submit'])) {

$layout_id = 1;
$h_title = mysql_prep($_POST["h_title"]);
$b_title = mysql_prep($_POST["b_title"]);
$f_title = mysql_prep($_POST["f_title"]);

$query = "UPDATE layout1 SET ";
$query .= "h_title = '{$h_title}', ";
$query .= "b_title = '{$b_title}', ";
$query .= "f_title = '{$f_title}' ";
$query .= "WHERE id = {$layout_id}";
$result = mysqli_query($connection, $query);

if ($result && mysqli_affected_rows($connection) == 1) {
//success
$_SESSION["message"] = "header/footer/title updated";
} else {
$_SESSION["message"] = "Update failed";
}
}
?>

<form action="website_design.php" method="post">
<h3>Edit header and footer titels</h3>
<p>Header title: <input type"text" name"h_title" value"" />
<br><br>Website Title: <input type"text" name"b_title" value"" />
<br><br>Footer title: <input type"text" name"f_title" value"" />
</p>
<input type="submit" name="submit" value="Edit" />
</form>

Answer
<p>Header title:          <input type"text" name"h_title" value"" />
<br><br>Website Title:    <input type"text" name"b_title" value"" />
<br><br>Footer title:     <input type"text" name"f_title" value"" />
</p>

Typo mistake. Missing = signs.

Should be <input type="text" name="h_title" value="" />.

Same for the other 2 lines.

Comments