Results 1 to 1 of 1

Thread: mysqli dropdown

  1. #1
    Join Date
    May 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mysqli dropdown

    I got one of those AHA moments. The following code
    is what I want in that it creates a menu and I can select and
    display a table row. I still need to use that selection to update
    the "lastused". I really appreciate your help.



    <!DOCTYPE><html><head><title>email menu</title></head>
    <body><center>
    <form name="form" method="post" action="">
    <?php
    $con=mysqli_connect("localhost","root","cookie","homedb");
    //============== check connection
    if(mysqli_errno($con))
    {echo "Can't Connect to mySQL:".mysqli_connect_error();}
    else
    {echo "Connected to mySQL</br>";}
    //This creates the drop down box
    echo "<select name= 'target'>";
    echo '<option value="">'.'--- Select email account ---'.'</option>';
    $query = mysqli_query($con,"SELECT target FROM emailtbl");
    $query_display = mysqli_query($con,"SELECT * FROM emailtbl");
    while($row=mysqli_fetch_array($query))
    {echo "<option value='". $row['target']."'>".$row['target']
    .'</option>';}
    echo '</select>';
    ?>
    <input type="submit" name="submit" value="Submit"/><!-- update "lastused" using selected "target"-->
    </form></body></html>

    <!DOCTYPE><html><head><title>email menu</title></head>
    <body><center>
    <?php
    $con=mysqli_connect("localhost","root","cookie","homedb");
    if(mysqli_errno($con))
    {echo "Can't Connect to mySQL:".mysqli_connect_error();}
    if(isset($_POST['target']))
    {
    $name = $_POST['target'];
    $fetch="SELECT target,username,password,emailused,lastused, purpose, saved FROM emailtbl WHERE target = '".$name."'";
    $result = mysqli_query($con,$fetch);
    if(!$result)
    {echo "Error:".(mysqli_error($con));}
    $lastused = "CURDATE()"; // update "lastused" using selected "target"
    //display the table
    echo '<table border="1">'.'<tr>'.'<td bgcolor="#ccffff align="center">'. 'Email menu'. '</td>'.'</tr>';
    echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'<td bgcolor="#ccffff align="center">'.'target'.'</td>'.'<td bgcolor="#ccffff align="center">'.'username'.'</td>'.'<td bgcolor="#ccffff align="center">'.'password'.'</td>'.'<td bgcolor="#ccffff align="center">'.'emailused'.'</td>'.'<td bgcolor="#ccffff align="center">'.'lastused'.'</td>'.'<td bgcolor="#ccffff align="center">'.'purpose'. '</td>'.'<td bgcolor="#ccffff align="center">'. 'saved' .'</td>'.'</tr>';
    while($data=mysqli_fetch_row($result))
    {echo ("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td><td>$data[4]</td><td>$data[5]</td><td>$data[6]</td></tr>");}
    echo '</table>'.'</td>'.'</tr>'.'</table>';
    }
    ?>
    </body></html>
    Last edited by 12Strings; 06-07-2014 at 03:54 AM.

Similar Threads

  1. mysqli dropdown
    By 12Strings in forum PHP
    Replies: 2
    Last Post: 06-02-2014, 05:35 PM
  2. Resolved mysql and mysqli connect
    By Deadweight in forum MySQL and other databases
    Replies: 1
    Last Post: 05-11-2014, 05:39 PM
  3. MySQLi and the PHP5.4 breaking changes.
    By ApacheTech in forum PHP
    Replies: 1
    Last Post: 07-28-2012, 05:30 PM
  4. Change syntax from mysqli to mysql
    By newphpcoder in forum PHP
    Replies: 0
    Last Post: 10-27-2011, 09:34 AM
  5. Mysqli vs Mysql and CMS
    By Victro in forum MySQL and other databases
    Replies: 2
    Last Post: 06-16-2010, 02:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •