Jump to content


Photo

Problem making update page..


  • Please log in to reply
2 replies to this topic

#1 opel

opel
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 30 September 2006 - 03:19 PM

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

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


#2 opel

opel
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 30 September 2006 - 04:09 PM

I altered my PHP code as I realisied that my id wasn't being passed properly but no I am getting Error querying Database.

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

?>


#3 opel

opel
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 30 September 2006 - 06:49 PM

fixed it there were some errors with my SQL

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users