PDO statement to UPDATE db not working

Hi,
I am having problems updating a DB using a prepared pdo statement.
I have been looking through this code for two days now and can not see what I am doing wrong.
I would be very grateful if anyone could have a look and would share their thoughts.

Here is an excerpt from the index.php file which populates the form. Note the form is use to update information and to add new information. But the code for adding information is not shown here. It is almost the same. Uses INSERT instead of UPDATE. So if it workis to INSERT, why not UPDATE.

if (isset($_POST['action']) and $_POST['action'] == 'Edit')
{
  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';

  try
  {
    $sql = 'SELECT id, unit, year, exam, question, part, subpart, topic, subtopic, tp, questiontype FROM teachingpts WHERE id = :id';
    $s = $pdo->prepare($sql);
    $s->bindParam(':id', $_POST['id']);
    $s->execute();
  }
  catch (PDOException $e)
  {
    $error = 'Error fetching teachingpoints row details.';
    include 'error.html.php';
    exit();
  }
  $row = $s->fetch();

  $pageTitle = 'Edit teaching points';
  $action = 'editform';
  $id = $row['id'];
  $unit = $row['unit'];
  $year = $row['year'];
  $exam = $row['exam'];
  $question = $row['question'];
  $part = $row['part'];
  $subpart = $row['subpart'];
  $topic = $row['topic'];
  $subtopic = $row['subtopic'];
  $tp = $row['tp'];
  $questiontype = $row['questiontype'];
  $button = 'Update teaching points';

  // Build the list of teaching point rows
  try
  {
    $result = $pdo->query('SELECT id, unit, year, exam, question, part, subpart, topic, subtopic, tp, questiontype FROM teachingpts');
  }
  catch (PDOException $e)
  {
    $error = 'Error fetching list of teaching points.';
    include 'error.html.php';
    exit();
  }

  foreach ($result as $row)
  {
 $teachingpts[] = array('id' => $row['id'], 'unit' => $row['unit'], 'year' => $row['year'], 'exam' => $row['exam'], 'question' => $row['question'], 'part' => $row['part'], 'subpart' => $row['subpart'], 'topic' => $row['topic'], 'subtopic' => $row['subtopic'], 'tp' => $row['tp'], 'questiontype' => $row['questiontype']);
  }

  include 'form.html.php';
  exit();
}

The HTML form is as follows.

<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/helpers.inc.php'; 
    include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/buildtopics.inc.php';
    include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/buildsubtopics.inc.php'; ?>
