<select> and variables problem

  • Pbpixels
  • Novice
  • Novice
  • User avatar
  • Posts: 17

Post 3+ Months Ago

Hey all, I have problems declaring a variable to a select form, or that is what I think is wrong. My code goes like this:

PHP Code: [ Select ]
require_once('connectvars.php');
 
  //Connects to your Database
 require_once('connectvars2.php');
 $data = mysql_query("SELECT * FROM cmslogin ORDER BY id DESC")
 or die(mysql_error());
 
  if (isset($_POST['execute'])) {
 
 $select = $_POST['select'];
 $id = $_POST['id'];
 $email = $_POST['email'];
 
 $data = "DELETE FROM cmslogin WHERE id = $id";
 $result = mysql_query($data);
 
 echo "hej $email";
 
  }
   //Connects to your Database
 require_once('connectvars2.php');
 $data = mysql_query("SELECT * FROM cmslogin")
 or die(mysql_error());
 
  echo '<form method="post">';
  echo '<select name="select">';
 
 while($row = mysql_fetch_array( $data )) {
 
 echo "<p><option value" . $row['id'] . ">" . $row['email'] . "</option></p>";
 
 }
 
  echo '</select>';
  ?>
<input type="submit" name="execute" />
 </form>
            <div id="footer" class="footer4">
               <a href="/cms/pbcms/main.php">
               <img src="images/back.png" /></a>
            </div>
<?php
}
?>
 
  1. require_once('connectvars.php');
  2.  
  3.   //Connects to your Database
  4.  require_once('connectvars2.php');
  5.  $data = mysql_query("SELECT * FROM cmslogin ORDER BY id DESC")
  6.  or die(mysql_error());
  7.  
  8.   if (isset($_POST['execute'])) {
  9.  
  10.  $select = $_POST['select'];
  11.  $id = $_POST['id'];
  12.  $email = $_POST['email'];
  13.  
  14.  $data = "DELETE FROM cmslogin WHERE id = $id";
  15.  $result = mysql_query($data);
  16.  
  17.  echo "hej $email";
  18.  
  19.   }
  20.    //Connects to your Database
  21.  require_once('connectvars2.php');
  22.  $data = mysql_query("SELECT * FROM cmslogin")
  23.  or die(mysql_error());
  24.  
  25.   echo '<form method="post">';
  26.   echo '<select name="select">';
  27.  
  28.  while($row = mysql_fetch_array( $data )) {
  29.  
  30.  echo "<p><option value" . $row['id'] . ">" . $row['email'] . "</option></p>";
  31.  
  32.  }
  33.  
  34.   echo '</select>';
  35.   ?>
  36. <input type="submit" name="execute" />
  37.  </form>
  38.             <div id="footer" class="footer4">
  39.                <a href="/cms/pbcms/main.php">
  40.                <img src="images/back.png" /></a>
  41.             </div>
  42. <?php
  43. }
  44. ?>
  45.  


I want it to select a email from a list created from the cmslogin database and then delete it after a push on the button.
Thanks in advance :)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 476

Post 3+ Months Ago

Well If you haven't figured this out by now. In the form you have here there are only two bits of info one is the button and the other is the select box. There is nothing there about id or email just "select", which I think is a bad name would change that to "email". However using your example the submission code should look like this.

PHP Code: [ Select ]
if(isset($_POST['execute'])) {
 
    $select = $_POST['select'];
 
    $data = "DELETE FROM cmslogin WHERE id = $select";
    $result = mysql_query($data);
 
}
 
  1. if(isset($_POST['execute'])) {
  2.  
  3.     $select = $_POST['select'];
  4.  
  5.     $data = "DELETE FROM cmslogin WHERE id = $select";
  6.     $result = mysql_query($data);
  7.  
  8. }
  9.  
  • Pbpixels
  • Novice
  • Novice
  • User avatar
  • Posts: 17

Post 3+ Months Ago

Hi ScottG, I have figured this out already but thank you anyway for taking your time to write it, I examined your example and it looks completely like how I would do it now :-)

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 76 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.