Jump to content

Test if query is successful


dzedward

Recommended Posts

How can I test if a query is successful?  Lets say

 

$id = '5';
$sql2 = "SELECT advURL FROM adv WHERE ID = '$id'";
$qry2 = mysql_query($sql2)
or die("Query failed: " . mysql_error() . " Actual query: " . $sql);

 

Lets say there is no value for advURL for that id.  How can I know?

Link to comment
Share on other sites

do u want this?

$id = '5';
$sql2 = "SELECT advURL FROM adv WHERE ID = '$id'";
$qry2 = mysql_query($sql2)
or die("Query failed: " . mysql_error() . " Actual query: " . $sql);

$row = mysql_fetch_array($qry2);
if($row['advURL'] == ''){
echo "advURL is empty!!";
}

Link to comment
Share on other sites

$sql = "SELECT ID FROM adv WHERE req = '$incoming'";

$qry = mysql_query($sql)
or die("Query failed: " . mysql_error() . " Actual query: " . $sql);

while($rand = mysql_fetch_object($qry)) {
        $request = $rand->ID;
        $id = $request+1;		

	$sql2 = "SELECT advURL FROM adv WHERE ID = '$id'";

   		$qry2 = mysql_query($sql2)
	or die("Query failed: " . mysql_error() . " Actual query: " . $sql2);
	if($qry2['advURL'] == ''){
		finish();
	} else {
		while($theId = mysql_fetch_object($qry2)) {
				$url = $theId->advURL;
			$newURL = $url;
				giveNew($newURL); 			
		}
	}     
}

function giveNew($next){
echo $next;
}
function finish(){
echo "Finish Line";
}

Link to comment
Share on other sites

isnt $qry2['advURL']  undifined? i think you u need a fetch array on $qry2

		$qry2 = mysql_query($sql2)
	or die("Query failed: " . mysql_error() . " Actual query: " . $sql2);
	if($qry2['advURL'] == ''){
		finish();
	} else {

 

replace with this

		
                         $qry2 = mysql_query($sql2)
                         $row2 = mysql_fetch_array($qry2);
	or die("Query failed: " . mysql_error() . " Actual query: " . $sql2);
	if($row2['advURL'] == ''){
		finish();
	} else {

Link to comment
Share on other sites

ooops forgot about the or die. use this


                         $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql2);
                         $row2 = mysql_fetch_array($qry2);
	if($row2['advURL'] == ''){
		finish();
	} else {

Link to comment
Share on other sites

ooops forgot about the or die. use this


                         $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql2);
                         $row2 = mysql_fetch_array($qry2);
	if($row2['advURL'] == ''){
		finish();
	} else {

 

Using this I get no error, and I works if it is the last one in line.  But all others fail to move on to next url, just get blank.

Link to comment
Share on other sites

this is the best i can do with out knowing exaclty what all these fields are

                      $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql2);
                         $row2 = mysql_fetch_array($qry2);
	if($row2['advURL'] == ''){
		finish();
	} else {		
				$url = $row2['advURL'];
			$newURL = $url;
				giveNew($newURL); 			
		}
	}     
}

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.