<!DOCTYPE html>
<html lang="en">
  <head>
      <script>
       var newTopics = <?php echo json_encode($topics, JSON_PRETTY_PRINT) ?>;//converts php arrays to JS object
     var newSubTopics = <?php echo json_encode($subtopics, JSON_PRETTY_PRINT) ?>;
         function populate(s1, s2){
        var s1 = document.getElementById(s1);
        var s2 = document.getElementById(s2);
        var optionArray = [];
        s2.innerHTML = "";
        for (i = 0;  i < newTopics.length; i++) {
            for (j = 0;  j < newSubTopics.length; j++) {
                if(newTopics[i].id == newSubTopics[j].topicid){
                    if(s1.value == newTopics[i].topic){            
                    optionArray.push(newSubTopics[j].subtopic);
                        }
                    }
                }
        } 
        for(var option in optionArray){
                var newOption = document.createElement("option");
                newOption.value = optionArray[option];
                newOption.innerHTML = optionArray[option];
                s2.options.add(newOption);
            }
        }
        </script>
    <meta charset="utf-8">
    <title><?php htmlout($pageTitle); ?></title>
    <style>
    table,th,td{ border-collapse:collapse;}
    th, td{ padding:6px;}
    td { vertical-align:top; text-align: center; width: 40px; overflow: hidden;  white-space: nowrap;}
    th{ background-color:#ccc;}
    </style>
  </head>
    <body background="/artgibney/includes/retro_intro_@2X.png">
  <p><a href="..">physCMS home</a> &#8658; <a href="/artgibney/admin/teachingpoints/">Teaching Points</a></p>
    <h1><?php htmlout($pageTitle); ?></h1>
    <form action="?<?php htmlout($action); ?>" method="post">
      <table>
      <tr>
      <th>Unit</th>
      <th>Year</th>
      <th>Exam</th>
      <th>Question</th>
      <th>Part</th>
      <th>Sub-part</th>
      <th>Question type</th>
      </tr>
      <tr>
            <?php $units = ['1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6']; 
            ?>
      <td>
                <select name="unit" id="unit">
                     <?php foreach($units as $key=>$option):
                           $selected = ($unit == $key) ? 'selected' : '';
                           echo "<option value='$key' $selected>$option</option>";
                      endforeach; ?>
                </select>
      </td>
            <?php $years = ['2009' => '2009', '2010' => '2010', '2011' => '2011', '2012' => '2012', '2013' => '2013', '2014' => '2014', '2015' => '2015']; 
            ?>
      <td>
                <select name="year" id="year">
                     <?php foreach($years as $key=>$option):
                           $selected = ($year == $key) ? 'selected' : '';
                           echo "<option value='$key' $selected>$option</option>";
                           echo($key);
                      endforeach; ?>
                </select>
      </td>
            <?php $exams = ['January' => 'January', 'June' => 'June']; ?>
      <td>
                <select name="exam" id="exam">
                     <?php foreach($exams as $key=>$option):
                           $selected = ($exam == $key) ? 'selected' : '';
                           echo "<option value='$key' $selected>$option</option>";
                      endforeach; ?>
                </select>
      </td>
      <td>
        <input type="number" name="question" min="1" max="25" value="<?php htmlout($question);?>">
      </td>
      <td>
        <input type="text" name="part" value="<?php htmlout($part);?>">
      </td>
      <td>
        <input type="text" name="subpart" value="<?php htmlout($subpart);?>">
      </td>
      <?php 
      $questions = ['Multiple Choice' => 'Multiple Choice', 'Calculation' => 'Calculation', 'Short answer' => 'Short answer', 'Long answer' => 'Long answer'];
      ?>
      <td>
                <select name="questiontype" id="questiontype">
                     <?php foreach($questions as $key=>$option):
                           $selected = ($questiontype == $key) ? 'selected' : '';
                           echo "<option value='$key' $selected>$option</option>";
                      endforeach; ?>
                </select>
      </td>
      </tr>
      </table>
      <table>
      <th>Topic</th>
      <th>Sub-topic</th>
      <th>Teaching point</th>
      <tr>
      <td>
                <select name="topic" id="topic" onchange="populate('topic', 'subtopic')"> 
                 <option value=""></option>
                     <?php foreach($topics as $topical):
                           $value = $topical['topic'];
                           $selected = ($topic == $value) ? 'selected' : '';
                           echo "<option value='$value' $selected>$value</option>";
                      endforeach; ?>
                </select>
      </td>
            <td>
                <select name="subtopic" id="subtopic">
                 <option value=""></option>
                     <?php foreach($subtopics as $subtopical):
                           $value = $subtopical['subtopic'];
                           $selected = ($subtopic == $value) ? 'selected' : '';
                           echo "<option value='$value' $selected>$value</option>";
                      endforeach; ?> 
                </select>
                
      </td>
      <td>
        <textarea id="tp" name="tp" rows="3" cols="40"><?php htmlout($tp); ?></textarea>
      </td> 
      </tr>
      </table>
        <input type="hidden" name="id" value"<?php htmlout($id); ?>">
        <input type="submit" value="<?php htmlout($button); ?>">
    </form>
  </body>
</html>

Everything to here is working fine. The next excerpt from the index.php file should insert the information into the database but there are no changes occurring in the database.

if (isset($_GET['editform']))
{
  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';
  try
  {
    $sql = 'UPDATE teachingpts SET
        unit = :unit,
        year = :year,
        exam = :exam,
        question = :question,
        part = :part,
        subpart = :subpart,
        topic = :topic,
        subtopic = :subtopic,
        tp = :tp,
        questiontype = :questiontype
        WHERE id = :id';
    $s = $pdo->prepare($sql);
    $s->bindValue(':id', $_POST['id']);
    $s->bindValue(':unit', $_POST['unit']);
    $s->bindValue(':year', $_POST['year']);
    $s->bindValue(':exam', $_POST['exam']);
    $s->bindValue(':question', $_POST['question']);
    $s->bindValue(':part', $_POST['part']);
    $s->bindValue(':subpart', $_POST['subpart']);
    $s->bindValue(':topic', $_POST['topic']);
    $s->bindValue(':subtopic', $_POST['subtopic']);
    $s->bindValue(':tp', $_POST['tp']);
    $s->bindValue(':questiontype', $_POST['questiontype']);
    $s->execute();
  }
  catch (PDOException $e)
  {
    $error = 'Error updating submitted teaching points';
    include 'error.html.php';
    echo $e;
    exit();
  }

  header('Location: .');
  exit();
}

Thanks,
Shane

Could this be the problem:

if (isset($_GET['editform']))

I think that $_GET should be $_POST by the looks of your form.

Edit: Also I don’t see you called your form “editform”? - My mistake you did.

Hi,
Thanks for looking at this. I changed the $_GET to $_POST but this did not change to the results. I didn’t think this was the problem because, $_GET is used in the following code which successfully adds data from the form to the database.

if (isset($_GET['add']))
{
  $pageTitle = 'New Teaching Points';
  $action = 'addform';
  $unit = '';
  $year = '';
  $exam = '';
  $question = '';
  $part = '';
  $subpart = '';
  $topic = '';
  $subtopic = '';
  $tp = '';
  $questiontype = '';
  $id = '';
  $button = 'Add teaching points';

  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';
  try
  {
    $result = $pdo->query('SELECT id, unit, year, exam, question, part, subpart, topic, subtopic, tp, questiontype FROM teachingpts');
  }
  catch (PDOException $e)
  {
    $error = 'Error fetching data from teachingpoints table.';
    include 'error.html.php';
    exit();
  }
  include 'form.html.php';
  exit();
}

if (isset($_GET['addform']))
{
  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';

  try
  {
    $sql = 'INSERT INTO teachingpts SET
        id = :id,
        unit = :unit,
        year = :year,
        exam = :exam,
        question = :question,
        part = :part,
        subpart = :subpart,
        topic = :topic,
        subtopic = :subtopic,
        tp = :tp,
        questiontype = :questiontype';
    $s = $pdo->prepare($sql);
    $s->bindParam(':id', $_POST['id']);
    $s->bindParam(':unit', $_POST['unit']);
    $s->bindParam(':year', $_POST['year']);
    $s->bindParam(':exam', $_POST['exam']);
    $s->bindParam(':question', $_POST['question']);
    $s->bindParam(':part', $_POST['part']);
    $s->bindParam(':subpart', $_POST['subpart']);
    $s->bindParam(':topic', $_POST['topic']);
    $s->bindParam(':subtopic', $_POST['subtopic']);
    $s->bindParam(':tp', $_POST['tp']);
    $s->bindParam(':questiontype', $_POST['questiontype']);
    $s->execute();    
  }
  catch (PDOExceptin $e)
  {
    $error = 'Error adding submitted teachpoints table data.';
    include 'error.html.php';
    exit();
  }

    include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';

  try
  {
    $result = $pdo->query('SELECT id, unit, year, exam, question, part, subpart, topic, subtopic, tp, questiontype FROM teachingpts');
  }
  catch (PDOException $e)
  {
    $error = 'Error fetching data from teachingpoints table.';
    include 'error.html.php';
    exit();
  }

  foreach ($result as $row)
  {
 $teachingpts[] = array('id' => $row['id'], 'unit' => $row['unit'], 'year' => $row['year'], 'exam' => $row['exam'], 'question' => $row['question'], 'part' => $row['part'], 'subpart' => $row['subpart'], 'topic' => $row['topic'], 'subtopic' => $row['subtopic'], 'tp' => $row['tp'], 'questiontype' => $row['questiontype']);
  }

  header('Location: .');
  exit();
}

This does use bindParam instead of bindValue. I have tried both and there is no change to the results.
There is some small little thing wrong and I just can’t see it. :confused:
Thanks,
Shane

Check to see if the form is actually passing values to the PHP maybe by echoing them or var_dump

There is a binded variables mismatch between your first SELECT and the UPDATE because you are using $sql for both query statements. Make these unique on the page, e.g. $sqlu for update etc.

If error reporting was on you would probably see

‘Invalid parameter number: number of bound variables does not match number of tokens.’

Hi,
Do you mean that there is a mismatch between the SELECT and the UPDATE here? The SELECT on the 6th line and the UPDATE line marked with **********************

 if (isset($_POST['action']) and $_POST['action'] == 'Edit')
                    {
                      include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';
                      try
                      {
                        $sql = 'SELECT id, unit, year, exam, question, part, subpart, topic, subtopic, tp, questiontype FROM teachingpts WHERE id
                = :id';
                        $s = $pdo->prepare($sql);
                        $s->bindParam(':id', $_POST['id']);
                        $s->execute();
                      }
                      catch (PDOException $e)
                      {
                        $error = 'Error fetching teachingpoints row details.';
                        include 'error.html.php';
                        exit();
                      }
                      $row = $s->fetch();
                
                  $pageTitle = 'Edit teaching points';
                  $action = 'editform';
                  $id = $row['id'];
                  $unit = $row['unit'];
                  $year = $row['year'];
                  $exam = $row['exam'];
                  $question = $row['question'];
                  $part = $row['part'];
                  $subpart = $row['subpart'];
                  $topic = $row['topic'];
                  $subtopic = $row['subtopic'];
                  $tp = $row['tp'];
                  $questiontype = $row['questiontype'];
                  $button = 'Update teaching points';
                /*
                  // Build the list of teaching point rows
                  try
                  {
                    $result = $pdo->query('SELECT id, unit, year, exam, question, part, subpart, topic, subtopic, tp, questiontype FROM
            teachingpts');
                  }
                  catch (PDOException $e)
                  {
                    $error = 'Error fetching list of teaching points.';
                    include 'error.html.php';
                    exit();
                  }
                
                  foreach ($result as $row)
                  {
                 $teachingpts[] = array('id' => $row['id'], 'unit' => $row['unit'], 'year' => $row['year'], 'exam' => $row['exam'],
            'question' => $row['question'], 'part' => $row['part'], 'subpart' =>
            $row['subpart'], 'topic' => $row['topic'], 'subtopic' =>
            $row['subtopic'], 'tp' => $row['tp'], 'questiontype' =>
            $row['questiontype']);
                  }*/
                
                  include 'form.html.php';
                  exit();
                }
                
                if (isset($_GET['editform']))
                {
                  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';
                
                  try
                  {
                    $sql = 'UPDATE teachingpts SET ***********This UPDATE ******************
                        unit = :unit,
                        year = :year,
                        exam = :exam,
                        question = :question,
                        part = :part,
                        subpart = :subpart,
                        topic = :topic,
                        subtopic = :subtopic,
                        tp = :tp,
                        questiontype = :questiontype
                        WHERE id = :id';
                    $s = $pdo->prepare($sql);
                    $s->bindValue(':id', $_POST['id']);
                    $s->bindValue(':unit', $_POST['unit']);
                    $s->bindValue(':year', $_POST['year']);
                    $s->bindValue(':exam', $_POST['exam']);
                    $s->bindValue(':question', $_POST['question']);
                    $s->bindValue(':part', $_POST['part']);
                    $s->bindValue(':subpart', $_POST['subpart']);
                    $s->bindValue(':topic', $_POST['topic']);
                    $s->bindValue(':subtopic', $_POST['subtopic']);
                    $s->bindValue(':tp', $_POST['tp']);
                    $s->bindValue(':questiontype', $_POST['questiontype']);
                    $s->execute();
                  }
                  catch (PDOException $e)
                  {
                    $error = 'Error updating submitted teaching points';
                    include 'error.html.php';
                    echo $e;
                    exit();
                  }
                  header('Location: .');
                  exit();
                }

I see 11 items in each: id, unit, year, exam, question, part, subpart, topic, subtopic, tp and questiontype.

I am now using $sqlu instead, but still no change.

if (isset($_GET['editform']))
{
  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';

  try
  {
    $sqlu = 'UPDATE teachingpts SET
        unit = :unit,
        year = :year,
        exam = :exam,
        question = :question,
        part = :part,
        subpart = :subpart,
        topic = :topic,
        subtopic = :subtopic,
        tp = :tp,
        questiontype = :questiontype
        WHERE id = :id';
    $s = $pdo->prepare($sqlu);
    $s->bindValue(':id', $_POST['id']);
    $s->bindValue(':unit', $_POST['unit']);
    $s->bindValue(':year', $_POST['year']);
    $s->bindValue(':exam', $_POST['exam']);
    $s->bindValue(':question', $_POST['question']);
    $s->bindValue(':part', $_POST['part']);
    $s->bindValue(':subpart', $_POST['subpart']);
    $s->bindValue(':topic', $_POST['topic']);
    $s->bindValue(':subtopic', $_POST['subtopic']);
    $s->bindValue(':tp', $_POST['tp']);
    $s->bindValue(':questiontype', $_POST['questiontype']);
    $s->execute();
  }
  catch (PDOException $e)
  {
    $error = 'Error updating submitted teaching points';
    include 'error.html.php';
    echo $e;
    exit();
  }
  header('Location: .');
  exit();
}

Also the error_log is empty.
Thanks,
Shane

I would change the $s as well to $su and use bindParam.

$sqlu = 'UPDATE teachingpts SET
        unit = :unit,
        year = :year,
        exam = :exam,
        question = :question,
        part = :part,
        subpart = :subpart,
        topic = :topic,
        subtopic = :subtopic,
        tp = :tp,
        questiontype = :questiontype
        WHERE id = :id';
    $su = $pdo->prepare($sqlu);
    $su->bindParam(':id', $_POST['id']);
    $su->bindParam(':unit', $_POST['unit']);
    $su->bindParam(':year', $_POST['year']);
    $su->bindParam(':exam', $_POST['exam']);
    $su->bindParam(':question', $_POST['question']);
    $su->bindParam(':part', $_POST['part']);
    $su->bindParam(':subpart', $_POST['subpart']);
    $su->bindParam(':topic', $_POST['topic']);
    $su->bindParam(':subtopic', $_POST['subtopic']);
    $su->bindParam(':tp', $_POST['tp']);
    $su->bindParam(':questiontype', $_POST['questiontype']);
    $su->execute()

Hi,
I made that change but this the same result.

if (isset($_GET['editform']))
{
  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';
  try
  {
    $sqlu = 'UPDATE teachingpts SET
        unit = :unit,
        year = :year,
        exam = :exam,
        question = :question,
        part = :part,
        subpart = :subpart,
        topic = :topic,
        subtopic = :subtopic,
        tp = :tp,
        questiontype = :questiontype
        WHERE id = :id';
    $su = $pdo->prepare($sqlu);
    $su->bindParam(':id', $_POST['id']);
    $su->bindParam(':unit', $_POST['unit']);
    $su->bindParam(':year', $_POST['year']);
    $su->bindParam(':exam', $_POST['exam']);
    $su->bindParam(':question', $_POST['question']);
    $su->bindParam(':part', $_POST['part']);
    $su->bindParam(':subpart', $_POST['subpart']);
    $su->bindParam(':topic', $_POST['topic']);
    $su->bindParam(':subtopic', $_POST['subtopic']);
    $su->bindParam(':tp', $_POST['tp']);
    $su->bindParam(':questiontype', $_POST['questiontype']);
    $su->execute();
  }

In another section of the site I am using the same code successfully but with less parameters. Why is it working there and not here.
Here is that code.
form.html.php

<?php include_once $_SERVER['DOCUMENT_ROOT'] .
    '/artgibney/includes/helpers.inc.php'; ?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title><?php htmlout($pageTitle); ?></title>
    <style type="text/css">
    textarea {
      display: block;
      width: 100%;
    }
    </style>
  </head>
  <body background="/artgibney/includes/retro_intro_@2X.png">
        <p><a href="..">physCMS home</a> &#8658; <a href=".">Manage Daily Notes</a></p> 
      <?php include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/logout.inc.html.php'; ?>
    <h1><?php htmlout($pageTitle); ?></h1>
    <form action="?<?php htmlout($action); ?>" method="post">
      <div>
        <label for="<?php htmlout($formid); ?>">Course:</label>
        <textarea id="<?php htmlout($formid); ?>" name="<?php htmlout($formid); ?>" rows="1" cols="40"><?php
            htmlout($name); ?></textarea>
      </div>
        <input type="hidden" name="id" value="<?php
            htmlout($id); ?>">
        <input type="submit" value="<?php htmlout($button); ?>">
      </div>
    </form>
  </body>
</html>

notes.index.php

if (isset($_POST['action']) and $_POST['action'] == 'Edit')
{
  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';

  try
  {
    $sql = 'SELECT id, course FROM courses WHERE id = :id';
    $s = $pdo->prepare($sql);
    $s->bindValue(':id', $_POST['id']);
    $s->execute();
  }
  catch (PDOException $e)
  {
    $error = 'Error fetching course row details.';
    include 'error.html.php';
    exit();
  }
  $row = $s->fetch();

  $pageTitle = 'Edit a row of the course table';
  $action = 'editform';
  $name = $row['course'];
  $id = $row['id'];
  $formid = 'course';
  $button = 'Update course';
 
  include 'form.html.php';
  exit();
}

if (isset($_GET['editform']))
{
  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';
  
  try
  {
    $sql = 'UPDATE courses SET
        course = :course
        WHERE id = :id';
    $s = $pdo->prepare($sql);
    $s->bindValue(':id', $_POST['id']);
    $s->bindValue(':course', $_POST['course']);
    $s->execute();
  }
  catch (PDOException $e)
  {
    $error = 'Error updating submitted course.';
    include 'error.html.php';
    exit();
  }
  
  header('Location: managecourses.html.php');
  exit();
}

I have printed out and compared the two codes and can’t see any difference. Also this latter code uses $sql and $s in both the SELECT and the UPDATE and it uses bindValue.

Also I am not sure where to put,

echo '<pre>';
    print_r($_POST);
    echo  '</pre>';

to see what is being passes in $_POST

Thanks,
Shane

Hi,
Looking at $_POST I see that the id is empty.
The array looks like this,

Array
(
[unit] => 1
[year] => 2009
[exam] => January
[question] => 12
[part] => c
[subpart] => iii
[questiontype] => Multiple Choice
[topic] => Knitting
[subtopic] => Scarves
[tp] => khing
[id] =>
)

So this is interesting. But why ‘id’ is empty i can’t see. The if(…‘Edit’) should be sorting this out. And the code there seems correct. Where,

$id = $row[‘id’];

I know this works because if it didn’t the form would not have the correct information in it. So I think that after the form.html.php has been populated for editing, when submitted the id is not being sent.

The form should send the ‘id’ with

......       </tr>
      </table>
        <input type="hidden" name="id" value"<?php htmlout($id); ?>">
        <input type="submit" value="<?php htmlout($button); ?>">
    </form>
  </body>
</html>

Shane

Hi,

I am able to output the ‘id’ in the form with,

        <textarea id="tp" name="tp" rows="3" cols="40"><?php htmlout($tp); ?></textarea>
      </td> 
      </tr>
      </table>
      <?php htmlout($id); ?>
        <input type="hidden" name="id" value"<?php htmlout($id); ?>">
        <input type="submit" value="<?php htmlout($button); ?>">
    </form>
  </body>
</html>

and you can see the 38 beside the submit button.

Then echoing $_POST

if (isset($_GET['editform']))
{
        echo '<pre>';
        print_r($_POST);
        echo  '</pre>';
  include $_SERVER['DOCUMENT_ROOT'] . '/artgibney/includes/db.inc.php';
  try
  {
    $sqlu = 'UPDATE teachingpts SET
        unit = :unit,

and there is no ‘id’

Array
(
[unit] => 5
[year] => 2012
[exam] => January
[question] => 2
[part] => b
[subpart] => ii
[questiontype] => Calculation
[topic] => Mechanics
[subtopic] => Forces
[tp] => 5 12 jan 2 b ii cal mech for
[id] =>
)

Why does it go missing after I submit the form? All the others are being sent in $_POST but not ‘id’.

And 38 is the id of that row in the database.


Thanks,
Shane

I just noticed that you’re missing the equal sign on the value attribute of your form and I came here to post and see you have found it as well.

1 Like

Ahhh! Thanks, I can’t believe it.
You’re the best.
Seriously thanks for that.
Works fine now.
Shane

Yes I copied your code to my editor and sat there looking at it for must have been 45 mins and wasn’t seeing any problem. I started focusing on the form, comparing names. I ended up forcing those echoed form values and added print_r($_POST); then noticed the missing id and equal sign.

I apologize for jumping the gun regarding Invalid parameter number. I didn’t look close enough to see that the queries in question were in separate GET calls. That would be a problem though if both were called.

1 Like

Not at all, I am delighted you took the time to look at all. I am also very grateful that you spent so much time on this.
Although I did manage to identify where the problem was, I still couldn’t see it and you beat me to it.
Very much appreciated,
Thanks for your help,
Shane
PS If you find yourself in Dublin Ireland, I owe you a pint! (And many others on this forum.)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.