All pastes #243546 Raw Edit

Stuff

public text v1 · immutable
·published 2006-11-08 16:58 UTC
rendered paste body
   1.
      got problem with php/mysql. The think is i alredy retype 4 times, dont know wahat to do.So i let ya'll know my work:
   2.
       
   3.
       
   4.
      Mysql table: (the table name is, jokes)
   5.
        id  ;   text  ;  other
   6.
      -------------------------
   7.
        1   ;   blah  ;  bluh
   8.
        2   ;  blah   ; bluh
   9.
       
  10.
      Here is the complete script for this table
  11.
      ----------------------------------------------------------------------------------------
  12.
      <?php
  13.
      $dbcnx=@mysql_connect('localhost', 'root', '');
  14.
      if (!@dbcnx) {
  15.
         echo( '<p>Unable co connect to the database server at this time.</p>' );
  16.
         exit();
  17.
         }
  18.
      mysql_select_db('jokes', $dbcnx);
  19.
      if (! @mysql_select_db('jokes') ) {
  20.
         
  21.
      die ( '<p>Unable to locate the joke' .
  22.
          ' database at this time.</p>');
  23.
         }
  24.
       
  25.
      $sql = 'create table Jokes (
  26.
         id int not null auto_increment primary key,
  27.
         JokeText text,
  28.
         JokeOther text,
  29.
         JokeDate date not null)';
  30.
      if (@mysql_query($sql)) {
  31.
         echo('<p>Jokes table successfuly created!</P>' );
  32.
         }
  33.
         else {
  34.
            die('<p>Error creating Jokes table:' .
  35.
            mysql_error() . '</p>');
  36.
            }
  37.
      ?>
  38.
      -------------------------------------------------------------------------------------------
  39.
       
  40.
      Add heres the joke list scrip (i think no problemo for this scrip)
  41.
       
  42.
      ------------------
  43.
      <?php
  44.
      $dbcnx=@mysql_connect('localhost', 'root', '');
  45.
      if (!@dbcnx) {
  46.
         echo( '<p>Unable co connect to the database server at this time.</p>' );
  47.
         exit();
  48.
         }
  49.
      mysql_select_db('jokes', $dbcnx);
  50.
      if (! @mysql_select_db('jokes') ) {
  51.
         
  52.
      die ( '<p>Unable to locate the joke' .
  53.
          ' database at this time.</p>');
  54.
         }
  55.
       
  56.
      $sql = 'create table Jokes (
  57.
         id int not null auto_increment primary key,
  58.
         JokeText text,
  59.
         JokeOther text,
  60.
         JokeDate date not null)';
  61.
      if (@mysql_query($sql)) {
  62.
         echo('<p>Jokes table successfuly created!</P>' );
  63.
         }
  64.
         else {
  65.
            die('<p>Error creating Jokes table:' .
  66.
            mysql_error() . '</p>');
  67.
            }
  68.
      ?>
  69.
      ---------------------------------------------------------------
  70.
       
  71.
      the PROBLEM IS IN HERE, adding+deleting data. for the adding data its ok. but the problem is from the DELETING data. CANNOT DELETE.
  72.
      This is the script:
  73.
       
  74.
      ---------------------------------------------------------------------------------------------
  75.
       
  76.
      <html>
  77.
      <body>
  78.
       
  79.
      <?php
  80.
        if (isset($_GET['addjoke'])):
  81.
      ?>
  82.
       
  83.
       
  84.
      <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  85.
      <p>Type your jokes here:<br />
  86.
      <textarea name="joketext" rows="10" cols="40" wrap>
  87.
      </textarea><br />
  88.
      <input type="submit" name="submitjoke" value="submiT" /></p>
  89.
      </form>
  90.
      <?php
  91.
         else:
  92.
       
  93.
      $dbcnx=@mysql_connect('localhost', 'root', '');
  94.
      if (!@dbcnx) {
  95.
         echo( '<p>Unable co connect to the database server at this time.</p>' );
  96.
         }
  97.
       
  98.
      if (! @mysql_select_db('jokes') ) {
  99.
         die ( '<p>Unable to locate the joke database at this time.</p>');
 100.
         }
 101.
       
 102.
       
 103.
       
 104.
      if (isset($_POST['submitjoke'])){
 105.
         $joketext = $_POST['joketext'];
 106.
       
 107.
      $sql = "insert into jokes set
 108.
         joketext='$joketext',
 109.
         jokedate=CURDATE()";
 110.
       
 111.
      if (@mysql_query($sql)) {
 112.
         echo('<p>your joke has been added</P>' );
 113.
         }
 114.
         else {
 115.
            echo('<p>error adding joke: ' . mysql_error() . '</p>');
 116.
            }
 117.
         }
 118.
       
 119.
       
 120.
       
 121.
       
 122.
       
 123.
       
 124.
       
 125.
       
 126.
       
 127.
      if (isset($_GET['deletejoke'])) {
 128.
         $jokeid = $_GET['deletejoke'];
 129.
         $sql = ("DELETE FROM jokes WHERE id='$jokeid'");
 130.
       
 131.
         if (@mysql_query($sql)) {
 132.
              echo('<p>The joke deleted.</p>');
 133.
         } else {
 134.
              echo ('<p>ERROR DELETING JOKE: ' . mysql_error() . '</p>');
 135.
           }
 136.
      }
 137.
       
 138.
       
 139.
       
 140.
       
 141.
       
 142.
       
 143.
       
 144.
       
 145.
       
 146.
       
 147.
       
 148.
       
 149.
       
 150.
      echo('<p>Here are all the jokes in database:</p>');
 151.
       
 152.
       
 153.
      $result = @mysql_query('select joketext from jokes');
 154.
       
 155.
      if (!$result) {
 156.
         die('<p>Error performing query' . mysql_error() . '</p>');
 157.
         }
 158.
       
 159.
       
 160.
       
 161.
       
 162.
       
 163.
       
 164.
       
 165.
       
 166.
       
 167.
       
 168.
       
 169.
      while ($row= mysql_fetch_array($result) ) {
 170.
         $jokeid = $row['id'];
 171.
         $joketext = $row['joketext'];
 172.
         echo('<p>' . $joketext . '<a href="' . $_SERVER['PHP_SELF'] . '?deletejoke=' . $jokeid . '">' . 'Delete this joke<a/></p>');
 173.
      }
 174.
       
 175.
       
 176.
       
 177.
       
 178.
       
 179.
       
 180.
       
 181.
       
 182.
       
 183.
       
 184.
       
 185.
       
 186.
       
 187.
       
 188.
      echo('<p><a href="' . $SERVER['PJP_SELF'] .
 189.
         '?addjoke=1">Add  a Joke!</a></p>');
 190.
       
 191.
       
 192.
      endif;
 193.
       
 194.
      ?>
 195.
       
 196.
       
 197.
      </body>
 198.
      </html>
 199.
      ---------------------------------------------------------------------------
 200.
      When i click the delete link,nothing happen, it wont delete the data, just said "the joke is deleted" when i click the link.
 201.
      ---------------------------------------------------------------------
 202.
      thanx for the help