Can anyone help me on this one? I am trying to write an update query that updates many rows from a form element array.

for($i = 0; $i <= $GET[numrows] ; $i++)
{
$sql = " UPDATE [LOW_PRIORITY] pupil_details SET $
GET[dept_data_col]='$POST[textbox][$i]' WHERE Adm_No='$POST[id][$i]' ";

$result = @($sql ,connection)
or die("Couldn't execute query.");
}

I have tested all the $POST and $GET variables to make sure they have been passed properly to this script. They can all be printed, but do not seem to work in the query.

// $sql = " UPDATE pupil_details SET Maths_YR8_NCL='6' WHERE Adm_No='4230' ";

The above query is 1 example of what I am trying to achieve. I have also tried quotes in a million different ways but to no avail.

Thanks in advance.

Ryan

    Ryan,

    Have had a similar sort of problem. Broke the query up so that the bits inside the [] were double quoted. In your case, try :

      Oops, bit too vigorous with my enter pressing.

      1. You don't need the [low priority] in you update.
      2. Split the sql statement so that all the [] entries are double quoted (fixed the problem for me).

      Example .

      $sql = "update pupil_details set ";
      $sql .= $GET["dept_data_col"] . " ='" . $POST["textbox"][$i] . "' ";
      $sql .= "where adm_no = '" . $_POST["id"][$i] . "' ;";

      HTH
      Justin

        Thank-you very much indeed. I would have never worked out this solution myself. You really have saved my day!!!

        Not wanting to be to cheeky, but could you possible answer a couple more q's regarding this snippet.

        What exactly do the full stops in '" . $_POST["id"][$i] . "' do ?

        I know .= contatenates the string, but I never really have got to grips with the full stops do inside the quotes.

        And am I write in saying that the $_GET variable in the snippet did not need double quoting because it was not an array ?

        Thanks again for you promt and much needed response.

        Ryan

          Full stops concatenate two strings. As $a += $b is really shorthand for $a = $a + $b where $a and $b are numeric, $a .= $b is equivalent to $a = $a . $b, where $a and $b are strings. If you try to concatenate strings with the + operator (as you might in JavaScript or other languages) you will get an error in PHP.

          Alternately, you could solve this problem using curly braces to eliminate ambiguity:

          $sql = "UPDATE [LOW_PRIORITY] pupil_details SET {$GET[dept_data_col]}='{$POST[textbox][$i]}' WHERE Adm_No='{$_POST[id][$i]}' ";

            Write a Reply...