-1

Ok below is my code and I've tried to debug it with var_dumps .. var_dump($insertion) returns through , which means that the query inserts into the database but for some reason , I'll get the warning message when I wanna see if mysql_num_rows is doing its job and it returns FALSE with the warning message of the title .. Below is my short straight-forward code

<?php

require'sensdb.php';

if (sensdb_connect()) {

$select = "SELECT SubGroupID from STx WHERE GroupID = '39'AND Status ='Provisioned'";

$result = mysql_query($select);
$result_count = mysql_num_rows($result);

  if($result_count > 0)
   {
       while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {


         if($row['SubGroupID'] != 123) {

        $insert = "INSERT INTO Routes (SubGroupID,GroupID,URL) VALUES (".$row['SubGroupID'].",39,'mailto://e2pressure@gmail.com')";
        $insertion = mysql_query($insert);
        $insertion_count =  mysql_num_rows($insertion); var_dump($insertion_count);
        $select_route_id = "SELECT RouteID FROM Routes WHERE SubGroupID =".$row['SubGroupID']." AND GroupID = 39";
        $result_route_id = mysql_query($select_route_id);
        $result_route_count = mysql_num_rows($result_route_id);
         if($insertion_count > 0 ) {
         if($result_route_count > 0) {
            $row_route = mysql_fetch_array($result_route_id,MYSQL_ASSOC);
             $update = "UPDATE STx SET RouteID =".$row_route['RouteID']." WHERE SubGroupID =".$row['SubGroupID']."";
             var_dump($update);

             }

           }

         }

     }

  }

}
user2041213
  • 29
  • 1
  • 5
  • You have an error in your query. You need to do proper error checking in order to catch such problems and debug them. http://www.php.net/mysql_error – Pekka Feb 11 '13 at 23:15
  • @Pekka웃 There may be an error in his SQL, but it's not the cause of this. – David Kiger Feb 11 '13 at 23:18

1 Answers1

0

From the PHP docs:

Retrieves the number of rows from a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use mysql_affected_rows().

PHP.net

Also, you should really be using PDO (or something like it).

David Kiger
  • 1,958
  • 1
  • 16
  • 25