Jump to content

Undefined Variable Issue


Aido89

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
https://forums.phpfreaks.com/topic/280159-undefined-variable-issue/
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>";
 
 ?>

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>";
 
 ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.