0

Hello I find a tutorial on www.phpeasystep.com about updating multiple records can anyone tell me how to make it work for php 5. When I click on update it shows the same page ...Please any help would be appreciated

1
Contributor
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Nigelmerle
0

here is my code...can anyone help me find a solution .
I'm trying hard to make it work. Please help

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Update a User</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="css/style.css" media="all" />
</head>
<body >

<div id="wrap"> 
<div id="right">
<div id="header">
  <div id="logo2">Update a User</div>
   </div>


 <div id="back"> <a href="admin-index.php"><font size="4px"><u>Back</u></font></a> </div>  

<strong>Update multiple rows in mysql</strong><br>

<?php


//Include database connection details and select database
require_once('config.php');


function clean($str) {
		$str = @trim($str);
		if(get_magic_quotes_gpc()) {
			$str = stripslashes($str);
		}
		return mysql_real_escape_string($str);
	}


$member_id = @$_POST['member_id'];
$firstname = @$_POST['firstname'];
$lastname = @$_POST['lastname'];
$email = @$_POST['email'];


$tbl_name="members"; // Table name

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0" align="center">
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0" align="center">


<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>First name</strong></td>
<td align="center"><strong>Last name</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><?php $member_id[]=$rows['member_id']; ?><?php echo $rows['member_id']; ?></td>
<td align="center"><input name="firstname[]" type="text" id="firstname" value="<?php echo $rows['firstname']; ?>"></td>
<td align="center"><input name="lastname[]" type="text" id="lastname" value="<?php echo $rows['lastname']; ?>"></td>
<td align="center"><input name="email[]" type="text" id="email" value="<?php echo $rows['email']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submitbtn" value="Update"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if(isset($_POST['Submitbtn'])){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET firstname='$firstname[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE member_id='$member_id[$i]'";
$result1=mysql_query($sql1);
}

if($result1)
header("location:addartist-success.php");

}


mysql_close();
?>

        
  


     
</div>
  
  <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div style="clear: both;"> </div>

<?php
include("include/footeradmin.php");
?>
</div>
</body>
</html>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

Is there anyone here. I would be very grateful if anyone could help with the code above. Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.