Jump to content

newtomysql

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

newtomysql's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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(); ?>
×
×
  • 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.