Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

trouble with mysqli dropdown


  • Please log in to reply
No replies to this topic

#1 12Strings

12Strings

  • Members
  • 41 posts
  • OFFLINE
  •  
  • Local time:09:35 AM

Posted 18 August 2016 - 07:45 PM

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>

--------------------------------------------------------


Edited by 12Strings, 18 August 2016 - 07:47 PM.


BC AdBot (Login to Remove)

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users