mysqli dropdown

limited

New Member
Hi, the project is to create a dropdown (using mysqli) which displays the selected record
and updates a field (lastused - the current date)in that record. Nothing happens when I
click the submit button. Any help?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
<html><body>
<form name="form" action="" method="post">
Select email to view<SELECT name=target>
<OPTION class=highlight value=email selected>owenspaulette59@yahoo
<OPTION class=highlight value=paypal>paypal 
<OPTION class=highlight value=ebay>ebay
</SELECT><p>
<CENTER><input type="submit" name="submit" value="THEN submit choice"><p>
PHP:
<?php  
$lastused = (isset($_POST['lastused']))?1:0;   
$target = (isset($_POST['target']))?1:0;
$id = (isset($_POST['id'])) ? mysqli_real_escape_string($dbconnect, $_POST['id']) : '';   
$dbconnect = mysqli_connect('localhost','root','cookie')or die(mysqli_error($dbconnect));
$result = mysqli_query($dbconnect, "SELECT * FROM emailtbl");
    if($result === FALSE) { die(mysql_error()); }
    echo date('m/d/y');
// if($target=="email"){$target=$username;}
// $lastused = $row['CURDATE()']; 
$lastused = date('Y-m-d');
  ?>
  <table cellspacing=0 cellpadding=0 border=1>
   <tr>  
    <th bgcolor="#7FFF2A">target</th>
  <th bgcolor="#7FFF2A">username</th>
  <th bgcolor="#7FFF2A">password</th>
  <th bgcolor="#7FFF2A">emailused</th>
  <th bgcolor="#7FFF2A">lastused</th>
  <th bgcolor="#7FFF2A">purpose</th>
  <th bgcolor="#7FFF2A">saved</th> 
  </tr>
<?php
  
 while($row = mysql_fetch_array($result))  
   { 
echo "<tr>";
echo "<td>" . $row['target'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "<td>" . $row['emailused'] . "</td>";
echo "<td>" . $row['lastused'] . "</td>";
echo "<td>" . $row['purpose'] . "</td>";
echo "<td>" . $row['saved'] . "</td>";
 echo "</tr>";
 echo "</table>
<input type='submit' name='update' value='submit' />
</form>";
if (!empty($_POST['update_lastused']))
  { $update = mysqli_query($dbconnect, "UPDATE emailtbl SET lastused = '$lastused' WHERE id ='$id");
       if($update == false)
       { die("UPDATE FAILED: ".mysqli_error($dbconnect)); }
       echo "Success!";
  }
    else { echo "oops!"; }
  }
?>
Code:
</body></html>
 
If you're running this in Chrome or Firefox, open the console with CTRL + SHIFT + J and then try clicking submit. You should get some javascript errors as to why your code isn't posting. Do this and if it doesn't show anything, I'll look more in depth at what your actual code is doing, but it doesn't sound like it's even getting to the PHP code.
 
Last edited:
Going forward you can post all the code in a single php or code block :)

If nothing is being output to the browser have you checked your php log on the server? I suspect there's an error and it's not getting pushed to the browser due to your php config.
 
Back
Top