I have been attempting to switch over to prepared statements, however I cant figure out why my new code no longer functions. I am new to using these and still learning but i understand it is the best practice for security. any help would be appreciated. Thank You.
<?php
$servername = "11.11.11.11";
$username = "root";
$password = "root";
$dbname = "sit";
$conn = new mysqli($servername, $username, $password,$dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$result = mysqli_query($conn, "SELECT * FROM `ourstory` ");
$values = mysqli_fetch_array($result);
if(isset($_POST['ourstory_title'])){
$ourstory_title = $_POST['ourstory_title'];
$ourstory_testimonial = $_POST['ourstory_testimonial'];
$ourstory_content = $_POST['ourstory_content'];
$ourstory->execute();
$ourstory = $conn->prepare("UPDATE ourstory SET
ourstory_title='$ourstory_title' ,
ourstory_content='$ourstory_content' ,
ourstory_testimonial='$ourstory_testimonial'
WHERE ourstory_id='1'");
$ourstory->bind_param("sss", $ourstory_title, $ourstory_content, $ourstory_testimonial);
if (mysqli_query($conn, $ourstory)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
$ourstory->close();
$conn->close();
}
?>
<form id="comment_form" method="post"
action="<?php echo $ourstory?>"
onsubmit="setTimeout(function () {
window.location.reload();
}, 10), location.reload(true);">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="85%">About Us Title</td>
</tr>
<tr>
<td>
<input class="commentarea"
name="ourstory_title" type="text"
id="ourstory_title" value="<?php echo $values['ourstory_title']?>">
</td>
</tr>
<tr>
<td width="85%" >Testimonial</td>
</tr>
<tr>
<td>
<pre>
<textarea class="commentarea"
name="ourstory_testimonial" type="text"
id="ourstory_testimonial" rows= "10" ><?php echo $values['ourstory_testimonial']?>
</textarea>
</pre>
</td>
</tr>
<tr>
<td width="85%" >About Us Content</td>
</tr>
<tr>
<td>
<pre>
<textarea class="commentarea" name="ourstory_content"
type="text" id="ourstory_content"
rows= "10" ><?php echo $values['ourstory_content']?>
</textarea>
</pre>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Update">
</td>
</tr>
</table>
</form>