Jump to content

Recommended Posts

I have been trying to my update script to post the changes to the Database, but it just is not happening  ??? I've read through every book and tutorial I have but can't see where I am going wrong.

Could anyone who thinks they can help have a look please. The error I am getting says that I have an undefined index. I have attached the file and update script that I'm using.

[b]Update form[/b]
[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="inpID" 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]

[b]Update Post Script[/b]
[code]<?
include ('../../connections/dbconn.php');

$linkID = $_POST['inpID'];
$linkTitle = $_POST['inpTitle'];
$linkDesc = $_POST['inpDescription'];
$linkUrl = $_POST['inpLinkUrl'];
$linkCategory = $_POST['inpCat'];
$linkDisplay = $_POST['inpDisplay'];


$query = "UPDATE tbl_links SET link_title='$linkTitle', link_desc='$linkDesc', link_url='$linkUrl', category_id='$linkCategory', link_display='$linkDisplay' WHERE link_id='$linkID'";
mysql_select_db($dbname, $conn) or die( "Unable to select database");
mysql_query($query);
echo "<p class='message'>You have successfully edited a link, click here to <a href='edit_link.php'>edit another link</a></p>";
mysql_close();
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/22663-error-updating-info-to-a-database/
Share on other sites

I have attached a screen grab and pasted copy of the code. The error appears when I click the submit form and the update script is activated.

[code]Notice: Undefined index: inpID in /Users/andrewcetnarskyj/Sites/GunkAdmin/central/updatescripts/updatelinks.php on line 4

Notice: Undefined index: inpTitle in /Users/andrewcetnarskyj/Sites/GunkAdmin/central/updatescripts/updatelinks.php on line 5

Notice: Undefined index: inpDescription in /Users/andrewcetnarskyj/Sites/GunkAdmin/central/updatescripts/updatelinks.php on line 6

Notice: Undefined index: inpLinkUrl in /Users/andrewcetnarskyj/Sites/GunkAdmin/central/updatescripts/updatelinks.php on line 7

Notice: Undefined index: inpCat in /Users/andrewcetnarskyj/Sites/GunkAdmin/central/updatescripts/updatelinks.php on line 8

Notice: Undefined index: inpDisplay in /Users/andrewcetnarskyj/Sites/GunkAdmin/central/updatescripts/updatelinks.php on line 9

You have successfully edited a link, click here to edit another link[/code]

[attachment deleted by admin]
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.