Hello,
I am new to PHP so I have done a research on how to check if an entry
exists on the table. I came up with the following code:
include("dbinfo .inc.php");
$Name=$_POST['Name'];
$Code=$_POST['Code'];
mysql_connect($ host,$username, $password);
@mysql_select_d b($database) or die( "Unable to select database");
$result = mysql_query("SE LECT * FROM Contacts WHERE Code=$Code");
if($row = mysql_fetch_arr ay($result)) echo "exists";
else
{$query = "INSERT INTO Contacts VALUES ('','$Name','$C ode')";
echo "ok";}
mysql_query($qu ery);
mysql_close();
This works if the code is integer (1264), however if the code is
string (a4fg5h4) it shows - "Warning: mysql_fetch_arr ay(): supplied
argument is not a valid MySQL result resource in D:\xampp\htdocs \reg
\insert.php on line 10
ok"
I can't found out what is the problem here as all the examples on the
web shows similar codes to do checking.
I am new to PHP so I have done a research on how to check if an entry
exists on the table. I came up with the following code:
include("dbinfo .inc.php");
$Name=$_POST['Name'];
$Code=$_POST['Code'];
mysql_connect($ host,$username, $password);
@mysql_select_d b($database) or die( "Unable to select database");
$result = mysql_query("SE LECT * FROM Contacts WHERE Code=$Code");
if($row = mysql_fetch_arr ay($result)) echo "exists";
else
{$query = "INSERT INTO Contacts VALUES ('','$Name','$C ode')";
echo "ok";}
mysql_query($qu ery);
mysql_close();
This works if the code is integer (1264), however if the code is
string (a4fg5h4) it shows - "Warning: mysql_fetch_arr ay(): supplied
argument is not a valid MySQL result resource in D:\xampp\htdocs \reg
\insert.php on line 10
ok"
I can't found out what is the problem here as all the examples on the
web shows similar codes to do checking.
Comment