0

at the top in the php code I am getting the data from the DB:

$pricesql="SELECT * FROM my_table";
$pricesqlresult=mysql_query($pricesql);

In the body I am having the following in order to list the results

<?php
while($rows=mysql_fetch_array($pricesqlresult)){
$date[]= $rows['date'];
?>
<p><input name="price[]" type="text" value="<? echo $rows['price']; ?>"></p>
<?php
}
?>

at the bottom of the page I have a php code with following sql:

<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
for($i=0;$i<$count;$i++){
$sql1="UPDATE my_table SET price='".$_POST['price'][$i]."' WHERE date='$date[$i]'";
$result99=mysql_query($sql1);
}
}
mysql_close();
?>

I do not know why the code does not update.

Thanks

Strawberry
  • 33,750
  • 13
  • 40
  • 57
user2615859
  • 37
  • 1
  • 6
  • Are you getting any errors? Can print / echo $sql1 and execute it in MySQL Console? – Anuraj Aug 30 '13 at 06:00
  • What is the value of `$count` ? Did you try to check MySQL errors ? Also, you should give a look at this : http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php before wasting more time using MySQL_ – Clément Malet Aug 30 '13 at 06:00
  • $count=mysql_query($pricesql); – user2615859 Aug 30 '13 at 06:03
  • $result99 is undefined – user2615859 Aug 30 '13 at 06:04
  • Cannot use a scalar value as an array in - i am getting these on the because of $date[]= $rows['date']; – user2615859 Aug 30 '13 at 06:05
  • is the $date getting posted ? do you get any error ? $date is just an array, not any html element, which should get posted – Deepanshu Goyal Aug 30 '13 at 06:06
  • and moreover if it is getting posted, then use $_POST['date'][$i] – Deepanshu Goyal Aug 30 '13 at 06:07
  • the price is not getting posted neither '".$_POST['price'][$i]."' , i do not know why – user2615859 Aug 30 '13 at 06:08
  • wait a sec, how are you calling the last code with the update part ? some submit button or something ? – Deepanshu Goyal Aug 30 '13 at 06:12
  • what ? type = 'image' and also ='submit' ? and you are postin it on same page ? – Deepanshu Goyal Aug 30 '13 at 06:36
  • why is that important? if use normal values in update sql it works ok, when i use above mentioned it does not update – user2615859 Aug 30 '13 at 06:53
  • with print($query) i can see that code is executing the UPDATES but the DB is not updated UPDATE my_table SET price = '3' WHERE date = '2013-09-02'UPDATE my_table SET price = '4' WHERE date = '2013-09-03' and so on – user2615859 Aug 30 '13 at 07:48
  • I did the following, but now when the DB is updated, it does accept letters only accept when a number is on the first place: $size = count($_POST['datum']); $i = 0; while ($i < $size) { $datum= $_POST['datum'][$i]; $perso_id= $_POST['perso_id'][$i]; $schicht= $_POST['schicht'][$i]; if ($schicht != 0) { $query = "UPDATE dienstplan SET schicht = '$schicht' WHERE datum = '$datum' AND perso_id='$perso_id'"; mysql_query($query) or die ("Error in query: $query"); } ++$i; } } – user2615859 Aug 30 '13 at 12:38

0 Answers0