Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by nit ( 13 years ago )
<?php
$conn=mysql_connect("localhost","root","")or die(mysql_error());
$db=mysql_select_db("puneet",$conn)or die("error in selecting db");

if(isset($_POST['submit'])){
 $strName = $_POST['name'];
 $strPass = $_POST['password'];
 $id = $_POST['id'];
 if($id > 0){ 
  $strQry = "UPDATE  fetch1 SET name = '".$strName."', email = '".$strEmail."', password = '".$strPass."'  where id=".$id;
 
 }else{
 $strQry = "INSERT INTO fetch1 (name,email,password) VALUES('".$strName."','".$strEmail."','".$strPass."')";
 }
 if(mysql_query($strQry)){
  $msg[]="Record Saved!!!";
  header("Location:fetch.php");
 }
}

 if(isset($_GET['del'])) 
 {
  $id = $_GET['del'];
  $query = "delete from fetch1 where id = '$id'";
  mysql_query($query);
 }
 else if(isset($_GET['mod'])) 
 {
  $id = $_GET['mod'];
  $query = "select * from fetch1 where id = '$id'";
  $result=mysql_query($query);
  
 while($resultset=mysql_fetch_array($result))
  {
  $rename=$resultset['name'];
  $remail=$resultset['email'];
  $repass=$resultset['password'];
  $reid=$resultset["id"];
  }
  
  
 }
 

// Saving Ended


 ?>

<html>
 <head><title>assignment</title></head>
 <body>
 <fieldset>
 <legend>Fill the form</legend>
 <form name="frm" method="post" acti>
 <input type="hidden" name="id" id="id" value="<?php if(isset($_GET['mod']))  echo $reid;?>" >
 <label>Name:</label>
 <input type="text" name="name" id="name" value="<?php if(isset($_GET['mod']))  echo $rename;?>"<br/>
 <label>Email:</label>
 <input type="text" name="email" id="email" value="<?php if(isset($_GET['mod']))  echo $remail;?>"<br/>
 <label>Password:</label>
 <input type="password" name="pass_word" id="pass_word" value="<?php if(isset($_GET['mod'])) echo $repass;?>"<br/>
 <input type="submit" name="submit" value="submit">
 <input type="reset" name="reset" value="reset">
 </fieldset>
 </form>
 
 <fieldset>
 <legend>Output:</legend>
 <form acti method="post">
 <?php
 $read=mysql_query("SELECT * FROM fetch1");
 echo"<table border=1 bgcolor=gray>";
 echo "<tr>
 <th> # </th>
 <th> id </th>
 <th> username </th>
 <th> email </th>
 <th> password </th>
 <th colspan=2>action</th>
 <tr>";
 while($x=mysql_fetch_array($read))
 {

 echo "<tr>";
 echo "<td><input type='checkbox' name='checkbox[]' id='checkbox[]' value='" . $x['id'] . "'> </td>";
 echo "<td>".$x['id']."</td>";
 echo "<td>".$x['name']."</td>";
 echo "<td>".$x['email']."</td>";
 echo "<td>".$x['password']."</td>";
 //echo "<td><img src='".$row[' width='50' height='50' alt='img' /></td>";
 echo "<td> <a del=".$x['id'].">delete </a></td>";
 echo "<td> <a mod=".$x['id'].">edit </a></td>";
 echo "<tr>";
 }
 echo "</table>";
 ?>
 

 <input type="submit" name="delete" value="delete">
 <?php
 if ((isset($_POST['delete'])) && (!empty($_POST['checkbox']))) 
 {
 foreach($_POST['checkbox'] as $did) 
 {
 $query = "DELETE FROM users WHERE id = $did";
 $link = mysql_query($query);
 }
 if($link)
 {
 echo "deleted sucessfully";
 }
  }
 ?>
 </form>
</fieldset>
</body>
</html>

 

Revise this Paste

Your Name: Code Language: