trouble with MYSQLi dropdown

Discussion in 'HTML & Website Design' started by ataloss, Aug 18, 2016.

  1. #1
    Hi, I'm trying for awhile to code up a MYSQLi dropdown from a database, select a field(url, formatted as "http://www.thisurl.com) and arrive at that destination. I've tried several forums re. compatability (connection/query/output etc..Problem is I blow up at the first query (see screen shot). It's like my PHP isn't working. If someone will advise of the PHP issue maybe I can work out the app code. Any volunteers? Thanks!
    --------------------------------------------------------------------- 1
    <!DOCTYPE html><html>.
    <title>email visit info</title>
    <head>
    </head>
    <BODY>
    create and display dropdown from database, url selected provides needed username and password. clicking on selected takes the user(me) to that url<br>
    <center>
    <form id="testform" name="testform" action="" method="post" accept-charset="UTF-8">

    <?php
    echo "<center>";echo date('m/d/y');echo "</center>";
    $con=mysqli_connect("localhost","root","cookie","homedb");
    //---------------------- check connection ------------------------
    if(mysqli_errno($con))
    {echo "Can't Connect to mySQL:".mysqli_connect_error();}
    else
    {echo "</br>";}
    $id = ''; $url= ''; $username = ''; $password = ''; $purpose = '';
    $emailused = ''; $date-time = ''; $count = ''; $saved = '';

    // ----------This creates the drop down box using records in the table -----------
    echo "<select name= 'url'>";
    echo '<option value="">'.' ---select email account ---'.'</option>';
    $query = mysqli_query($con,"SELECT url FROM emailtbl");
    $query_display = mysqli_query($con,"SELECT * FROM emailtbl");
    while($row=mysqli_fetch_array($query))
    { echo "<option class=highlight value='". $row['url']."'>".$row['url']
    .'</option>';}
    echo '</select>';
    ?>
    <input type="submit" name="submit" value="Submit"/>
    </form>
    {
    $url = $_POST['url'];

    // ----------------------- display the table ------------------------
    echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'
    <td bgcolor="#ccffff">'.'url'.'</td>'.'
    <td bgcolor="#ccffff">'.'username'.'</td>'.'
    <td bgcolor="#ccffff">'.'password'.'</td>'.'
    <td bgcolor="#ccffff">'.'purpose'.'</td>'.'
    <td bgcolor="#ccffff">'.'emailused'.'</td>'.'
    <td bgcolor="#FFD47F">'.'date-time'.'</td>'.'
    <td bgcolor="#FFD47F">'.'count'.'</td>'.'
    <td bgcolor="#ccffff">'.'saved'.'</td>'.'</tr>';
    // while($data = mysqli_fetch_row($fetch))
    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><td>$data[7]</td>
    </tr>");
    }
    echo '</table>'.'</td>'.'</tr>'.'</table>';
    mysqli_query($con,"UPDATE emailtbl SET
    date-time = 'DATE()'; count = 'count + 1';
    WHERE url=$url");
    ?>
    </center></body></html>

    ------------------------------------------------------------------------
    2
    <?php
    echo "<center>";echo date('m/d/y');echo "</center>";
    $con=mysqli_connect("localhost","root","cookie","homedb");
    //---------------------- check connection ------------------------
    if(mysqli_errno($con))
    {echo "Can't Connect to mySQL:".mysqli_connect_error();}
    else
    {echo "</br>";}
    $id = ''; $url= ''; $username = ''; $password = ''; $purpose = '';
    $emailused = ''; $date-time = ''; $count = ''; $saved = '';

    // ----------This creates the drop down box using records in the table -----------
    echo "<select name= 'url'>";
    echo '<option value="">'.' ---select email account ---'.'</option>';
    $query = mysqli_query($con,"SELECT url FROM emailtbl");
    $query_display = mysqli_query($con,"SELECT * FROM emailtbl");
    while($row=mysqli_fetch_array($query))
    { echo "<option class=highlight value='". $row['url']."'>".$row['url']
    .'</option>';}
    echo '</select>';
    ?>
    <input type="submit" name="submit" value="Submit"/>
    </form>
    {
    // ----------------------- display the table ------------------------
    echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'

    // ======================anchor attempt=========================
    // echo "<a href='".$row['url']."'>".$row['url']."</a>";
    // ==========================================================

    <td bgcolor="#ccffff">'.'username'.'</td>'.'
    <td bgcolor="#ccffff">'.'password'.'</td>'.'
    <td bgcolor="#ccffff">'.'purpose'.'</td>'.'
    <td bgcolor="#ccffff">'.'emailused'.'</td>'.'
    <td bgcolor="#FFD47F">'.'date-time'.'</td>'.'
    <td bgcolor="#FFD47F">'.'count'.'</td>'.'
    <td bgcolor="#ccffff">'.'saved'.'</td>'.'</tr>';
    // while($data = mysqli_fetch_row($fetch))
    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><td>$data[7]</td>
    </tr>");
    }
    echo '</table>'.'</td>'.'</tr>'.'</table>';
    mysqli_query($con,"UPDATE emailtbl SET
    date-time = 'DATE()'; count = 'count + 1';
    WHERE url=$url");
    ?>
    </center></body></html>
    -----------------------------------------------
    3
    <!DOCTYPE html><html>
    <head>
    <title>test 3</title>
    </head>
    <body><center>
    <form id="testform" name="testform" action="" method="post" accept-charset="UTF-8">

    <table border=1 cellpadding=2 cellspacing=2 bgcolor="#D4FFAA">
    <tr>
    <th>url</th><th>username</th><th>password</th><th>purpose</th>
    <th>emailused</th><th>date-time</th><th>count</th><th>saved</th>
    </tr>
    <?php
    $connect=mysql_connect("localhost", "root", "cookie") or die("error");
    mysql_select_db("homedb", $connect);
    $sql="SELECT * from emailtbl";
    $result=mysql_query($sql, $connect);
    $url='';;
    while($res=mysql_fetch_assoc($result))
    {
    echo "<tr>";
    echo "<td>"; echo '<input type="radio" name="url" >'; echo "</td>";
    echo "<td>"; echo $res['username']>'; echo "</td>";
    echo "<td>"; echo $res['password']; echo "</td>";
    echo "<td>"; echo $res['purpose']; echo "</td>";
    echo "<td>"; echo $res['emailused']; echo "</td>";
    echo "<td>"; echo $res['date-time']; echo "</td>";
    echo "<td>"; echo $res['count']; echo "</td>";
    echo "<td>"; echo $res['saved']; echo "</td>";
    echo "</tr>";
    }
    ?>
    </table> </form></body></html>
    --------------------------------------------------------
     
    ataloss, Aug 18, 2016 IP