hance2105 Posted June 22, 2013 Share Posted June 22, 2013 hello guys, when i run the code below, i get the following error message - Undefined variable: prod_id in C:\wamp\www\buysmart_site\my_list.php on line 50 <?php session_start(); include "db_connect.php"; $username = $_SESSION['username']; $sql=mysql_query("select user_id from tbllogin where username = '$username'"); $row=mysql_fetch_array($sql); $sql1 = mysql_query("select a.prod_name, a.prod_photo from tbl_product a, tblfavourites b where a.prod_id=b.prod_id AND b.user_id='$row[user_id]'"); $row1=mysql_fetch_array($sql1); if($row1){ echo "<table border='0'>";//start table // our table heading echo "<tr>"; echo "<th class='textAlignLeft'>Name</th>"; echo "<th>Product</th>"; echo "<th>Action</th>"; echo "</tr>"; //also compute for total price $totalPrice = 0; while ($row1 = mysql_fetch_assoc($sql1)){ extract($row1); //$totalPrice += $prod_price; //creating new table row per record echo "<tr>"; echo "<td>{$prod_name}</td>"; echo '<td><img height="100" width="100" src="Images/Products/'.$row1['prod_photo'].'"/></td>'; echo "<td class='textAlignCenter'>"; echo "<a href='removefav.php?prod_id={$prod_id}&prod_name={$prod_name}' class='customButton'>"; echo "<img src='' title='Remove from favourite' />"; echo "</a>"; echo "</td>"; echo "</tr>"; } /* echo "<tr>"; echo "<th class='textAlignCenter'>Total Price</th>"; echo "<th class='textAlignRight'>{$totalPrice}</th>"; echo "<th></th>"; echo "</tr>"; echo "</table>"; echo "<br /><div><a href='#' class='customButton'>Home</a></div>"; }else{ echo "<div>No products found in your favourites. </div>"; } //else{ echo "<div>No products in favourites yet.</div>";//} */} ?> the prod_id is the product id that is stored in 2 tables - tbl_product and tblfavourites how can i sort this issue out? Quote Link to comment https://forums.phpfreaks.com/topic/279457-undefined-variable-error-message-when-running-code/ Share on other sites More sharing options...
darkfreaks Posted June 22, 2013 Share Posted June 22, 2013 where is it defined in the code? i am not seeing this. please give the full code or where $prod_id is defined within the code. Quote Link to comment https://forums.phpfreaks.com/topic/279457-undefined-variable-error-message-when-running-code/#findComment-1437400 Share on other sites More sharing options...
hance2105 Posted June 22, 2013 Author Share Posted June 22, 2013 prod_id is not defined in this code....how do i define it? it is found in tbl_product and i call it in tblfavourites Quote Link to comment https://forums.phpfreaks.com/topic/279457-undefined-variable-error-message-when-running-code/#findComment-1437408 Share on other sites More sharing options...
Solution Psycho Posted June 22, 2013 Solution Share Posted June 22, 2013 Since you are using it within a loop that is processing record from the DB, I suggest you include that ID in the SELECT part of your query so it will be available in the loop. Quote Link to comment https://forums.phpfreaks.com/topic/279457-undefined-variable-error-message-when-running-code/#findComment-1437409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.