Jump to content

[SOLVED] Retriving a Specific record and displaying it to be updated


Loathar

Recommended Posts

I've been able to create/edit and display all records but I am trying to make a page that will diplay all the data for one record.... and be able to it it

 

here is what i have for retrieving the record but its failing

what am i doing wrong?

 

I hate being such a Nub

 

----------------------------------------------------------------

<?php include("header.php"); ?>
<?php
include("library/db.php");

$Link = mysql_connect ($Host, $User, $Password);

$Query = "Select FROM $TableName WHERE id='$_POST[id]'";
$Result = mysql_db_query ($DBName, $Query, $Link);

/* In case of Error */

if (mysql_db_query ($DBName, $Query, $Link)) {


// Fetch the Results 
while ($Row = mysql_fetch_array ($Result)) 

print ("<table width=800 border=0 cellspacing=0 cellpadding=0>\n");
print ("  <tr>\n");
print ("    <td width=50 ><img src=images/spacer.gif width=50 height=1></td>\n");
print ("    <td class=text width=50 align=left><img src=images/spacer.gif width=50 height=1></td>\n");
print ("    <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n");
print ("    <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n");
print ("    <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n");
print ("    <td class=text width=100 align=left><img src=images/spacer.gif width=100 height=1></td>\n");
print ("  </tr>\n");
print ("  <tr>\n");
print ("    <td width=50> <img src= $Row[image] height=$imgh width=$imgw width=45></td>\n");
print ("    <td class=text width=50 align=left>$Row[id]</td>\n");
print ("    <td class=text width=200 align=left>$Row[name]</td>\n");
print ("    <td class=text width=200 align=left>$Row[price]</td>\n");
print ("    <td class=text width=200 align=left>$Row[description]</td>\n");
print ("    <td class=text width=100 align=left><a href=$Row[purchase]>Armory Link</a></td>\n");
print ("  </tr>\n");
print ("</table>\n");

	}  else {
		print ("<center><p class=note>REQUEST FAILED<br></center>\n");
		}
	mysql_close ($Link);
?>
<?php include("footer.php"); ?>

-----------------------------------------------
This is the parent page
----------------------------------------------
<form Action=HandleEdit.php Method=Post enctype=multipart/form-data>
<table width=550 border=0 align=center cellpadding=1 cellspacing=0 bgcolor=#333333>
  <tr>
   <td><table width=100% border=0 align=center cellpadding=4 cellspacing=0>
      <tr bgcolor=#000000>
        <td colspan=2 class=heading1>Edit a Member</td>
      </tr>
      <tr bgcolor=#eeeeee>
        <td class=text>Select a Member to Edit</td>
        <td><select name=id id=id>
<?php
include("library/db.php"); 
$Link = mysql_connect ($Host, $User, $Password);


$Query ="SELECT * from $TableName ORDER BY name";
$Result = mysql_db_query ($DBName, $Query, $Link);
// Before Selecte Menu


// Fetch the Results 

while ($Row = mysql_fetch_array ($Result)) 
{ 

print ("          <option value=$Row[id]>$Row[name]</option>\n");

}
mysql_close ($Link);




	  
// After Select menu
?>
          </select>
          </td>
      </tr>
      <tr bgcolor=#eeeeee>
        <td> </td>
        <td><input type=Submit name=Submit value=Edit></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>

Link to comment
Share on other sites

<?php

$Result = mysql_db_query ($DBName, $Query, $Link);

?>

 

change this for some error detection, let us know if the query is failing and with what error

 

<?php

$Result = mysql_db_query ($DBName, $Query, $Link) or die(mysql_error());

?>

Link to comment
Share on other sites

also i have noticed u dont have starting and closing brackets around your while loop.

 

<?php

/* In case of Error */

if (mysql_db_query ($DBName, $Query, $Link)) {
   
   
   // Fetch the Results 
while ($Row = mysql_fetch_array ($Result)) 

{ // Start of while loop
   
print ("<table width=800 border=0 cellspacing=0 cellpadding=0>\n");
print ("  <tr>\n");
print ("    <td width=50 ><img src=images/spacer.gif width=50 height=1></td>\n");
print ("    <td class=text width=50 align=left><img src=images/spacer.gif width=50 height=1></td>\n");
print ("    <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n");
print ("    <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n");
print ("    <td class=text width=200 align=left><img src=images/spacer.gif width=200 height=1></td>\n");
print ("    <td class=text width=100 align=left><img src=images/spacer.gif width=100 height=1></td>\n");
print ("  </tr>\n");
print ("  <tr>\n");
print ("    <td width=50> <img src= $Row[image] height=$imgh width=$imgw width=45></td>\n");
print ("    <td class=text width=50 align=left>$Row[id]</td>\n");
print ("    <td class=text width=200 align=left>$Row[name]</td>\n");
print ("    <td class=text width=200 align=left>$Row[price]</td>\n");
print ("    <td class=text width=200 align=left>$Row[description]</td>\n");
print ("    <td class=text width=100 align=left><a href=$Row[purchase]>Armory Link</a></td>\n");
print ("  </tr>\n");
print ("</table>\n");

} // End of while loop ----------------------

      }  else {
         print ("<center><p class=note>REQUEST FAILED<br></center>\n");
         }
      mysql_close ($Link);

