Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2010
    Posts
    2

    Unanswered: 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");

    ?>

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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!

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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
    Last edited by healdem; 04-01-10 at 12:20.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •