If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Could use some URGENT help with mysql_num_rows() error!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-01-10, 08:09
corelement corelement is offline
Registered User
 
Join Date: Apr 2010
Posts: 2
Could use some URGENT help with mysql_num_rows() error!

I am doing a weblog and keep getting the same error for several links. Im getting very frustrated!! Please help if anyone can.

Here is my code:

<?PHP

REQUIRE("config.php");

IF(ISSET($_GET['id']) == TRUE){

IF(IS_NUMERIC($_GET['id']) == FALSE){
$error = 1;
}

IF($error == 1){
header("Location:".$config_basedir);
}ELSE{
$validentry = $_GET['id'];
}

}ELSE{
$validentry = 0;
}


IF($_POST['submit']){

$db = mysql_connect($dbhost, $dbuser, $dbpassword);

mysql_select_db($dbdatabase, $db);

$sql = "INSERT INTO comments(blog_id, dateposted, name, comment)VALUES(".$validentry.",
NOW(),'".$_POST['name']."','".$_POST['comment']."');";

mysql_query($sql);

header("Location: http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]."?id=".
$validentry);


}ELSE{


REQUIRE("header.php");

IF($validentry == 0){

$sql = "SELECT entries.*,categories.cat FROM entries,categories WHERE entries.cat_id =
categories.id ORDER BY dateposted DESC LIMIT 1;";

}ELSE{

$sql = "SELECT entries.*,categories.cat FROM entries,categories WHERE((entries.cat_id =
categories.id) AND (entries.id = ".$validentry."))ORDER BY dateposted DESC LIMIT 1;";

}





$result = mysql_query($sql);

$row = mysql_fetch_assoc($result);

ECHO"<h2>".$row['subject']."</h2><br/>";

ECHO"<i>In <a href = 'viewcat.php?id=".$row['cat_id']."'>".$row['cat']."</a>-Posted on ".
date("D jS F Y g.iA",strtotime($row['dateposted']))."</i>";


if(isset($_SESSION['USERNAME']) == TRUE){
echo"[<a href='updateentry.php?id=".$row['id']."'>edit</a>]";
}


ECHO "<p>";

ECHO nl2br($row['body']);

ECHO "</p>";




$commsql = "SELECT * FROM comments WHERE blog_id = ".$validentry."ORDER BY dateposted
DESC;";


$commresult = mysql_query($commsql);

$numrows_comm = mysql_num_rows($commresult);

IF($numrows_comm == 0){
ECHO "<p> No comments.</p>";

}ELSE{

$i = 1;
WHILE($commrow = mysql_fetch_assoc($commresult)){

ECHO "<a name = 'comment".$i."'>";
ECHO "<h3>Comment by ".$commrow['name']."on".date("D jS F Y g.iA",
strtotime($commrow['dateposted'])). "</h3>";
ECHO $commrow['comment'];
$i++;
}
}

?>

<h3>Leave a comment</h3>

<FORM ACTION = "<?PHP ECHO $_SERVER["SCRIPT_NAME"]."?id=".$vaildentry;?>"
METHOD = "POST">
<TABLE>
<TR>
<TD>Your name</TD>
<TD><INPUT TYPE = "TEXT" NAME = "name"></TD>
</TR>
<TR>
<TR>
<TD><TEXTAREA NAME = "comment" ROWS = "10" COLS = "50"></TEXTAREA></TD>
</TR>
<TR>
<TD></TD>
<TD><INPUT TYPE = "submit" NAME = "submit" VALUE = "Add comment"></TD>
</TR>
</TABLE>
</FORM>

<?PHP

}

REQUIRE("footer.php");

?>
Reply With Quote
  #2 (permalink)  
Old 04-01-10, 08:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
Quote:
Originally Posted by corelement View Post
$commsql = "SELECT * FROM comments WHERE blog_id = ".$validentry."ORDER BY dateposted
DESC;";

$commresult = mysql_query($commsql);

$numrows_comm = mysql_num_rows($commresult);
there was no need to dump the entire page of code, because you only use mysql_num_rows once, and that's it right there

try putting a space between $validentry and ORDER

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-01-10, 10:38
corelement corelement is offline
Registered User
 
Join Date: Apr 2010
Posts: 2
Sorry bout all the code. Im a newbie. Man that was simple. Thanks worked! But now im having some other issues. when attempting to post a comment to an entry on the blog, after submitting, the comment doesnt show. And also having issues with the user login functions. If you have time and want me to post code let me know. Thanks!
Reply With Quote
  #4 (permalink)  
Old 04-01-10, 11:02
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
new problem/question new post, please.. dats der rules....

however to get things kicked off...
what error message are you getting when you try to write/update the data. examine the mysql_error and PHP: mysql_errno - Manual functions.
have you examined the SQL you are actually executing and made certain its valid MySQL. the or dire construct is helpful here, you can use
PHP Code:
or die(echo $strSQL); 
if looks OK then I'd suggest you run it in MySQL Query Browser or similar and see if it runs there. if it doens't run in Query browser you know its your SQL thats banjaxed, if it runs then its your PHP code

what error_reporting level are you running on your code
consider using the or die construct on your code, at least while you are developing

New installations of PHP no longer automatically report everything, meaning it cna be a perplexing devlopment environment. turningon the appropriate level of error reporting can help diagnose some errors.

incidentally if you post PHP use the PHP code tags which make the code much more visible. thats [ followed by PHP followed by ], and after the code snippet [ followed by /PHP followed by ]

please don't post complete scripts, just where the error is and any lines upstream of that error that are relevant to that error. Posting complete scripts makes my eyes glaze over. it also sends the message that you value your time far more than people you are asking to help you. its a self defeating approach.. if you can't be bothered, why should anyone else be bothered to help you
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton

Last edited by healdem; 04-01-10 at 11:20.
Reply With Quote
  #5 (permalink)  
Old 04-01-10, 11:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,538
sorry, i don't actually do php (coldfusion is what i use)

i can sort of read php, but mainly only where SQL is involved

someone else will have to step in

note that dbforums is primarily a database site, not a programming site
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On