Question

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.

Was it helpful?

Solution

You should use quotes in your insert statement like:

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top