I am building a project and for some reason, I am unable to get my Update statement to actually update.
I have some input fields in a form which provide the details for the variables below.
Here's my code:
//update database
$stmt = $mysqli->prepare("UPDATE pages SET
pg_name= ?,
pg_title = ?,
pg_keywords = ?,
pg_description = ?,
pg_header1 = ?,
pg_header2 = ?,
pg_maintext = ?,
pg_active = ? WHERE id = ?");
$stmt->bind_param('sssssssii',
$pg_name,
$pg_title,
$pg_keywords,
$pg_description,
$pg_header1,
$pg_header2,
$pg_maintext,
$pg_active,
$id);
if($stmt->execute() === TRUE){
$stmt->close();
echo "Database successfully updated";
} else {
echo "There was a problem updating the database.";
}
I have tested and the variables are being set from my form ok, and when I run the script , I get the 'success' message but check my database and nothings happened.
Anything I've missed? :)
Thanks for your help/
OK< existing form/ table below:
<form action="" method="post">
<table>
<tr>
<td colspan="2"><?php echo "<span style='color: red; font-weight: bold;'>".$errmsg."</span><br />"; ?></td>
</tr>
<tr>
<td>Page Name:</td>
<td><input type="text" name="pg_name" id="pg_name" value="<?php if(isset($id)){ echo $page['pg_title']; }?>" /></td>
</tr>
<tr>
<td>Page Title:</td>
<td><input type="text" name="pg_title" id="pg_title" value="<?php if(isset($id)){ echo $page['pg_title']; }?>" /></td>
</tr>
<tr>
<td>Keywords:</td>
<td><input type="text" name="pg_keywords" id="pg_keywords" value=" <?php if(isset($id)){ echo $page['pg_keywords']; }?>" /></td>
</tr>
<tr>
<td>Description:</td>
<td><input type="text" name="pg_description" id="pg_description" value="<?php if(isset($id)){ echo $page['pg_description']; }?>"/></td>
</tr>
<tr>
<td>Main page header:</td>
<td><input type="text" name="pg_header1" id="pg_header1" value="<? php if(isset($id)){ echo $page['pg_header1']; }?>"/></td>
</tr>
<tr>
<td>Subheader:</td>
<td><input type="text" name="pg_header2" id="pg_header2" value="<? php if(isset($id)){ echo $page['pg_header2']; }?>" /></td>
</tr>
<tr>
<td>Page text</td>
<td><textarea name="pg_maintext" id="pg_maintext"><?php if(isset($id)){ echo $page['pg_maintext']; }?></textarea></td>
</tr>
<tr>
<td>Active?</td>
<td><select name="pg_active">
<option value="1">Yes</option>
<option value="0">No</option>
</select></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="<?php if(isset($_GET['page_id'])){ echo "Update"; } else { echo "Add"; } ?>" /><?php if(isset($_GET['page_id'])){ echo "<a href='pages.php' /><input type='button' name='new' id='new' value='New' /></a>"; } ?></td>
<td></td>
</tr>
</table>
</form>
I have tried the SQL commend in my database direct, and it works. Just doesnt work via this form. DB is connected and form is able to pull data from the database.
UPDATE: I've tried everything I an think of - nothing is working here. I've added error reporting to each step, and because it thinks nothing is wrong, no errors are flagging up! I have update access to the SQL as I use it all the time.