netman182 Posted January 25, 2010 Share Posted January 25, 2010 Hey there i have some code i need to update multiple records at one time. can i get some help. i have a page that selects what team i want to edit the stats for. then it sends it to another page where i can make changes to the stats. I can't figure this out at all. why is it not updating the players DB. i have another page where it is just changed approved field and that works fine but this is not. am i not doing something right. i will include the drop-down list page and the stats edit page as well as the page where i am just changing the approved field. thanks in advance. stefan drop.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//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> <body> <form id="teamsearch" name="teamsearch" method="post" action="update_multiple.php"> <p> </p> <p> <label> <?php include 'dbc.php'; $query="SELECT teamname,teamid FROM teams"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=teamid value='$nt[teamid]'>Team Name</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value='$nt[teamid]'>$nt[teamname]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> <input name="submit" type="submit" id="submit" value="Submit" /> </form> <p> </p> <p> </p> </body> </html> Update_multiple.php <?php include 'dbc.php'; $tbl_name="players"; // Table name // Connect to server and select databse. $sql="select * from players where teamid='$_POST[teamid]'"; $result=mysql_query($sql); // Count table rows // $count=mysql_num_rows($result); // Count table rows $count=mysql_num_rows($result); echo 'count='.$count; ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <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>Team ID</strong></td> <td align="center"><strong>Games Played</strong></td> <td align="center"><strong>Goals</strong></td> <td align="center"><strong>Assists</strong></td> <td align="center"><strong>Points</strong></td> <td align="center" bgcolor="#FFFF00"><strong>Yellow Cards</strong></td> <td align="center" bgcolor="#FF0000"><strong>Red Cards</strong></td> <td align="center"><strong>Suspension</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $id[]=$rows['ID']; ?><? echo $rows['ID']; ?></td> <td align="center"><input name="first[]" type="text" id="first" size="15" value="<? echo $rows['first']; ?>" disabled="disabled"></td> <td align="center"><input name="last[]" type="text" id="last" size="15" value="<? echo $rows['last']; ?>" disabled="disabled"></td> <td align="center"><input name="teamid[]" type="text" id="teamid" size="15" value="<? echo $rows['teamid']; ?>" disabled="disabled"></td> <td align="center"><input name="gp[]" type="text" id="gp" size="10" value="<? echo $rows['gp']; ?>"></td> <td align="center"><input name="goal[]" type="text" id="goal" size="10" value="<? echo $rows['goal']; ?>"></td> <td align="center"><input name="assist[]" type="text" id="assist" size="10" value="<? echo $rows['assist']; ?>"></td> <td align="center"><input name="point[]" type="text" id="point" size="10" value="<? echo $rows['point']; ?>"></td> <td align="center"><input name="yellow[]" type="text" id="yellow" size="10" value="<? echo $rows['yellow']; ?>"></td> <td align="center"><input name="red[]" type="text" id="red" size="10" value="<? echo $rows['red']; ?>"></td> <td align="center"><input name="susp[]" type="text" id="susp" size="10" value="<? echo $rows['susp']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE `players` SET `gp`='{$gp[$i]}', `goal`='{$goal[$i]}', `assist`='{$assist[$i]}', `point`='{$point[$i]}', `yellow`='{$yellow[$i]}', `red`='{$red[$i]}', `susp`='{$susp[$i]}' WHERE `ID`='$ID[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update_multiple.php"); } ?> playercheck.php <?php /* For the following details, ask your server vendor */ $dbhost = "localhost"; $dbuser = "netman13_adminbc"; $dbpass = "95887rj"; $dbname = "netman13_bccsltest"; mysql_connect( $dbhost, $dbuser, $dbpass ) or die ( "Unable to connect to MySQL server" ); mysql_select_db( "$dbname" ); mysql_query( "SET NAMES utf8" ); if(isset($_POST["update"]) AND isset($_POST["hiddenid"])) { $updated=false; $activateapproved=array(); $deactivateapproved=array(); foreach($_POST["hiddenid"] AS $value) { if(isset($_POST["checkboxapproved"][$value])) $activateapproved[]=intval($value); else $deactivateapproved[]=intval($value); } if(count($activateapproved)>0) { $SQL=sprintf("UPDATE players SET approved=1 WHERE ID in (%s)" , implode(",", $activateapproved)); mysql_query($SQL) OR DIE(mysql_error()); $updated=true; } if(count($deactivateapproved)>0) { $SQL=sprintf("UPDATE players SET approved=0 WHERE ID in (%s)" , implode(",", $deactivateapproved)); mysql_query($SQL) OR DIE(mysql_error()); $updated=true; } if($updated==true) { header("Location: ".$_SERVER["PHP_SELF"].""); exit(); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//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> <script type="text/javascript" src="public_smo_scripts.js"></script> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <body> <?php if(isset($_GET["todo"]) AND $_GET["todo"]=="updated") { echo "Updated succesfully"; } ?> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="Form"> <table border="1" cellpadding="2" cellspacing="2"> <tr> <td><div align="center">First</div></td> <td><div align="center">Last</div></td> <td><div align="center">Address</div></td> <td><div align="center">City</div></td> <td><div align="center">Postal</div></td> <td><div align="center">Phone #</div></td> <td><div align="center">Feet</div></td> <td><div align="center">Inches</div></td> <td><div align="center">weight</div></td> <td><div align="center">Year</div></td> <td><div align="center">Month</div></td> <td><div align="center">Day</div></td> <td><div align="center">Team ID</div></td> <td><div align="center">Type</div></td> <td><div align="center">Approved</div></td> </tr> <?php $sql="select * from players where teamid='$_POST[teamid]'"; $res=mysql_query($sql) or die(mysql_error()); while($r=mysql_fetch_assoc($res)) { ?> <tr> <input type="hidden" name="hiddenid[]" value="<?php echo $r["ID"]?>"> <td> <div align="center"><?php echo empty($r["first"])?' ':htmlspecialchars($r["first"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["last"])?' ':htmlspecialchars($r["last"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["address"])?' ':htmlspecialchars($r["address"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["city"])?' ':htmlspecialchars($r["city"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["postal"])?' ':htmlspecialchars($r["postal"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["phone"])?' ':htmlspecialchars($r["phone"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["feet"])?' ':htmlspecialchars($r["feet"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["inch"])?' ':htmlspecialchars($r["inch"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["weight"])?' ':htmlspecialchars($r["weight"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["yyyy"])?' ':htmlspecialchars($r["yyyy"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["mm"])?' ':htmlspecialchars($r["mm"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["dd"])?' ':htmlspecialchars($r["dd"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["teamid"])?' ':htmlspecialchars($r["teamid"]); ?> </div></td> <td> <div align="center"><?php echo empty($r["status"])?' ':htmlspecialchars($r["status"]); ?> </div></td> <td> <div align="center"> <input type="checkbox" name="checkboxapproved[<?php echo $r["ID"]?>]" value="1"<?php echo empty($r["approved"])?'':' checked="checked"'; ?> /> </div></td> </tr> <?php } ?> </table> <p> <input type="checkbox" name="checkall" onclick="checkUncheckAll(this);"/> select/unselect <input type="submit" value="update" name="update"> </p> </form> <table width="178" border="1" cellpadding="0" cellspacing="1"> <tr> <th colspan="2" scope="col">Type</th> </tr> <tr> <td width="113"><div align="center">Church Player</div></td> <td width="50"><div align="center">1</div></td> </tr> <tr> <td><div align="center">Import Player</div></td> <td><div align="center">2</div></td> </tr> <tr> <td><div align="center">Witness Player</div></td> <td><div align="center">3</div></td> </tr> </table> <p> </p> </body> </html> Players Database TABLE `players` ( `ID` int(11) NOT NULL default '0', `first` varchar(255) default NULL, `last` varchar(255) default NULL, `address` varchar(255) default NULL, `city` varchar(255) default NULL, `postal` varchar(255) default NULL, `phone` varchar(255) default NULL, `feet` varchar(255) default NULL, `inch` varchar(255) default NULL, `weight` varchar(255) default NULL, `yyyy` varchar(255) default NULL, `mm` varchar(255) default NULL, `dd` varchar(255) default NULL, `teamid` varchar(255) default NULL, `status` varchar(255) default NULL, `gp` varchar(255) default NULL, `goal` varchar(255) default NULL, `assist` varchar(255) default NULL, `point` varchar(255) default NULL, `yellow` varchar(255) default NULL, `red` varchar(255) default NULL, `susp` varchar(255) default NULL, `approved` int(11) default '0', PRIMARY KEY (`ID`) Link to comment https://forums.phpfreaks.com/topic/189692-update-multiple-records-please-help/ Share on other sites More sharing options...
jl5501 Posted January 25, 2010 Share Posted January 25, 2010 I think there are several issues here. My first question is your if($Submit) in your update script. Is that meant to be testing the value of the submit button from the form? like if($_POST['submit'] = 'Submit') or if(isset($_POST['submit'])) Link to comment https://forums.phpfreaks.com/topic/189692-update-multiple-records-please-help/#findComment-1001172 Share on other sites More sharing options...
netman182 Posted January 26, 2010 Author Share Posted January 26, 2010 i dont know what you mean. I am not testing. i just want to update the fields that will show up when the teamid is selected. if could get some advice that would be great. Link to comment https://forums.phpfreaks.com/topic/189692-update-multiple-records-please-help/#findComment-1001687 Share on other sites More sharing options...
jl5501 Posted January 26, 2010 Share Posted January 26, 2010 By Testing, I mean your i($Submit). That is checking (testing) the value of a variable called $Submit. I dont see anything setting the value of a variable called $Submit. You do have the submit button on the form which when the form is submitted will be available as $_POST['submit'], so that is the reason for my question in my last post Link to comment https://forums.phpfreaks.com/topic/189692-update-multiple-records-please-help/#findComment-1001710 Share on other sites More sharing options...
netman182 Posted January 27, 2010 Author Share Posted January 27, 2010 i have tried both if($_POST['submit'] = 'Submit') or if(isset($_POST['submit'])) to no luck. the link to the test pages i am using is : http://bccsl.org/bccsltest/login/drop2.php that way you can see it in working condition.. would love this to be solved soon. i have pulled enough hair out and would like some advice. Link to comment https://forums.phpfreaks.com/topic/189692-update-multiple-records-please-help/#findComment-1002223 Share on other sites More sharing options...
satya61229 Posted January 27, 2010 Share Posted January 27, 2010 In the page drop.php, you are submitting data to update_multiple.php but there instead of taking submitted data from drop.php you are taking data from update_multiple.php itself. So how does it work! and also you are getting data in while loop after SELECT statement on Page update_multiple.php. that is ok. But how come data will be available in goal[$i] etc in UPDATE statement there. HTML array are not know to PHP without submitting the form. So there are lots of issue as I can see. Or i may have taken it wrongly in hurry! Link to comment https://forums.phpfreaks.com/topic/189692-update-multiple-records-please-help/#findComment-1002280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.