I’m having the weirdest problem right now. In order to see if a contact is already in the database I check it. For me to see I echo: “Is in database” or “is not in database”. For the user to see I return him the string with the same massage. Weird thing is, the echo is always right, but the string is always the same “Is not in database”, even when a contact is in database. For example: I add my Mum. My Mum is in database, so the echo is correct and says “Is in database”. But the string I get returned always says “Is not in database”.
Full code
<?php
$DB_HostName = "localhost";
$DB_Name = "db";
$DB_User = "user";
$DB_Pass = "pw";
$DB_Table = "contacts";
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die (mysql_error());
mysql_select_db($DB_Name,$con) or die(mysql_error());
$fnumber = mysql_real_escape_string($_GET["fnumber"]);
$result = mysql_query("SELECT * FROM $DB_Table WHERE User = '$fnumber'", $con);
if ($result) {
if (mysql_num_rows($result) > 0) {
echo "This user is already in database";
$number = mysql_real_escape_string($_GET["number"]);
mysql_query("DELETE FROM Echo WHERE Number=('$number')");
mysql_query("INSERT INTO Echo (Number,Answer)
VALUES ('$number','This user is already in database.')");
}
else echo
"This user isn't in the database";
$number = mysql_real_escape_string($_GET["number"]);
mysql_query("DELETE FROM Echo WHERE Number=('$number')");
mysql_query("INSERT INTO Echo (Number,Answer)
VALUES ('$number','this user isn't in the database.')");
}
mysql_close($con);
?>
And before you ask: In order to not crowd my database I always delete the number and then write the entry.
I guess this is the right code: