How to update a single database row without having to update all the rows
Please look at code and give me ideas to how i can solve this:
PHP Code:
<?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION['id'];
$username = $_SESSION['username'];
include("../adminonly/admin.php");
if ($_POST['updateinfo']){
// get the form data
$getname = mysql_real_escape_string(stripslashes($_POST['name']));
$getbio = mysql_real_escape_string(stripslashes($_POST['bio']));
$getlocation = mysql_real_escape_string(stripslashes($_POST['location']));
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
// update fullname
if ($getname){
$insert = mysql_query("UPDATE members SET name='$getname' WHERE username='$username'");
mysql_query($insert);
echo "<font color='#999'>Your info has been updated!</font><br/><br/>";
}
//update bio
if ($getbio){
$insert = mysql_query("UPDATE members SET bio='$getbio' WHERE username='$username'");
mysql_query($insert);
echo "<font color='#999'>Your info has been updated!</font><br/><br/>";
}
//update location
if ($getlocation){
$insert = mysql_query("UPDATE members SET location='$getlocation' WHERE username='$username'");
mysql_query($insert);
echo "<font color='#999'>Your info has been updated!</font><br/><br/>";
//update avatar
if ($name){
$userimage = "avatar/$name";
move_uploaded_file($tmp_name, $userimage);
$insert = mysql_query("UPDATE members SET avatar='$userimage' WHERE username='$username'");
mysql_query($insert);
echo "<font color='#999'>Your Avatar has been updated!</font><br/><br/>";
}
}
}
?>
<html>
<title>Members Page</title>
<head></head>
<body>
<?php
if ($username){
echo "Welcome <b>$username</b>, <a href='./logout.php'>Logout</a>";
echo "<br /><a href='./resetpass.php'>Reset Your Password</a>";
}
else
echo "Please login to access this page. <a href='./login.php'>Login Here</a>";
$form = "<form action='./member.php' method='post' enctype='multipart/form-data'>
<table>
<tr>
<td>Fullname:</td>
<td><input type='text' name='name' value='$getname'/></td>
</tr>
<tr>
<td>Bio:</td>
<td><textarea name='bio' value='$getbio'></textarea></td>
</tr>
<tr>
<td>Location:</td>
<td><input type='text' name='location' value='$getlocation'/></td>
</tr>
<tr>
<td>Avatar: </td>
<td><input type='file' name='myfile'/></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='updateinfo' value='Update info' /></td>
</tr>
</table>
</form>";
echo $form;
$get = mysql_query("SELECT * FROM members WHERE username='$username'");
$numrows = mysql_num_rows($get);
if ($get < 1){
echo "No results found!";
}
else{
while ($row = mysql_fetch_array($get)){
$dbuser = $row['username'];
$getname = $row['name'];
$getbio = $row['bio'];
$getlocation = $row['location'];
$getuserimage = $row['avatar'];
$user_results = "<form action='./member.php'>
<table>
<tr>
<td><b></b></td>
<td><img src='$getuserimage' width='100' height='100'></td>
</tr>
<tr>
<td><b>Fullname:</b></td>
<td>$getname</td>
</tr>
<tr>
<td><b>Bio:</b></td>
<td>$getbio</td>
</tr>
<tr>
<td><b>Location:</b></td>
<td>$getlocation</td>
</tr>
</table>
</form>";
echo $user_results;
}
}
?>
</body>
</html>