mysql_num_rows()

Discussion in 'PHP' started by fireflyproject, Sep 15, 2008.

  1. #1
    I'm having a little trouble working with this function. I've come across this problem before, but never found a suitable fix for it.

    First of all, here is my very basic code.

    	$page = str_replace(" ","-",$_POST['page']);
    	$sql = "select * from articles where page = '$page'";
    	$result = mysql_query($sql);
    	$num = mysql_num_rows($result);
    	
    	if ($num > 0) {
    		$sql = "insert into articles values('', '$page', '" . $_POST['title'] . "', '" . $_POST['content'] . "',)";
    		mysql_query($sql);
    	} else {
    		$sql = "update articles set title = '" . $_POST['title'] . "', content = '" . $_POST['content'] . "' where page = '$page'";
    		mysql_query($sql);
    	}
    PHP:
    I don't see any trouble with it, as when there is no matching row $num = 0. I was echoing this just fine. However it does not insert anything into the database, nor are any errors appearing when the code is ran.

    Any ideas?
     
    fireflyproject, Sep 15, 2008 IP
  2. fireflyproject

    fireflyproject Active Member

    Messages:
    969
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Oi vey. Ok, I saw the problem the second I hit "Post". It's a typo in my query to mysql. Damn commas.
     
    fireflyproject, Sep 15, 2008 IP