Parameter Passing

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

Wed May 15, 2013 2:07 pm

I inherited a project that has some code that does not work. I cannot figure out the problem. The problem is that I have a form (list_events.php), which properly displays a table of events from the database. The last column of the table contains an "Edit" link, which displays an edit form (edit_event.php) for the user to edit the selected row.

List_events.php creates the edit link with this code:

Code: Select all

 <td bgcolor="#CCCCCC"><strong>

      <a href="edit_event.php?pid=<?php echo $event['pid']; ?>">Edit</a>

      <a href="delete_event.php?pid=<?php echo $event['pid']; ?>" onClick="confirmdelete('<?php echo $event["pid"]; ?>'); return false;">Delete</a>
When the edit form is displayed the correct value for pid is shown in the browser address bar. The correct row data is also shown in the edit form. My problem is that when the OK button is clicked the record is not updated because the pid value is blank.

The second form contains this code to read the pid parameter.

Code: Select all

// if the script has been called without ID or the user hit "Cancel" just return to listing
  if (empty($pid) || isset($_POST['cancel'])) { 
      Header("Location: list_events.php"); 

// run this only, once the user has hit the "OK" button
  if (isset($_POST['ok'])) {
    // assign form inputs
    $date = mysql_real_escape_string($_POST['date']);
    $dateend = mysql_real_escape_string($_POST['dateend']);
    $location = mysql_real_escape_string($_POST['location']);
    $type = mysql_real_escape_string($_POST['type']);
    $shownews = mysql_real_escape_string($_POST['shownews']);
    $title = mysql_real_escape_string($_POST['title']);
    $comments = mysql_real_escape_string($_POST['comments']);
    $auto_push = mysql_real_escape_string($_POST['auto_push']);
    $status = mysql_real_escape_string($_POST['status']);

    // validate inputs
    if ( !empty($date) && !empty($title) && !empty($location) && !empty($type) ) {    

      // add member to database
      $query = "UPDATE events SET date='".$date."',dateend='".$dateend."',location='".$location."',type='".$type."',title='".$title."',shownews='".$shownews."',comments='".$comments."',auto_push='".$auto_push."',status='".$status."' WHERE pid='".$pid."'";

   //echo $query;
     $result = mysql_query($query);
     Header("Location: list_events.php"); 
    else {
      $error = true; // input validation failed
  else { // read member data from database
    $query = "SELECT * FROM events WHERE pid='".$pid."'";
    $result = mysql_query($query);
    $event = mysql_fetch_assoc ( $result );
    $date = $event['date'];
    $dateend = $event['dateend'];
    $location = $event['location'];
    $type = $event['type'];
    $shownews = $event['shownews'];
    $title = $event['title'];
    $comments = $event['comments'];
    $auto_push = $event['auto_push'];
    $status = $event['status'];
The value of $pid is always blank and the last block of code that updates the database is never executed. Is my problem on the first form or the second?


User avatar
New php-forum User
New php-forum User
Posts: 26
Joined: Sat Oct 15, 2011 3:21 am
Location: Hull, East Yorkshire, England

Wed May 15, 2013 10:39 pm

in your forms are you passing the pid in as a hidden field? might be helpful if you most your forms and the code on the edit page.

Post Reply