This question already has an answer here:
I am trying to work with databases on PHP, however I am getting an error when I try to make a table of data. The table seems to be created correctly (I think) but when I want to print the confirmation of the table is created, it throws me an error. This is the code:
if (mysql_query($connection,$sql)) //error
{
echo "1 record added";
}
else
{
die('Error: ' . mysql_error($con)); //error
}
They both give me the error mysql_query() expects parameter 1 to be string
and mysql_error() expects parameter 1 to be resource
Where
$sql
- the info being put in the table
mysql_query() expects parameter 1 to be string
. Are you sure that variables$connection
and$sql
are string? – Vainglory07 Feb 17 at 1:39($sql,$connection)
– Dagon Feb 17 at 1:39$connection
first` and$con
second? And why didn't you just try switching parameter order for the first? Isn't the error message clear? – mario Feb 17 at 1:39mysql_query()
likemysqli_query()
, which takes a resource as its first param. – Michael Berkowski Feb 17 at 1:39mysql
functions? Please, get with the times and usemysqli
orpdo
. – Christian Varga Feb 17 at 1:40