Jump to content

update multiple rows not working


jacko_162

Recommended Posts

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.

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

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());
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.