I am trying to learn PHP and MySQL by creating a small database and keep getting an error.
Warning: mysql_query() expects parameter 1 to be string, object given in F:\usbwebserver\root\headset\insert.php on line 14 Error:
Code:
<?php
$con=mysqli_connect("localhost","root","usbw","consoleheadsets");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "connected succesfully.";
$sql="INSERT INTO headset (user, console, prodname, price, mic, sound, surround, comment)
VALUES
('$_POST[user]','$_POST[console]','$_POST[prodname]')','$_POST[price]','$_POST[mic]','$_POST[sound]','$_POST[surround]','$_POST[comment]')";
if (!mysql_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "Headset added succesfully.";
mysqli_close($con);
?>
The code was taken from this page on W3Schools and I just added the fields I needed. I can insert data in phpMyAdmin - it seems to work not sure what length to use for price decimal.
Database table:
user,verchar
console,verchar
prodname,verchar
price,decimal,(6.0)
mic,verchar
sound,verchar
surround,verchar
comment,verchar
id,int(11),auto_increment,primary
Thanks for the reply.