I'm creating a mysql database table and want to insert some values to my table from a page by using PHP. I've succeeded in everything however, I can only insert integer values to my table. I've used VARCHAR for the input type for the fields. I've also tried TEXT input type but that did not work as well. What can be the problem?

One of my fields' code is:

<p>
<label>Event Name: 
<input name = "ename" type = "text" size = "30" 
maxlength = "300" /> 

My insert code is:

$sql = "INSERT INTO sca (ename, eplace, society, edate, ehour) VALUES ($_POST[ename], $_POST[eplace], $_POST[society], $_POST[edate], $_POST[ehour])";

Thank you.

有帮助吗?

解决方案

You should use quotes in your insert statement like:

VALUES ('{$_POST['ename']}', '{$_POST['eplace']}') // and so on

其他提示

The answer of Christian Bitoi is correct, but I would also like to mention you should escape your sql input. Just google SQL-injection and you'll see why.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top