Jump to content

mysql_num_rows works when it feels like it?


law

Recommended Posts

Well the title is kinda true.. here is what goes down.. (in my form processor) It retrieved the data with no issues.. it uses the UPDATE query perfectly ($row =1).. the problem is that if $row doesn't = 1.. it actually returns NO value @ all!! So all my code just craps out.. the }else{ statement that is supposed to make the query INSERT INTO never gets called.. in fact when i try to make it INSERT the entire page goes blank and only shows the background (the form dissappears) This is weird because the form isn't even in the php code its all written in html and is below the form processor (on the same page.. the form target is "self") 

 

Anyone see what im doing wrong here? Also PLEASE inform me if any thing im doing is not safe!! im a newbie and i need all the safety tips i can get!!

 

<?php
//==========================Form Processor============================
$listval1 = mysql_escape_string($_POST['list1']);
$listval2 = mysql_escape_string($_POST['list2']);
$urlval = mysql_escape_string($_POST['url']);
$titleval = mysql_escape_string($_POST['title']);
$captionval = mysql_escape_string($_POST['caption']);
$infoval = mysql_escape_string($_POST['info']);
if($listval1 != null){
for ($num=1;$num<10;$num++){
		if($listval1 == $num){
		$table = $urlname[$num];
		echo "$table";
		}
	}
if($listval2 != null){
	$listval2++;
	echo "$listval2";
			$row = 0;
			$query = "SELECT * FROM $table WHERE id='$listval2'";
			$sql = mysql_query($query) or die(mysql_error());
			$row = mysql_num_rows($sql) or die(mysql_error());
			echo "$row";
				if($row == 1){
					$updatequery = "UPDATE $table SET title='$titleval',url='$urlval',caption='$captionval',info='$infoval' WHERE id='$listval2'";
					$updatesql = mysql_query($updatequery) or die(mysql_error());
				echo"<div id='caption'><h2><font color='orange'>Updated $table data Sucessfully</font></h2></div>";
				}else{
				$insertquery = "INSERT INTO $table (title, url, caption, info) VALUES ('$titleval','$urlval','$captionval','$infoval')";
				$inssql = mysql_query($insertquery) or die(mysql_error());
				echo"<div id='caption'><h2><font color='orange'>Submitted $table data Sucessfully</font></h2></div>";
				}
			}
}
//----------------------------------------------------------------------------------------------------
?>

Link to comment
Share on other sites

For fun, replace echo "$row"; with:

 

    echo "row=$row listval2=$listval2";

 

Make sure two things are happening. 1) that line is output 2) listval2 is a valid value

 

echo "$row"; is bad practice, because you don't know if the code's even getting there! You can't assume it's just empty because nothing shows up.

 

Bryan

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.