?>

Link to comment
Share on other sites

mysql_db_query () is DEPRECATED so stop using it! Use mysql_connect (), mysql_select_db(), and mysql_query () instead! Also don't assume anything, always validate user inputs. Also print, echo , require, include... are *language construct* so you don't need to use *()* to enclose their values.

 

Here is an example with some code clean up, note, there is no right way to code in regards to coding style, this is just to give you an idea of how you might write a simple application that checks all of its actions before doing the next required action, "Logical Flow Control"

 

<?php

// form process page (HandleEdit.php)

include 'header.php';

include 'library/db.php';

if ( isset ( $_POST['id'] ) )
{
$Link = mysql_connect ( $Host, $User, $Password ) or die ( 'Database Connection Error: ' . mysql_error () );

mysql_select_db ( $DBName, $Link ) or die ( 'Select Database Error: ' . mysql_error () );

$Query = "SELECT * FROM $TableName WHERE id = '" . intval ( $_POST['id'] ) . "';";

$Result = mysql_query ( $Query, $Link ) or die ( 'Select Query Error: ' . mysql_error () );

if ( mysql_num_rows ( $Result ) > 0 )
{
	$Row = mysql_fetch_assoc ( $Result );
?>
<table width='800' border='0' cellspacing='0' cellpadding='0'>
<tr>
	<td width='50' >
		<img src='images/spacer.gif' width='50' height='1'>
	</td>
	<td class='text' width='50' align='left'>
		<img src='images/spacer.gif' width='50' height='1'>
	</td>
	<td class='text' width='200' align='left'>
		<img src='images/spacer.gif' width='200' height='1'>
	</td>
	<td class='text' width='200' align='left'>
		<img src='images/spacer.gif' width='200' height='1'>
	</td>
	<td class='text' width='200' align='left'>
		<img src='images/spacer.gif' width='200' height='1'>
	</td>
	<td class='text' width='100' align='left'>
		<img src='images/spacer.gif' width='100' height='1'>
	</td>
</tr>
<?php
echo "	<tr>
	<td width='50' >
		<img src='" . $Row['image'] . "' width='" . $imgw . "' height='" . $imgh . "'>
	</td>
	<td class='text' width='50' align='left'>
		" . $Row['id'] . "
	</td>
	<td class='text' width='200' align='left'>
		" . $Row['name'] . "
	</td>
	<td class='text' width='200' align='left'>
		" . $Row['price'] . "
	</td>
	<td class='text' width='200' align='left'>
		" . $Row['description'] . "
	</td>
	<td class='text' width='100' align='left'>
		<a href='" . $Row['purchase'] . "'>
			Armory Link
		</a>
	</td>
</tr>
</table>
";
}
else
{
	echo 'The query did not return a result set!';
}

mysql_free_result ( $Result );

mysql_close ( $Link );

}
else
{
echo 'The form input *id* was not submitted!';
}

include 'footer.php';

?>

 

<?php

// form submit page (?)

include 'library/db.php';

$Link = mysql_connect ( $Host, $User, $Password ) or die ( 'Database Connection Error: ' . mysql_error () );

mysql_select_db ( $DBName, $Link ) or die ( 'Select Database Error: ' . mysql_error () );

$Query = "SELECT * FROM " . $TableName . " ORDER BY name;";

$Result = mysql_query ( $Query, $Link ) or die ( 'Select Query Error: ' . mysql_error () );

if ( mysql_num_rows ( $Result ) > 0 )
{
?>
<form action='HandleEdit.php' Method='post'>
<table width='550' border='0' align='center' cellpadding='1' cellspacing='0' bgcolor='#333333'>
<tr>
	<td>
		<table width='100%' border='0' align='center' cellpadding='4' cellspacing='0'>
			<tr bgcolor='#000000'>
				<td colspan='2' class='heading1'>
					Edit a Member
				</td>
			</tr>
			<tr bgcolor='#eeeeee'>
				<td class='text'>
					Select a Member to Edit
				</td>
				<td>
					<select name='id' id='id'>
<?php
while ( $Row = mysql_fetch_assoc ( $Result ) ) 
{ 

	echo "							<option value='" . $Row['id'] . "'>" . $Row['name'] . "</option>\n";

}
?>
					</select>
				</td>
			</tr>
			<tr bgcolor='#eeeeee'>
				<td>
					 
				</td>
				<td>
					<input type='Submit' name='Submit' value='Edit'>
				</td>
			</tr>
		</table>
	</td>
</tr>
</table>
</form>
<?php
}
else
{
echo 'The query did not return any results!';
}

mysql_free_result ( $Result );

mysql_close ( $Link );

?>

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.