php - trying to send primary key value for editing data when button is pressed -


im trying send primary key value corresponds button has been pressed in table of results mysql server. each result has own edit , delete buttons. can create button , link corresponding php page struggle sending value of specific tuple has been clicked. code looks like

 try {         $stmt->execute();         $results = $stmt->fetchall();         if (!$results) { // check have results             echo "no trainingcourses found <br />";         } else { //generate table of trainingcourses             print "<table>\n";             echo "<th>meeting id</th><th>title</th><th>date</th><th>link</th>\n";             foreach ($results $row) {                 echo "<tr>";                 echo "<td>" . $row["trainingid"] . "</td>";                 echo "<td>" . $row["title"] . "</td>";                 echo "<td>" . $row["date"] . "</td>";                 echo "<td>" . $row["link"] . "</td>";                 echo "<td><a href='edittrainingcourse.php?id=".$row['trainingid']."'><strong>edit</strong></a></td>";                 echo "<td><a href='deletetrainingcourse.php?id=".$row['trainingid']."'><strong>delete</strong></a></td>";                  echo "</tr>\n";             }             print "</table>\n";         }     } catch (pdoexception $e) {         echo "query failed: " . $e->getmessage();     }      }   catch (pdoexception $e) {     //$conn->rollback();     // if raised exception in our transaction block of statements,     // roll work performed in transaction     exit('<p>unable complete transaction!</p>'.$e->getmessage());      } 

i think answer lies the

id=".$row['trainingid'] 

section im not sure how handle that.

thanks , help!

you have create edittrainingcourse.php , deletetrainingcourse.php.

in each of those, need check existence of $_get['id'] represents ?id=xxx found in url.

verify id passed indeed integer, use it:

if ( is_int($_get['id']) ) {     $trainingid = $_get['id']); } else {     die('bad id given.'); } 

now perform queries using $trainingid.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -