php - Database Error. SQL query is not being executed -
i have form takes 2 values input , parses them using post method next file have piece of code. should save 2 values in mysql database. strangely doesn't .. , in output error this: 0: 0:
$service_name = $_post['service_name']; $service_price = $_post['service_price']; $link = mysql_connect("localhost", "db_user", "pa$$"); mysql_select_db("database", $link); echo mysql_errno($link) . ": " . mysql_error($link). "\n"; mysql_select_db("database", $link); mysql_query("insert service_tbl(id_service, service_name, service_price) values(null,'$service_name','$service_price')", $link); echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
in database table service_tbl
, id_service
is auto_increment , other 2 columns varchar. doing wrong here?
you trying insert null
in auto increment column, wich not possible, change
mysql_query("insert service_tbl( service_name, service_price) values('$service_name','$service_price')", $link);
then remember mysql_
functions deprecated advise switch mysqli
or pdo
, indeed @ risk of sql injection
, have here how can prevent sql injection in php?. should use prepared statment avoid risk
Comments
Post a Comment