jacko_162 Posted February 14, 2011 Share Posted February 14, 2011 can anyone see anything wrong here?? it wont update the Ships table.. i should of gone bed hours ago but its bugging me: <?php $sql="SELECT * FROM ships ORDER BY auction='Yes' DESC"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Active?</strong></td> <td align="left"><strong>typeID</strong></td> <td align="left"><strong>Item Name</strong></td> <td align="left"><strong>Base Price</strong></td> <td align="left"><strong>Market Price</strong></td> <td align="center"><strong>Auction</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <?php if ($rows['auction'] != "Yes") { ?> <td align="center"><img src="../images/site/delete.png" /></td> <?php } else { ?> <td align="center"><img src="../images/site/accept.png" /></td> <? } ?> <td align="left"><span class="isk"> <? $typeID[]=$rows[typeID]; ?> <? echo $rows['typeID']; ?></span></td> <td align="left"><span class="eveyellow"><? echo $rows['typeName']; ?></span></td> <td align="left"><span class="normal"><?php echo number_format($rows['basePrice'])?> isk</span></td> <td align="left"><input name="marketPrice[]" type="text" size="10" id="marketPrice" value="<? echo $rows['marketPrice']; ?>"> <span class="credits">(<?php echo number_format($rows['marketPrice']/1000000, 2)?> m)</span></td> <td align="center"><input name="auction[]" type="text" size="6" id="auction" value="<? echo $rows['auction']; ?>"></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 ships SET marketPrice='$marketPrice[$i]', auction='$auction[$i]' WHERE typeID='$typeID[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:ship.php"); } mysql_close(); ?> typeID is my primary key in the table and i only want to update "marketPrice" and "auction" upon submit. its a update multiple rows form by the way. thank you so much for helping me... again.. would be lost without phpfreaks. Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/ Share on other sites More sharing options...
denno020 Posted February 14, 2011 Share Posted February 14, 2011 Shouldn't you be passing the database connection to mysql_query() aswell? But I guess if you're getting the information from the database without it, then you might not need it :S. Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1173901 Share on other sites More sharing options...
jacko_162 Posted February 14, 2011 Author Share Posted February 14, 2011 i am getting the database connection in the header file. which i didnt include in the code above. the query above all pull the data correctly, its just the UPDATE query thats not updating the sql tables. Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1173989 Share on other sites More sharing options...
jacko_162 Posted February 14, 2011 Author Share Posted February 14, 2011 still cant find my problem even after sleep. Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174007 Share on other sites More sharing options...
BlueSkyIS Posted February 14, 2011 Share Posted February 14, 2011 this is probably never true: if($Submit){ I suggest that you update that line to: if ($_SERVER['REQUEST_METHOD'] == "POST") { Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174066 Share on other sites More sharing options...
jacko_162 Posted February 14, 2011 Author Share Posted February 14, 2011 now it did something, it set every value in the db table to blank:-[ Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174095 Share on other sites More sharing options...
jacko_162 Posted February 14, 2011 Author Share Posted February 14, 2011 if i echo $sql1 after it runs i get the following: UPDATE ships SET marketPrice='', auction='' WHERE typeID='592' seems to add nothing to the database which makes the field blank? Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174098 Share on other sites More sharing options...
Jessica Posted February 14, 2011 Share Posted February 14, 2011 That means your variables are empty, which makes sense because I don't see you setting them. NEVER use globals! You need to process your $_POST array from your form. (Or $_GET, but I'd use $_POST for a form) Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174099 Share on other sites More sharing options...
jacko_162 Posted February 14, 2011 Author Share Posted February 14, 2011 ok how do i process the POST array from the form? Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174102 Share on other sites More sharing options...
Jessica Posted February 14, 2011 Share Posted February 14, 2011 ok how do i process the POST array from the form? See below. Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174109 Share on other sites More sharing options...
jacko_162 Posted February 14, 2011 Author Share Posted February 14, 2011 i still cant figure out what you mean here is my newest code with the crap taken out. <?php include "../connect.php"; $sql="SELECT * FROM ships LIMIT 10"; $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"><strong>typeID</strong></td> <td align="center"><strong>Ship Name</strong></td> <td align="center"><strong>Market Price</strong></td> <td align="center"><strong>Auction?</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $typeID[]=$rows['typeID']; ?><? echo $rows['typeID']; ?></td> <td align="center"><? $typeName[]=$rows['typeName']; ?><? echo $rows['typeName']; ?></td> <td align="center"><input name="marketPrice[]" type="text" id="marketPrice" value="<? echo $rows['marketPrice']; ?>"></td> <td align="center"><input name="auction[]" type="text" id="auction" value="<? echo $rows['auction']; ?>"></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($_POST['Submit']){ for($i=0;$i<$count;$i++){ $sql1="UPDATE ships SET marketPrice='$marketPrice[$i]' AND auction='$auction[$i]' WHERE typeID='$typeID[$i]'"; $result1=mysql_query($sql1) or die(mysql_error()); } } if($result1){ echo "sucess<br>"; echo $sql1; //header("location:test.php"); } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174197 Share on other sites More sharing options...
Jessica Posted February 14, 2011 Share Posted February 14, 2011 You never set $marketPrice Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174204 Share on other sites More sharing options...
sasa Posted February 14, 2011 Share Posted February 14, 2011 update code to if($_POST['Submit']){ $marketPrice = $_POST['marketPrice']; $auction = $_POST['auction']; $count = count($auction); for($i=0;$i<$count;$i++){ $sql1="UPDATE ships SET marketPrice='$marketPrice[$i]' AND auction='$auction[$i]' WHERE typeID='$typeID[$i]'"; $result1=mysql_query($sql1) or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174205 Share on other sites More sharing options...
jacko_162 Posted February 14, 2011 Author Share Posted February 14, 2011 update code to if($_POST['Submit']){ $marketPrice = $_POST['marketPrice']; $auction = $_POST['auction']; $count = count($auction); for($i=0;$i<$count;$i++){ $sql1="UPDATE ships SET marketPrice='$marketPrice[$i]' AND auction='$auction[$i]' WHERE typeID='$typeID[$i]'"; $result1=mysql_query($sql1) or die(mysql_error()); } still no luck, here is link to test page; http://www.shiplotto.com/test.php Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174278 Share on other sites More sharing options...
jacko_162 Posted February 14, 2011 Author Share Posted February 14, 2011 ha finally figured it out. $id = $_POST['typeID'] ; $typeName = $_POST['typeName'] ; $marketPrice = $_POST['marketPrice']; $auction = $_POST['auction'] ; if(isset($_POST['Submit'])) { for($i=0;$i<$count;$i++){ $sql1 = "UPDATE `ships` SET `marketPrice`='$marketPrice[$i]', `auction`='$auction[$i]' WHERE `ships`.`typeID`='$id[$i]'"; $result1 = mysql_query($sql1); for whatever reason i changed typeID to assign to $id instead of $typeID and it worked.. strange. Thank you for help and assistance guys and gals Quote Link to comment https://forums.phpfreaks.com/topic/227589-update-multiple-rows-not-working/#findComment-1174287 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.