Hi everyone,
I’m relatively new to PHP and database scripting, but I’m running into a strange problem that I can’t seem to resolve. I am using a simple HTML forum to get data which will then be sent to a MySQL database table.
<?php
if(isset($_POST[‘Submit’])){
$participant = $
$time = $_POST[‘time’];
$err = ”;
if(trim($participant)==”){
$err .= ‘-Please enter a name<br>’;
}
if(empty($time)){
$err .= ‘-Please enter a time’;
}
if($err!=”){
echo $err;
}
else{
$db=mysql_connect (“localhost”, “user”, “pass”) or die (‘I cannot connect to the database because: ‘ . mysql_error());
mysql_select_db (“mydb”);
$query = “INSERT INTO testtable (name, milliseconds) VALUES ($participant, $time)”;
mysql_query($query) or die(‘Error: ‘ . mysql_error());
echo “new record added”;
mysql_close($db);
}
}
?>
<form name=”dataform” method=”post” action=””>
Participant Name: <br>
<input name=”participant” type=”text” id=”participant” value=”Bob”><br><br>
Time (milliseconds):<br><input name=”time” type=”text” id=”time” value=”99.99″><br><br>
<input type=”submit” name=”Submit” value=”Submit”>
</form>
When I hit submit, however, I get an error: “Unknown column ‘Bob’ in ‘field list'” Now, the problem here is that, ‘Bob’ is what I entered in my text box for $participant. That is being sent as a value for the ‘name’ column.
Any idea why it would switch those around on me?
Thanks!