Forum Moderators: coopster
[edited by: eelixduppy at 3:16 pm (utc) on Mar 10, 2010]
[edit reason] removed URL [/edit]
$id=$_GET['user_id'];
$conn = connection
$conn = mysql_connect("hostname", "Your Username","password") or die(mysql_error());
mysql_select_db("mydb367", $conn)or die(mysql_error());
$query="SELECT * FROM `user` WHERE `user_id` = '".$id."'";
$result=mysql_query($query) or die(mysql_error());
//mysql_close(); this can be optional
if($result)
{
while ($num = mysql_fetch_object($result))
{
//getting info from DB, now process the form
?>
<form action="updated.php">
<input type="hidden" name="ud_id" value="<?php echo $id; ?>">
Username <input type="text" name="ud_username" value="<?php echo $num->$username; ?>"><br>
Password: <input type="text" name="ud_password" value="<?php echo $num->$password; ?>"><br>
Email: <input type="text" name="ud_email" value="<?php echo $num->$email; ?>"><br>
Name: <input type="text" name="ud_name" value="<?php echo $num->$name; ?>"><br>
Favclub: <input type="text" name="ud_favclub" value="<?php echo $num->$favclub; ?>"><br>
Startdate: <input type="datetime" name="ud_startdate" value="<?php echo $num->$startdate; ?>"><br>
<input type="Submit" value="Update">
</form>
<?php
}//close while
}//close if
else{//no data found/sent, throw clause to say!
echo "No data to get from the database!";
}
?>
Notice: Undefined index: user_id in /always/anonymize/your/paths/in/posts/expupdate.php on line 3
Line 3 is $id=$_GET['user_id']
<?PHP
error_reporting(E_ALL); //Comment out once you release
if (isset($_GET['user_id'])) {
$id = strip_tags($_GET['user_id']);//cleanse the input & assign to var
}
else {
echo "user id is not set";
exit;
}
$conn = your connection detail here ;)
mysql_select_db("mydb367", $conn)or die(mysql_error());
$query = "SELECT * FROM `user` WHERE `user_id` = '".$id."'";
$result = mysql_query($query, $conn) or die(mysql_error()); ;
$num = mysql_num_rows($result) or die( "Unable to query the database" .mysql_error());
<body>
<?php
$sql_user_id = "SELECT `user_id` FROM `user`";
$sql_send = mysql_query($sql_user_id, $conn) or die(mysql_error());
if ($sql_send)
{//do the fetch data loop
?>
<form action="expupdate.php" method="post">
<?php
while($got = mysql_fetch_object($mysql_send))
{
//build form
?>
<p><a href="expupdate.php?user_id=<?php echo $got->user_id?>">User id <?php echo $got->user_id;?></p>
<?php
}//close while loop
}
else{
echo "No data to get";
}
?>
</form>
</body>
</html>