Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Below is the code where I am trying to change the values of one column in multiple rows but I am a little bit stuck.

File 1:

<form name="update-location" method="post" action="recibos_location_update.php">

<div align="right"><button type="submit">Actualizar Estado</button></div>
<hr />

<ul>
    <?php
        $get_logs = mysql_query("SELECT * FROM recibos ORDER BY id DESC");
        while ($logs = mysql_fetch_array($get_logs)){

        $serial = $logs['serial'];
        $check = $logs['location'];
        $problem = $logs['problem'];
    ?>

    <li class="<?php 
        if ($check == $location1){echo 'recibos-container-shop-li';}
        if ($check == $location2){echo 'recibos-container-haji-li';}
        if ($check == $location3){echo 'recibos-container-return-li';} ?>">

        <?php echo $serial . " | " . $logs['model'] . " | " . $problem; ?>

        <div align="right">
            <?php
                if ($check != 'Returned'){
            ?>
                <input type="hidden"  name="serial[]" value="<?php echo $serial; ?>" />
                <select name="location">
                    <option <?php if ($check == $location1){echo 'selected';} ?> value="<?php echo $location1; ?>" style="background: #fff8bf;">Mobils Calfont</option>
                    <option <?php if ($check == $location2){echo 'selected';} ?> value="<?php echo $location2; ?>" style="background: #ffc1bf;">Haji Jorda</option>
                    <option <?php if ($check == $location3){echo 'selected';} ?> value="<?php echo $location3; ?>"style="background: #ecffbf;">Devuelto</option>
                </select>
            <?php
            }
            else {
                echo "<i><font color='#5e8029'>Devuelto</font></i>";
            }
            ?>
        </div>
    </li>
    <?php } ?>
</ul>

File 2

<?php
include "connect.php";
include "links.php";


foreach($_POST["serial"] as $serial){

    $location = $_POST['location'];
    echo $location . " " . $serial . "<br>";
}
mysql_query("UPDATE recibos SET location='$location' WHERE serial='$serial'");

//header("Location: " . $_SERVER['HTTP_REFERER']);

?>

and the output I am getting is:

Haji 900005
Haji 900004
Haji 900002

But for all 3 output lines, it should give different names as names in 3 select boxes were different.

What I need is for the process form to update every row with what value is contained in select box options.

share|improve this question
1  
Usually when one's trying to change something, their code will have an UPDATE statement. I do not see one here. –  tadman Apr 11 '13 at 3:16
    
oops, i just saw my statement above about updating the rows, well i update my question.. thanks for the point out. well, right now i am only printing the taken values as is to see if the code is working fine or not... so if it is not printing the names correctly, it will not write the names correctly in colums in database rows. –  digitiZer Apr 11 '13 at 3:21
1  
@digitiZer: same goes to you. a serious fundamental security flaw in your code has been pointed out, and your response has been to stick your fingers in your ears and go "la la la la". –  Marc B Apr 11 '13 at 3:45
1  
well thanks because i am aware of that and i am not having this as some banking page. This is just a practice code i am doing offline on xampp.. now... i havent put this code for you guys to point out irrelevant flaws in this case. and i am not going "la la la" ... i did read that MOM STUDENT brilliant conversation Mr. tadman just highly suggested..... ..lolz.... "la la la".... are you serious? –  digitiZer Apr 11 '13 at 3:50
1  
and what made me like.... "what the...." he red carded me like he had paid me to write him some code or something... :/ guys please –  digitiZer Apr 11 '13 at 3:53
show 3 more comments

2 Answers

up vote 0 down vote accepted

html

<select name="location[]">

php

foreach($_POST["serial"] as $k=> $serial){

    $location = $_POST['location'][$k];
    mysql_query("UPDATE recibos SET location='$location' WHERE serial='$serial'");
}
share|improve this answer
    
thanks great sir. you really saved the day. worked like a charm :D. Also wanted to request a little favor if you could post some link to understand this coding as i wanted to understand these expressions in future if i want to do something same :) –  digitiZer Apr 11 '13 at 7:18
add comment
foreach($_POST["serial"] as $serial){

    $location = $_POST['location'];
    echo $location . " " . $serial . "<br>";
    mysql_query("UPDATE recibos SET location='$location' WHERE serial='$serial'");//update
}
//    mysql_query("UPDATE recibos SET location='$location' WHERE serial='$serial'");
share|improve this answer
    
thanks for reply, but it is working with outputing the location with lowest serial number and put the same location in all columns of rows. Same as was working with my code above. –  digitiZer Apr 11 '13 at 6:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.