shadiadiph Posted December 19, 2008 Share Posted December 19, 2008 this page has a form the url has carried the id=3 for cid but doesn't display in the page what is wrong with my coding please? ??? <? $cid = $_GET["cid"]; if($cid==""){ $sql = "SELECT * FROM tblcatdetails where intCatID='$cid'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $cid = $row["intCatID"]; $category = $row["category"]; }} ?> <table class="category" > <form name="addcategory" method="post" action="subcatsubmit.php" > <input type="hidden" name="adminlogged" value="<?=$row["vcUserID"]?>" /> <input type="hidden" name="loggedid" value="<?=$row["intLoginID"]?>" /> <input type="hidden" name="catid" value="<?=$row["intCatID"]?>" /> <tr><td>CATEGORY NAME</td></tr> <tr><td><input type="text" name="category" value="<?=$row["category"]?>" /></td></tr> <tr><td>SUB CATEGORY NAME</td></tr> <tr><td><input type="text" name="subcategory" value="" /></td></tr> <tr><td colspan="2"> </td></tr> <tr><td colspan="2"> <input class="button" name="submit" type="submit" value="Preview" /> <input class="button" type="reset" name="reset" value="Reset Form" /> </td></tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 19, 2008 Share Posted December 19, 2008 if($cid==""){ It should be if($cid!=""){ I believe. Or even better if(!empty($cid)){ Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted December 19, 2008 Author Share Posted December 19, 2008 mmm doesn't work thanks for trying Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 Actually I take that back I think I misread the question lol. what does the url look like and mchl was right it should be what he said. oh yeah and where in your query should be WHERE. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 19, 2008 Share Posted December 19, 2008 What do you get when you do a "view source" of the page in your browser? Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted December 19, 2008 Author Share Posted December 19, 2008 yes i changed it to just to get the value of cid which has been carried the url browser bar says http://asiapacificsolutions.net/hmt/secure/admin/category/addsubcategory.php?cid=3 so the value 3 is there but $cid=$_GET["cid"] doesn't set any value for it I don't get it? The html source code says all the val;ues in the form ="" nothing?? <? $cid = $_GET["cid"]; $sql = "SELECT * FROM tblcatdetails where intCatID='$cid'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $cid = $row["intCatID"]; $category = $row["category"]; } ?> <table class="category" > <form name="addcategory" method="post" action="subcatsubmit.php" > <input type="hidden" name="adminlogged" value="<?=$row["vcUserID"]?>" /> <input type="hidden" name="loggedid" value="<?=$row["intLoginID"]?>" /> <input type="hidden" name="catid" value="<?=$row["intCatID"]?>" /> <tr><td>CATEGORY NAME</td></tr> <tr><td><input type="text" name="category" value="<?=$row["category"]?>" /></td></tr> <tr><td>SUB CATEGORY NAME</td></tr> <tr><td><input type="text" name="subcategory" value="" /></td></tr> <tr><td colspan="2"> </td></tr> <tr><td colspan="2"> <input class="button" name="submit" type="submit" value="Preview" /> <input class="button" type="reset" name="reset" value="Reset Form" /> </td></tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 I don't know if this makes a difference but I always use single quotes. Also I would not use short_open_tags either. try this: <?php $cid = $_GET['cid']; $sql = "SELECT * FROM tblcatdetails WHERE intCatID='$cid'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $cid = $row['intCatID']; $category = $row['category']; } ?> <table class="category" > <form name="addcategory" method="post" action="subcatsubmit.php" > <input type="hidden" name="adminlogged" value="<?=$row['vcUserID']?>" /> <input type="hidden" name="loggedid" value="<?=$row['intLoginID']?>" /> <input type="hidden" name="catid" value="<?=$row['intCatID']?>" /> <tr><td>CATEGORY NAME</td></tr> <tr><td><input type="text" name="category" value="<?=$row['category']?>" /></td></tr> <tr><td>SUB CATEGORY NAME</td></tr> <tr><td><input type="text" name="subcategory" value="" /></td></tr> <tr><td colspan="2"> </td></tr> <tr><td colspan="2"> <input class="button" name="submit" type="submit" value="Preview" /> <input class="button" type="reset" name="reset" value="Reset Form" /> </td></tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 19, 2008 Share Posted December 19, 2008 Add the following two lines immediately after your first opening <? (or more properly <?php) tag - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 Another question I have for you is how many results should you get from this query? is it going to be only 1 or can it be more? Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted December 19, 2008 Author Share Posted December 19, 2008 should only be one result intCatID 3 but could be different if a different object is selected on the page the item is selected on so i can just give $cid the value of 3 wouldn't work. I added this ini_set ("display_errors", "1"); error_reporting(E_ALL); showed no errors but doesn't display anything still? Quote Link to comment Share on other sites More sharing options...
Mad Mick Posted December 19, 2008 Share Posted December 19, 2008 At the end of the while loop $row ends up containing nothing (i.e. it is false) - that is how it gets out of the loop. You use the elements of $row after the while loop, at that point they will all equal nothing. If you enabled full error reporting I would expect you to see the notice - index does not exist for all your form elements. Change your code so that the form is populated with $row data inside the while loop. Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 Or he can keep it the way that it is and just take out the while loop. If you are only returning 1 result you can do it like this: <?php $cid = $_GET['cid']; $sql = "SELECT * FROM tblcatdetails WHERE intCatID='$cid'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $cid = $row['intCatID']; $category = $row['category']; } ?> <table class="category" > <form name="addcategory" method="post" action="subcatsubmit.php" > <input type="hidden" name="adminlogged" value="<?=$row['vcUserID']?>" /> <input type="hidden" name="loggedid" value="<?=$row['intLoginID']?>" /> <input type="hidden" name="catid" value="<?=$row['intCatID']?>" /> <tr><td>CATEGORY NAME</td></tr> <tr><td><input type="text" name="category" value="<?=$row['category']?>" /></td></tr> <tr><td>SUB CATEGORY NAME</td></tr> <tr><td><input type="text" name="subcategory" value="" /></td></tr> <tr><td colspan="2"> </td></tr> <tr><td colspan="2"> <input class="button" name="submit" type="submit" value="Preview" /> <input class="button" type="reset" name="reset" value="Reset Form" /> </td></tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted December 19, 2008 Author Share Posted December 19, 2008 mm I took the loop out a while ago and got it working now this is how still don't get why it didn't like the <?=$row[ usually it worls fine. this is how it ended up. Thanks for the input guys. <table class="category" > <form name="addcategory" method="post" action="subcatsubmit.php" > <input type="hidden" name="adminlogged" value="<?=$row["vcUserID"]?>" /> <input type="hidden" name="loggedid" value="<?=$row["intLoginID"]?>" /> <? $cid = $_GET["cid"]; $sql = "SELECT * FROM tblcatdetails where intCatID='$cid'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $cid = $row["intCatID"]; $category = $row["category"]; } ?> <tr><td>CATEGORY NAME</td></tr> <tr><td><input type="text" name="category" value="<?=$category?>" /></td></tr> <tr><td>SUB CATEGORY NAME</td></tr> <tr><td><input type="text" name="subcategory" value="" /></td></tr> <tr><td colspan="2"> </td></tr> <tr><td colspan="2"> <input type="hidden" name="cid" value="<?=$cid?>" /> <input class="button" name="submit" type="submit" value="Preview" /> <input class="button" type="reset" name="reset" value="Reset Form" /> </td></tr> </table> </form> I had to move the php down the form as it was already calling php from the head without moving it down it cancelled out the first bit of php in my header. Quote Link to comment Share on other sites More sharing options...
Mad Mick Posted December 19, 2008 Share Posted December 19, 2008 When you do a mysql_fetch_assoc it extracts the data then increments the pointer to the SQL table. The while loop keeps running until $row is false i.e. there is no data left to extract and so $row is empty. So you can't use $row after the while loop. In this situation you don't need a while loop anyway because you only want one row (As ngreenwood has said!). Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted December 19, 2008 Author Share Posted December 19, 2008 thanks for the help guys Quote Link to comment 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.