Jump to content

passing value with button....pls help


saradrungta

Recommended Posts

actually i m displaying all the records in my DB, and want to allow user to see and edit any data which he wish to edit.

 

but the code i mentioned, it display the UID on BUTTON,

 

instead i want that it should display EDIT on button and pass UID in $_POST['edit']

 

pls help

<?php

// Connect to server and select databse.

mysql_connect("localhost","root","")or die("cannot connect");

mysql_select_db("sarad")or die("cannot select DB");

 

//Display all the Records//

$sql="SELECT * FROM studentrec";

$result=mysql_query($sql);

mysql_num_rows($result);

?>

 

<form method="post" action="adelete.php">

<table width="100%" border="1" cellpadding="3" cellspacing="1">

<tr>

<th colspan="5" align="center">Delete multiple rows in mysql</th>

</tr>

<tr>

<th>DELETE</th>

<th>Edit</th>

<th>Id</th>

<th>Name</th>

<th>Age</th>

<th>City</th>

</tr>

<?php

while($rows=mysql_fetch_array($result)){

?>

<tr>

<td><input type="checkbox" name= "delid[]" value="<?php echo $rows['UID']; ?>"></td>

<td><input type="hidden" name="uid" value="<?php echo $rows['UID']; ?>" />

<input type="submit" name="edit" value="EDIT"></td>

<td><?php echo $rows['UID']; ?></td>

<td><?php echo $rows['Name']; ?></td>

<td><?php echo $rows['age']; ?></td>

<td><?php echo $rows['city']; ?></td>

</tr>

<?php

}

?>

<tr>

<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>

</tr>

<?php

 

//checking edit button value

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

echo $_POST['uid'];

 

}

 

// Check if delete button active, start this

 

if($_POST['delete']){

$del_id = $_POST['delid'];

 

foreach($_POST['delid'] as $id){

$delque="delete from studentrec where(UID='$id')";

$q=mysql_query($delque) or die(mysql_error());

printf("Records deleted: %d\n", mysql_affected_rows());

 

}

 

// if successful redirect to delete_multiple.php

 

if($q){

echo "<meta http-equiv=refresh content=0;URL=adelete.php>";

}

 

}

mysql_close();

?>

 

</table>

</form>

</td>

</tr>

</table>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.