3

MySQL gives an error when I try to input data into the following table my_table:

my_table
Columns | data type:
Task    | varchar(20) (primary key)
Descr   | tinytext
start   | time
end     | time

The my_table character set is utf8

I am trying to insert values into the table from a PHP file:

<?php

mysql_connect("localhost", "admin", "passwd") or die(mysql_error());
mysql_select_db("my_table") or die(mysql_error());

$task = $_POST["taskname"];
$descr = $_POST["taskdesc"];
$start = $_POST["starttime"];
$end = $_POST["endtime"];

$insert = "INSERT INTO tasks (task, descr, start, end) 
VALUES ('$task','$descr','$start','$end')";

mysql_query($insert) or die(mysql_error());
mysql_close();

?>

I receive the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'descr, start, end) VALUES ('Task 1','This is a task. This is only a task. This ' at line 1

Here is the html that gives the inputs:

<form id="taskentry" method="post" action="create-task.php">
<ul>
    <li><input type="text" name="taskname" placeholder="Task Name"/></li>
    <li><textarea form="taskentry" name="taskdesc" placeholder="Description" rows="5"></textarea></li>
    <li><input type="time" name="starttime"></li>
    <li><input type="time" name="endtime"></li>
    <li class="naked"><input type="submit" name="Save" value="Submit Task" /></li>
</ul>
</form>

I suspect it is a format issue. Can anyone help?

4

1 回答 1

1

try to insert data using mysql comand prompt, if that works then try to check if your form data is submitted to your action php page or not. you can write a code to test that

if(isset($_POST["taskname"]) && isset($_POST["taskdesc"]) && isset($_POST["starttime"]) && isset($_POST["endtime"]))
{
$task = $_POST["taskname"];
$descr = $_POST["taskdesc"];
$start = $_POST["starttime"];
$end = $_POST["endtime"];
echo $task."<br />".$descr."<br />".$start."<br />".$end;
}
于 2012-12-16T02:48:18.280 回答