I'm making a small project to manage my projects, but im having trouble with the script that adds a new client to the the database. As of now im getting and error that says
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\testing folder\project_manger\write_client.php on line 15
Could anyone explain to my why this is happening? and why is the code able to bypass the last 'if else' statement?
Thank you for your time. Note: if have highlightened line 15
Code: Select all
<?php
include( 'conn_inc.php' );
include( 'comm_func.php' );
#check the fields for user errors
if ($_POST['first_name']=="" || $_POST['last_name'] == ""){
echo "one of the name fields are empty";
exit;
}
$date_logged= (date("Y-m-d"));
$id=rand(1000,9999);
$sql= "SELECT id FROM client WHERE id='$id'";
$mysql_result=mysql_query ($sql,$connect);
[b]$num_rows=mysql_num_rows($mysql_result);[/b]
if ($num_rows!=0){
$id=rand(1000,9999);
}
$insert = "INSERT INTO client (first_name,last_name,email,home_phone,cell_phone,office_phone,address,date,id) VALUES ('$_POST[first_name]','$_POST[last_name]','$_POST[email]','$_POST[home_phone]','$_POST[cell_phone]','$_POST[office_number]','$date_logged','$id')";
if(!$insert){
echo "the records could to be added at this time. Please try again later";
exit;
} else {
echo "the records were added<br />";
main_menu();
}
?>