문제

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