Jump to content

[SOLVED] can anyone tell me why this isn't working please


shadiadiph

Recommended Posts

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> 

Link to comment
Share on other sites

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> 

Link to comment
Share on other sites

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> 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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> 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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!).

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.