Frage

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.

War es hilfreich?

Lösung

You should use quotes in your insert statement like:

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top