Jump to content


Photo

In Need of some help!


  • Please log in to reply
3 replies to this topic

#1 Andy Rixon

Andy Rixon

    Young Padawan

  • Members
  • Pip
  • 13 posts
  • Gender:Male
  • Location:Scotland, UK
  • Interests:PHP, MySQL CSS, HTML, My fiancee, My Daughter :D

Posted 23 January 2011 - 08:39 PM

Its strange of me to need help, because I programme a lot in php and mysql, but can't figure out whats wrong here.

Heres the code:

<?php
// Config File
include ("config.php");
// Get client id
$id = $_GET[ClientID];
// Query Database
$query = "SELECT * FROM clients WHERE ClientID = '$id' ORDER BY ClientID DESC LIMIT 1";
$result = mysql_query($query); 
// Check if database returns a problem or not
if (!$result) {
	echo "Unable to select data from table";
} else {
     while($row = mysql_fetch_array($result)):
?>
<form action="update.php?id=<?php echo '$id'; ?>" method="post">
  <table width="600" border="0" cellspacing="0" cellpadding="4">
	<tr>
  	<td width="142">Name:</td>
  	<td width="442"><label for="name"></label>
  	<input name="name" type="text" id="name" value="<?php echo $row['ClientName']; ?>"></td>
	</tr>
	<tr>
  	<td>Email:</td>
  	<td><label for="email"></label>
  	<input name="email" type="text" id="email" value="<?php echo $row['ClientEmail']; ?>"></td>
	</tr>
	<tr>
  	<td>&nbsp;</td>
  	<td><input type="submit" name="update" id="update" value="Update"></td>
	</tr>
  </table>
</form>
<?php endwhile ?>
<?php } ?>

When the page is loaded like "edit.php?id=5" it should display the form to edit a row in a database, but nothing shows, no errors, nothing, just a blank white page, can anyone help with this?

Edited by Andy Rixon, 23 January 2011 - 08:41 PM.


#2 gold killer

gold killer

    Young Padawan

  • Members
  • Pip
  • 14 posts

Posted 24 January 2011 - 05:50 AM

Try this

<?php
// Config File
include_once ("config.php");
// Get client id
$id = $_GET['clientid'];
// Security
if( !is_numeric( $id ) )
{
	die( 'You have entered an invalid client id, please try again. If this continues to occur please contact the webmaster.' );	
}
// Query Database
$query = @mysql_query( "SELECT `ClientName`, `ClientEmail` FROM `clients` WHERE `ClientID` = '{$id}' ORDER BY `ClientID` DESC LIMIT 1;" ) or die( 'Query Error: ' . mysql_error()); 
// Check if database returns a problem or not
$row = mysql_fetch_object( $query );
?>
<form action="update.php?id=<?php echo $id; ?>" method="post">
  <table width="600" border="0" cellspacing="0" cellpadding="4">
        <tr>
        <td width="142">Name:</td>
        <td width="442"><label for="name"></label>
        <input name="name" type="text" id="name" value="<?php echo $row->ClientName; ?>"></td>
        </tr>
        <tr>
        <td>Email:</td>
        <td><label for="email"></label>
        <input name="email" type="text" id="email" value="<?php echo $row->ClientEmail; ?>"></td>
        </tr>
        <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="update" id="update" value="Update"></td>
        </tr>
  </table>
</form>

Edited by gold killer, 24 January 2011 - 11:03 AM.


#3 gold killer

gold killer

    Young Padawan

  • Members
  • Pip
  • 14 posts

Posted 24 January 2011 - 11:04 AM

He could still do example.com/?clientid=1

#4 Andy Rixon

Andy Rixon

    Young Padawan

  • Members
  • Pip
  • 13 posts
  • Gender:Male
  • Location:Scotland, UK
  • Interests:PHP, MySQL CSS, HTML, My fiancee, My Daughter :D

Posted 24 January 2011 - 11:30 AM

Try this

<?php
// Config File
include_once ("config.php");
// Get client id
$id = $_GET['clientid'];
// Security
if( !is_numeric( $id ) )
{
	die( 'You have entered an invalid client id, please try again. If this continues to occur please contact the webmaster.' );	
}
// Query Database
$query = @mysql_query( "SELECT `ClientName`, `ClientEmail` FROM `clients` WHERE `ClientID` = '{$id}' ORDER BY `ClientID` DESC LIMIT 1;" ) or die( 'Query Error: ' . mysql_error()); 
// Check if database returns a problem or not
$row = mysql_fetch_object( $query );
?>
<form action="update.php?id=<?php echo $id; ?>" method="post">
  <table width="600" border="0" cellspacing="0" cellpadding="4">
        <tr>
        <td width="142">Name:</td>
        <td width="442"><label for="name"></label>
        <input name="name" type="text" id="name" value="<?php echo $row->ClientName; ?>"></td>
        </tr>
        <tr>
        <td>Email:</td>
        <td><label for="email"></label>
        <input name="email" type="text" id="email" value="<?php echo $row->ClientEmail; ?>"></td>
        </tr>
        <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="update" id="update" value="Update"></td>
        </tr>
  </table>
</form>


This did not work, displays the error, when I know that the Client ID is correct.

You need to use the $_GET correctly, depending on how you want your URL to look.

By reading your code and comments.. you would need this.

$id = $_GET['id'];


Using $_GET['ClientID'] will return nothing as that is the database field name, not the url segment.


ClientID is the database field name. but I have done what you suggested and it worked. sorry, when I wrote the code it was late at night and I was tired.

Thanks for the help :D

Edited by Andy Rixon, 24 January 2011 - 11:33 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users