Webocreation

Monday, February 8, 2010

Edit the row from the database

<?php

if(isset($_GET['user_id']))
{
$user_id=$_GET['user_id'];
}
else if(isset($_POST['user_id']))
{
$user_id=$_POST['user_id'];
}
else
{
$user_id=0;
}


if($user_id!=0)
{

//echo "$name $address $user_name $pass";
if (mysql_connect("localhost","root",""))
{

//echo "connected";
mysql_select_db("php_classes");



if(isset($_POST['button']))
{


$name=$_POST['name'];

$address=$_POST['address'];

$user_name=$_POST['user_name'];




$query1="select user_id from profile where user_id=$user_id";

$result1=mysql_query($query1);
if(mysql_num_rows($result1)==0)
{
echo "This username is not available";
}
else
{


$query="update profile set name='$name',address='$address',user_name='$user_name' where user_id=$user_id limit 1";
//echo $query;

$result=mysql_query($query);

if (mysql_affected_rows()==1)
{
echo "Data has been updated";
}
else
{
echo "Data has been not been updated";
}
}








}//end of submit



$query11="select * from profile where user_id=$user_id";
//echo $query11;
$result11=mysql_query($query11);
$rows=mysql_fetch_array($result11,MYSQL_ASSOC);



?>





<form id="form1" name="form1" method="post" action="edit.php">
<p>Name
<label>
<input type="text" name="name" id="name" value="<?php echo $rows['name']; ?>" />
</label>
</p>
<p>Address
<input type="text" name="address" id="address" value="<?php echo $rows['address']; ?>" />
</p>
<p>Username
<input type="text" name="user_name" id="user_name" value="<?php echo $rows['user_name']; ?>"/>
</p>
<input type="hidden" name="user_id" value="<?php echo $user_id; ?>" />
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>


<?php
/*
mysql_connect()//connects
mysql_select_db()//
mysql_query()//passes query to mysql from php/
//CUD-Create-Unpdate-Delete---
//R-Read
mysql_affected_rows
mysql_num_rows
mysql_fetch_array
*/
}
else
{
echo "Could not connect to database";
}


}
else
{
echo "No user id Found";
}

?>
Edit the row from the database

No comments:

Post a Comment