473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

PHP checking for no record

I am trying to check for '$date' & '$mileage' but when I give them a value
that is not in the table $result = 2 & the 'if' statement fails to create
the new record, or just print "create DMID" in this case. $result seems to
always = 2. num_rows shows correct (0 or 1) & the DMID is printed if
$date & $mileage are in the table.

What am I doing wrong?

-----------
$result = mysql_query("select DMID from DateMileage where date = '$date' and mil
eage = '$mileage'");
printf("Rows = ".mysql_num_rows($result));
$data=mysql_fetch_object($result);
printf(" data= $data->DMID");

printf("<BR>Result = $result, Mileage = $mileage, Date= $date");
printf("<BR>Year = $year, Make = $make, Model = $model");
printf("<BR>Category = $category");

if( !$result )
{
prinf("<P>create DMID");
}
else
{
print("<P>Found DMID");
//$DMID = mysql_fetch_object($result);
}

Apr 6 '07 #1
1 5889
>I am trying to check for '$date' & '$mileage' but when I give them a value
>that is not in the table $result = 2 & the 'if' statement fails to create
the new record, or just print "create DMID" in this case. $result seems to
always = 2. num_rows shows correct (0 or 1) & the DMID is printed if
$date & $mileage are in the table.

What am I doing wrong?
if (!$result) tests whether the query has *FAILED*, which is not
the same thing as successfully returning an empty result. $result
is a resource, not a numeric value (although it might look like one
when printed). You get a failure for things like syntax errors in
the query, nonexistent tables, permission problems, etc. I suggest
that the test you want is:

if (mysql_num_rows($result) == 0) {
...
}
>
-----------
$result = mysql_query("select DMID from DateMileage where date = '$date' and mil
eage = '$mileage'");
printf("Rows = ".mysql_num_rows($result));
$data=mysql_fetch_object($result);
printf(" data= $data->DMID");

printf("<BR>Result = $result, Mileage = $mileage, Date= $date");
printf("<BR>Year = $year, Make = $make, Model = $model");
printf("<BR>Category = $category");

if( !$result )
{
prinf("<P>create DMID");
}
else
{
print("<P>Found DMID");
//$DMID = mysql_fetch_object($result);
}

Apr 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sue | last post by:
As soon as a character is entered in the first field of a new record, the number of records shown in the navigation buttons increases by 1 and the new record button becomes enabled. In the...
2
by: R Bolling | last post by:
I am using a routine to check to see if a phone number (PK) has alread been entered, and takes the user to that record if it is found -- as follows: Private Sub...
6
by: John | last post by:
Hi We have a staff database and need to make sure that the same staff is not entered twice. Is there a way for Access to flag if combination of forename and surname fields is already in the...
5
by: BerkshireGuy | last post by:
Hello everyone, I have a bond form that a user uses to enter data. One of my fields, is PolicyNumber. I added some code on the Before Update event of txtPolicyNumber that checks to see if...
4
by: Patrick De Ridder | last post by:
My question has to do with checking whether someone is fraudulently messing about with data. ********************************************* Given a field, say fieldString I want to add a...
6
by: Joey Lee | last post by:
Hi, I was wondering which is the best way of checking if a record exist in the database before inserting. There are quite a few ways I have seen. Here are some... 1> Insert and hit a...
6
by: TonyMacaroni | last post by:
Hi everyone, I have a database I'm helping set up for a Charity - I'd like to create a query where if the admin team tries to enter a member twice, a pop up box will inform them that a member with...
6
by: maxx429 | last post by:
I am trying to check if notes have been added to a Memo field on a form if certain other fields have changed. Example: If the user ticks a particular check box on the form, I want to force them to...
4
by: barmatt80 | last post by:
I have created an unbound form so that when users enter the information, there is a save button they have to click, checking to make sure a field(txtDocketNo) is not blank. For some reason I cannot...
2
by: hakkatil | last post by:
Hi to all, I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.