Jump to content

checking for empty values


php_begins

Recommended Posts

i retrieving an adid from $_GET which is also a value retireved from a database.

 $this_adid=$_GET['adid'];
    if(empty($this_adid))
{
    $get_ad_id = mysql_query("SELECT userid FROM ads WHERE adid='$this_adid'", $con) or die("Error Getting AD ID: ".mysql_error());
   while($get_ad_id_results = mysql_fetch_assoc($get_ad_id)) { $owner_id=$get_ad_id_results['userid']; }
}

the above query works if  $this_adid returns 0 (http://www.website.com/?do=delete&adid=0&givenuserid=15773) i.e. adid is 0 in the table.

 

But it does not work if $this_adid returns null or ntohin (http://www.website.com/?do=delete&adid=&givenuserid=15773) .i.e adid is ' ' (empty) field in the databse table..

 

can someone tell me why it does not check for null or empty values properly?

Link to comment
Share on other sites

i still want to execute the query if the the adid field is empty or null.

in some places adid is stored as empty(there is no value in the database table.)

i still need to compare those values in the table nad execute.

Right now if the adid field is empty it does not return anything..

Note: adid is not a primary key.it can be null

Link to comment
Share on other sites

well this:

" SELECT userid FROM ads WHERE adid='$this_adid' "

will ALWAYS be translated as this:

"SELECT userid FROM ads WHERE adid='' "

because its nested within an empty caluse.

 

Are there any records that have NOTHING in adid column? you should always try print_r on the results

 

Link to comment
Share on other sites

like i said the adid field is empty in the database table in some cases.(there is no value for adid in the table even when there are userids)

so i want to select userid from the ad table where adid=NULL or ' ')

this would still give me the userids.

But unfortunately it does not return anything..i do not know to how to check for fields tht have no value..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.