• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
3,541
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
1
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. AssignmentTopic: PHP UPDATE & DELETE OPERATIONSubmitted Date: 12-NOV-2012, MONDAY
  • 2. Update Operation <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>Untitled Document</title> </head> <?php $uid = $_REQUEST[uid]; $con= mysql_connect("localhost","root",""); if($con) { mysql_select_db("bs_morning",$con); } if($_REQUEST[update]!="")
  • 3. { $uid = $_REQUEST[user_id]; $user_name = $_REQUEST[uname]; $email = $_REQUEST[email]; $qry = "UPDATE users SETuser_name=$user_name ,user_email=$email WHEREuser_id=$uid"; $rs = mysql_query($qry); if(mysql_affected_rows() > 0) { echo("Data Updated !!!"); } else { echo("not updated !!! "); } } $query = "SELECT * FROM users WHEREuser_id=$uid";
  • 4. $res = mysql_query($query); $row = mysql_fetch_array($res); ?> <body> <form> username : <input type="text" name="uname"value="<?php echo($row[user_name]); ?>" /> <br /> email : <input type="text" name="email" value="<?phpecho($row[user_email]); ?>" /> <br /> <input type="hidden" name="user_id" value="<?phpecho($uid); ?>" /> <input type="submit" name="update" value="UpdateRecord" /> </form> </body> </html>
  • 5. Delete Operation<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>Untitled Document</title><?php $con= mysql_connect("localhost","root",""); if($con) { mysql_select_db("bs_morning",$con); } Else { echo("server details invalid");
  • 6. } if ($_REQUEST[uid]!="") { $uid = $_REQUEST[uid]; $qry = "DELETE FROM users WHEREuser_id=$uid"; $rs = mysql_query($qry); } $query = "SELECT * FROM users"; $res = mysql_query($query);?><script type="text/javascript"> function confirmation() { return confirm("Are you Sure ??"); }</script></head><body>
  • 7. <table border="1"> <tr> <td>User ID</td><td>User Name</td><td>Email</td><td>Action</td></tr><?php while($rows=mysql_fetch_array($res)) { ?> <tr> <td><?php echo($rows[user_id]) ?></td> <td><?php echo($rows[user_name]) ?></td> <td><?php echo($rows[user_email]) ?></td> <td> <a href="edit.php?uid=<?php echo($rows[user_id]); ?>">Edit</a>
  • 8. <a href="?uid=<?php echo($rows[user_id]); ?>"onclick="return confirmation();" > Delete </a></td></tr><?php } ?></table></body></html>