Jump to content

Archived

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

opel

Problem making update page..

Recommended Posts

I am trying to get my update script to work but for some reason I am getting an error when I try to pull the page content based on the id.

The error say that there is an undefined index but I have checked my table names and everything is fine? ???

[code]<?php
$id=$_GET['link_id'];
mysql_select_db($dbname, $conn);

$query=" SELECT * FROM tbl_links WHERE ID='$id'";
$result=mysql_query($query) or die("error querying database");
$num=mysql_num_rows($result);
mysql_close();

$i=0;
while ($i < $num)
{$linkID=mysql_result($result,$i,"link_id");
$categoryID=mysql_result($result,$i,"category_id");
$linkTitle=mysql_result($result,$i,"link_title");
$linkDescription=mysql_result($result,$i,"link_desc");
$linkURL=mysql_result($result,$i,"link_url");
$linkDisplay=mysql_result($result,$i,"link_display");

?>
<form action="updatescripts/updatelinks.php">
<input type="hidden" name="ud_id" value="<? echo "$linkID"; ?>">
<table cellpadding="5">
<tr>
<th width="120">Field Name</th>
<th width="378">Field Inputs</th>
</tr>
<tr>
<td width="120"><div align="right"><strong>Category :</strong></div></td>
<td>
<select name="inpCat">
  <?php


mysql_select_db($dbname, $conn);
$query_rsLinks = "SELECT * FROM categories ORDER BY category_name ASC";
$rsLinks = mysql_query($query_rsLinks, $conn) or die(mysql_error());
$row_rsLinks = mysql_fetch_assoc($rsLinks);
$totalRows_rsLinks = mysql_num_rows($rsLinks);
 
do { 
?>
  <option value="<?php echo $row_rsLinks['category_id']?>"><?php echo $row_rsLinks['category_name']?></option>
  <?php
} while ($row_rsLinks = mysql_fetch_assoc($rsLinks));
  $rows = mysql_num_rows($rsLinks);
  if($rows > 0) {
      mysql_data_seek($rsLinks, 0);
  $row_rsLinks = mysql_fetch_assoc($rsLinks);
  }

include ('../connections/dbclose.php');
?>

</select>
</td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Title :</strong></div></td>
<td><input type="text" name="inpTitle" value="<? echo $linkTitle ?>" class="inputbox" size="72" /></td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Description :</strong></div></td>
<td><input type="text" name="inpDescription" value="<? echo $linkDescription ?>" class="inputbox" size="72" /></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Link URL <em>('http;//' not required)</em> :</strong></div></td>
<td><input type="text" name="inpLinkUrl" value="<? echo $linkURL ?>" class="inputbox" size="72" /></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Display Link :</strong></div></td>
<td><input name="inpDisplay" type="checkbox" value="<? echo $linkDisplay ?>" class="inputbox" checked="CHECKED"/></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Click to submit :</strong></div></td>
<td><input type="submit" value="Add This Link" name="add" id="add"/></td>
</tr>
</table>
</form>
<?
++$i;
}
?>[/code]

Share this post


Link to post
Share on other sites
I altered my PHP code as I realisied that my id wasn't being passed properly but no I am getting Error querying Database.

[code]<?php
$id=$_GET['id'];
mysql_select_db($dbname, $conn);

$query=" SELECT * FROM tbl_links WHERE id=$id";
$result=mysql_query($query) or die("error querying database");
$num=mysql_num_rows($result);
mysql_close();

$i=0;
while ($i < $num)
{$linkID=mysql_result($result,$i,"link_id");
$categoryID=mysql_result($result,$i,"category_id");
$linkTitle=mysql_result($result,$i,"link_title");
$linkDescription=mysql_result($result,$i,"link_desc");
$linkURL=mysql_result($result,$i,"link_url");
$linkDisplay=mysql_result($result,$i,"link_display");

?>[/code]

Share this post


Link to post
Share on other sites
fixed it there were some errors with my SQL

[code]<?php
$id=$_GET['id'];
mysql_select_db($dbname, $conn);

$query="SELECT * FROM tbl_links, categories WHERE tbl_links.category_id = categories.category_id AND link_id=$id";
$result= mysql_query($query) or die("error querying database");
$num= mysql_num_rows($result);
mysql_close();

$i=0;
while ($i < $num)
{$linkID=mysql_result($result,$i,"link_id");
$categoryID=mysql_result($result,$i,"category_id");
$linkTitle=mysql_result($result,$i,"link_title");
$linkDescription=mysql_result($result,$i,"link_desc");
$linkURL=mysql_result($result,$i,"link_url");
$linkDisplay=mysql_result($result,$i,"link_display");

?>
<form action="updatescripts/updatelinks.php">
<input type="hidden" name="ud_id" value="<? echo "$linkID"; ?>">
<table cellpadding="5">
<tr>
<th width="120">Field Name</th>
<th width="378">Field Inputs</th>
</tr>
<tr>
<td width="120"><div align="right"><strong>Category :</strong></div></td>
<td>
<select name="inpCat">
  <?php


mysql_select_db($dbname, $conn);
$query_rsLinks = "SELECT * FROM categories ORDER BY category_name ASC";
$rsLinks = mysql_query($query_rsLinks, $conn) or die(mysql_error());
$row_rsLinks = mysql_fetch_assoc($rsLinks);
$totalRows_rsLinks = mysql_num_rows($rsLinks);
 
do { 
?>
  <option value="<?php echo $row_rsLinks['category_id']?>"><?php echo $row_rsLinks['category_name']?></option>
  <?php
} while ($row_rsLinks = mysql_fetch_assoc($rsLinks));
  $rows = mysql_num_rows($rsLinks);
  if($rows > 0) {
      mysql_data_seek($rsLinks, 0);
  $row_rsLinks = mysql_fetch_assoc($rsLinks);
  }

include ('../connections/dbclose.php');
?>

</select>
</td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Title :</strong></div></td>
<td><input type="text" name="inpTitle" value="<? echo $linkTitle ?>" class="inputbox" size="72" /></td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Description :</strong></div></td>
<td><input type="text" name="inpDescription" value="<? echo $linkDescription ?>" class="inputbox" size="72" /></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Link URL <em>('http;//' not required)</em> :</strong></div></td>
<td><input type="text" name="inpLinkUrl" value="<? echo $linkURL ?>" class="inputbox" size="72" /></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Display Link :</strong></div></td>
<td><input name="inpDisplay" type="checkbox" value="<? echo $linkDisplay ?>" class="inputbox" checked="CHECKED"/></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="120"><div align="right"><strong>Click to submit :</strong></div></td>
<td><input type="submit" value="Add This Link" name="add" id="add"/></td>
</tr>
</table>
</form>
<?
++$i;
}
?>[/code]

Share this post


Link to post
Share on other sites

×

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.