PHP instering to database

hi guys i am quite new to php and mysql data bases and i am having some trouble with my site i am making. I have a page which is meant to add a new item into a table called ‘my_build’, the code below is what i have but i doesn’t seem to be working and i amn’t getting any error with it either. Can any one with this?

[php]<?php
$con = mysqli_connect(“localhost”, “root”, “”, “Computers”);
if ( isset($_POST[‘serial_no’]) && isset($_POST[‘description’]) && isset($_POST[‘price’])
&& isset($_POST[‘fname’]) && isset($_POST[‘lname’]) )
{
$s = mysql_real_escape_string($_POST[‘serial’]);
$d = mysql_real_escape_string($_POST[‘description’]);
$p = mysql_real_escape_string($_POST[‘price’]);
//$sql = “INSERT INTO my_build (Serial_no, Description, Price)
//VALUES (’$s’, ‘$d’, ‘$p’)”;
echo “

\n$sql\n
\n”;
mysqli_query($con, “INSTER INTO my_build (serial_no, description, price) VALUES (’$s’, ‘$d’, ‘$p’)”);
echo ‘Success - Continue…’;
return;
}
mysqli_close($con);
?>

Add A New User

Serial_no:

Description:

Price:

Cancel

[/php]

you should add error handling to the database query. You have an invalid query syntax
http://php.net/manual/en/mysqli.query.php

Also as you’re using mysqli you should change to use parameterized queries, that way you don’t have to deal with escaping data before doing queries.

Just noticed you had the same typo in the thread title. You mean an “INSERT” statement… :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service