-2

Im trying to build a shopping cart but i am getting this error

Parse error: syntax error, unexpected ')', expecting '(' in C:\xampp\htdocs\products.php on line 12

This is the code

<?php
if(isset($_GET['action']) && $_GET['action']==add){        
    $id=intval($_GET['id']);
    if(isset($_SESSION['cart'])){
        $_SESSION['cart'][$id]['quantity']++;
    } else {            
        $sql_s="SELECT * FROM tutorial WHERE id_product=[$id]";
        $query_s=mysql_query($sql_s);
        if (mysql_num_rows(&query_s)!=0){ 

        } else {
            $message="This ID is invalid!";
        }
  }
?>

Product`s

<?php 
 if(isset($message)){
        echo"<h2>$message</h2>";
    }
   <table>
       <tr>
           <th>Name</th>
            <th>Description</th>
            <th>Price</th>
            <th>Action</th>
       </tr>
      <?php
      $sql="SELECT * FROM tutorial ORDER BY name ASC";
      $query=mysql_query($sql);
      while ($row=mysql_fetch_array($query)) {
      ?>
      <tr>
         <td><?php echo $row['name'] ?></td>
         <td><?php echo $row['description'] ?></td>
         <td>&euro;<?php echo $row['price'] ?></td>
         <td><a href="index.php?page=products$action=add&id=<?php echo $row['id_product']?>">Add to cart</a></td>
      </tr>
       <?php
          }
        ?>
 </table>

Can anyone help me it will be much appreciated!

Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104
Trojan_DC
  • 11
  • 1
  • 9

1 Answers1

2

You have an invalid character which is throwing off the parser.

if (mysql_num_rows(&query_s)!=0){

should be

if (mysql_num_rows($query_s)!=0){
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Thanks but now im getting this error Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\products.php on line 51 – Trojan_DC Oct 13 '14 at 13:05
  • You're probably missing a closing bracket somewhere – John Conde Oct 13 '14 at 13:06
  • Know anything to this error perhaps? Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\products.php on line 12 – Trojan_DC Oct 13 '14 at 13:31
  • See: http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select – John Conde Oct 13 '14 at 13:33