Jump to content

Recommended Posts

Hello there,

 

i'm new to php / mysql and try to make a simple address book with some code i found in a similar but more complex addressbook. I've got a database with a table (id, firstname, lastname, email, phone) and i can enter new data and display the table (with the id as a hidden field) on a page called "allentries". This page echos the complete table and allows to edit, view or delete entries. This is where the problem starts; the links delete, edit and view don't seem to pass the id to the next page and therefore the edit/view/delete function fails.

I've postet the code here:

http://pastebin.co.uk/10183

http://pastebin.co.uk/10184

 

Please help!

 

Thanks alot

Link to comment
https://forums.phpfreaks.com/topic/37853-table-id-doesnt-arrive/
Share on other sites

Sorry, i just found out how to post the code here...

 

This is the "allentries" page

   1.
      <title>All entries</title><table width="100%"  border="1">
   2.
        <tr>
   3.
          <td><div align="center">
   4.
            <h1>Address book </h1>
   5.
          </div></td>
   6.
        </tr>
   7.
        <tr>
   8.
          <td><div align="center">
   9.
            <h3>All entries </h3>
  10.
          </div></td>
  11.
        </tr>
  12.
        <tr>
  13.
          <td><div align="center">
  14.
         
  15.
          <?php include("include/nav.inc"); ?>
  16.
         
  17.
          </div></td>
  18.
        </tr>
  19.
      </table>
  20.
      <table width="100%"  border="0">
  21.
        <tr>
  22.
          <td> </td>
  23.
        </tr>
  24.
      </table>
  25.
      <table width="100%"  border="0">
  26.
        <tr>
  27.
          <td><div align="center">
  28.
         
  29.
      <?php
  30.
       
  31.
      include("include/dbconnect.php");
  32.
       
  33.
      $result = mysql_query("SELECT * FROM $table ORDER BY lastname",$db);
  34.
      echo "<table cellpadding=2 cellspacing=1 border=0>";
  35.
       
  36.
      $alternate = "2";
  37.
      while ($row = mysql_fetch_array($result)) {
  38.
      $id = $row["id"];
  39.
      $firstname = $row["firstname"];
  40.
      $lastname = $row["lastname"];
  41.
       
  42.
      if ($alternate == "1") {
  43.
      $color = "#ffffff";
  44.
      $alternate = "2";
  45.
      }
  46.
      else {
  47.
      $color = "#efefef";
  48.
      $alternate = "1";
  49.
      }
  50.
      echo "<tr bgcolor=$color>
  51.
      <td><input type=\"hidden\" name=\"recid\" value=\"$id\"></td>
  52.
      <td>$lastname, $firstname</td>
  53.
      <td> --- </td>
  54.
      <td><a href='view.php?id=$id'>see details</a></td>
  55.
      <td> - </td><td><a href='edit.php?id=$id'>edit record</a></td>
  56.
      <td> - </td><td><a href='delete.php?id=$id' onClick=\"return confirm('Are you sure?')\">delete record</a></td>
  57.
      </tr>";
  58.
      }
  59.
      echo "</table>";
  60.
       
  61.
      ?>
  62.
       
  63.
      </div></td>
  64.
        </tr>
  65.
      </table>
  66.
      <form name="form1" method="post" action="">
  67.
        <input type="hidden" name="hiddenField">
  68.
      </form>
  69.
      <p> </p>
  70.
       

 

 

 

 

 

And here's the "delete" page. The same problem occurs when you click the link to the "edit" and the "view" link

   1.
      <?php
   2.
      session_start();
   3.
      ?>
   4.
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   5.
      <html xmlns="http://www.w3.org/1999/xhtml">
   6.
      <head>
   7.
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   8.
      <title>Delete existing entries</title>
   9.
      </head>
  10.
       
  11.
      <body>
  12.
      <table width="100%"  border="1">
  13.
        <tr>
  14.
          <td><div align="center">
  15.
            <h1>Address book </h1>
  16.
          </div></td>
  17.
        </tr>
  18.
        <tr>
  19.
          <td><div align="center">
  20.
            <h3>Delete</h3>
  21.
          </div></td>
  22.
        </tr>
  23.
        <tr>
  24.
          <td><div align="center">
  25.
         
  26.
          <?php include("include/nav.inc"); ?>
  27.
         
  28.
          </div></td>
  29.
        </tr>
  30.
      </table>
  31.
      <table width="100%" border="1">
  32.
        <tr>
  33.
          <td>
  34.
      <?php
  35.
      include("include/dbconnect.php");
  36.
       
  37.
      $id = $row["id"];
  38.
      echo ':'.$id.':';
  39.
      mysql_query("DELETE FROM $table WHERE id=$id",$db);
  40.
       
  41.
      echo "Record deleted<br><br>";
  42.
      ?>
  43.
       
  44.
          </td>
  45.
        </tr>
  46.
      </table>
  47.
      <p> </p>
  48.
      </body>
  49.
      </html>
  50.
       

 

Thanks again

 

tech7

When you click the edit or delete link, is the ID in the string (URL)?

 

If it is, it doesn't appear you defined your script to use it.

 

Instead of $row, you would want to grab it from the URL, $id = $GET["id"];, unless you re-select it.

 

 

    <?php
  35.
      include("include/dbconnect.php");
  36.
       
  37.
      $id = $GET["id"];
  38.
      echo ':'.$id.':';
  39.
      mysql_query("DELETE FROM $table WHERE id=$id",$db);
  40.
       
  41.
      echo "Record deleted<br><br>";
  42.
      ?>

after adding

 

ini_set('display_errors', 1);

error_reporting(E_ALL);

 

i found out that the variable $id doesn't seem to be defined. where can i define it?

i've tried $id = $row["id"]; without success. perhaps i've tried the wrong place to define $id?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.