Jump to content

Undefined Variable Issue


Aido89
Go to solution Solved by Barand,

Recommended Posts

Hi 

 

Please see code below, when I query my db I am getting an unefined variable issue, any ideas?

 

I am quiet new to PHP so please help.

 

 mysql_connect("localhost","root","");
 mysql_select_db("db");
 
 $id = intval($_GET['id']);
$res = "SELECT * FROM table WHERE id=$id";
 
 
 
 
 echo "<table>";
 
 
 echo "<tr>";
 
 echo "<td>"; echo "<h4>".$row['item']."</h4>"; echo "</td>";  echo "</tr>";
 echo "<td>";?> <img src ="<?php echo $row['image']; ?>" height ="100" width ="100"> <?php echo "</td>"; echo "</tr>";
 
  echo "<td>"; echo $row['description']; echo "</td>"; echo "</tr>";
   echo "<td>"; echo $row['price']; echo "</td>";
 
 echo "</tr>";
 
 
 
 echo"</table>";
 
 ?>
Link to comment
Share on other sites

Hi I have added in $row = mysql_fetch_assoc($res); as seen below but am now getting following error, Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in

 

Thanks again for fast replies guys, much appreciated

<?php
	   
	    mysql_connect("localhost","root","");
 mysql_select_db("db");
 

 $id = intval($_GET['id']);
$res = "SELECT * FROM table WHERE id=$id";


 /*
 $res = "SELECT * FROM shoes WHERE id=".intval($_REQUEST['id']);*/
 /*$res=mysql_query ("select * from shoes");*/
 
 echo "<table>";
 
$row = mysql_fetch_assoc($res);
{
 echo "<tr>";
 
 echo "<td>"; echo "<h4>".$row['item']."</h4>"; echo "</td>";  echo "</tr>";
 echo "<td>";?> <img src ="<?php echo $row['image']; ?>" height ="100" width ="100"> <?php echo "</td>"; echo "</tr>";
 
  echo "<td>"; echo $row['description']; echo "</td>"; echo "</tr>";
   echo "<td>"; echo $row['price']; echo "</td>";

 echo "</tr>";
 
 }
 
 echo"</table>";
 
 ?>
Link to comment
Share on other sites

Hi 

 

I have tried this but the same error keeps appearing I'm afraid

 

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given inC:\xampp\htdocs\readmore.php on line 68

<?php
	   
	    mysql_connect("localhost","root","");
 mysql_select_db("db");
 

 $id = intval($_GET['id']);

$sql = "SELECT * FROM table WHERE id=$id";
$res = mysql_query($sql);

 /*
 $res = "SELECT * FROM table WHERE id=".intval($_REQUEST['id']);*/
 /*$res=mysql_query ("select * from table");*/
 
 echo "<table>";
 
$row = mysql_fetch_assoc($res);
{
 echo "<tr>";
 
 echo "<td>"; echo "<h4>".$row['item']."</h4>"; echo "</td>";  echo "</tr>";
 echo "<td>";?> <img src ="<?php echo $row['image']; ?>" height ="100" width ="100"> <?php echo "</td>"; echo "</tr>";
 
  echo "<td>"; echo $row['description']; echo "</td>"; echo "</tr>";
   echo "<td>"; echo $row['price']; echo "</td>";

 echo "</tr>";
 
 }
 
 echo"</table>";
 
 ?>
Link to comment
Share on other sites

Yes it comes back with the below

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table WHERE id=1' at line 1

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.