Simple update to Mysql


I am a complete newbie to php and mysql. I am just trying to achieve something simple right now as a test.

I have a Mysql database with 3 columns (Chapter, Editor, Approved). Using form I have managed to get these to show on a page to allow someone to change the relevant details then submit them. The problem is when the page updates it shows the old details - ie the changes are not stored. I am sure I am doing something incredibly stupid but after 2 hours can’t see it. I’m sure someone with some knowledge will spot it in a heartbeat. The necessary code.

The page to show the info
include_once ‘includes/’;

<title>Update progress</title>

//connect to dbase
//done in inc file

//select database - in inc file?

//select query
$sql="SELECT * FROM VM;";

//execute query

	<th>Approved for submission</th>
	echo "<tr><form action=update.php method=post>";
	echo "<td><input type=text name=chapter_i value='".$row['Chapter']."'</td>";
	echo "<td><input type=text name=editor_i value='".$row['Editor']."'</td>";
	echo "<td><input type=date name=submission_i value='".$row['Approved']."'</td>";
	echo "<td><input type=submit>";
	echo "</form></tr>";


include_once 'includes/';

//connect to dbase
//done in inc file

//select database - in inc file?

//update query
$sql="update VM set Approved='$submission_i' WHERE Chapter='$Chapter'";
//can use comma and another for each variable

//execute query
	header("refresh:1; url=test_update.php");
	echo "NO";


The primary key is chapter. If you need anything more please yell. TIA


Yes, the problem is very obvious. Where do you expect the values for those “magic” update variables to come from? They just appear out of nowhere don’t they?

Before you spend too much time learning Mysqli, I would suggest you just stop and learn PDO with Prepared Statements instead. This will get you going

You can also download my PDO Bumpstart Database that will help you get going.


I don’t quite follow. Aren’t the update variable submission_i being the name attached to that box on the form? Or am I missing something (yet again!)?


Yes, but the values are held in the POST array. PHP does not magically (not anymore) create variables. So you would access the values like $_POST[‘submission_i’]


That’s what I originally had before I took it out. STuck it back but still doesn’t work.

This is what I have at the moment (after putting POST back).

$sql="update VM set Approved='$_POST[submission_i]' WHERE Chapter='$_POST[Chapter]'";
//can use comma and another for each variable


For one, that’s not what I showed you. Look at my post again. Naturally you looked at the error logs right? What does the error log say? And of course you have error reporting turned on right?