newtomysql Posted October 30, 2009 Share Posted October 30, 2009 Hi, I am trying to update multiple records in one of my tables and I can't find the problem why is not updating the table. Can someone take a look at my code and see what I am doing wrong. Thank you. Page Reference: http://www.phpeasystep.com/mysql/10.html My Page: <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="tbl"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM tbl"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <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"> </td> <td align="center"><div align="left"><strong>Type</strong></div></td> <td align="center"><div align="center"><strong>Order Type</strong></div></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $boardTypeID[]=$rows['boardTypeID']; ?></td> <td align="center"><div align="left"><? echo $rows['type']; ?> </div> <div align="left"></div></td> <td align="center"><input name="orderType[]" type="text" id="orderType" value="<? echo $rows['orderType']; ?>" size="2"></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 tbl SET orderType='$orderType[$i]' WHERE boardTypeID='$boardTypeID[$i]'"; $result=mysql_query($sql1); } } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/179632-multiple-records-update-problem/ Share on other sites More sharing options...
Bricktop Posted October 30, 2009 Share Posted October 30, 2009 Hi newtomysql, The problem is with the following line: if($Submit){ It's basically saying if $Submit is set, perform the code below, but nowhere is the $Submit variable defined. Even if it was, checking for a $_POST request using this method isn't as effective as using the $_SERVER as some browsers don't process it properly. Change it to read: if($_SERVER['REQUEST_METHOD']=='POST'){ Hope this helps. Link to comment https://forums.phpfreaks.com/topic/179632-multiple-records-update-problem/#findComment-947841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.