Hi, The following code selects and displays a record from the "emailtbl" table
as desired except for the the date and it doesn't update the "lastused" (date)
field to the "numbers" table via "lastused.php" include. No error messages. I need help.

<html><head> 
</head>
<BODY>
     <?php
include ("lastused.php");
include ("counter.php");
$id="''";
    $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>";}

// ==========This creates the drop down box using records in the table

       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 class=highlight value='". $row['target']."'>".$row['target']
    .'</option>';}
    echo '</select>';
    ?>
<input type="submit" name="submit" value="Submit"/>
    </form>
     <?php
        if(isset($_POST['target']))
  {
    $id = ' ';
    $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));}

// =============================== this displays the table

    echo '<table border="1">'.'<tr>'.'<td bgcolor="#FFD47F" align="center">'. 'email menu'. '</td>'.'</tr>';
    echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'<td bgcolor="#ccffff">'.'target'.'</td>'.'<td bgcolor="#ccffff">'.'username'.'</td>'.'<td bgcolor="#ccffff">'. 'password' .'</td>'.'<td bgcolor="#ccffff">'. 'emailused'. '</td>'.'<td bgcolor="#FFD47F">'. 'lastused' .'</td>'.'<td bgcolor="#ccffff">'. 'purpose'. '</td>'.'<td bgcolor="#ccffff">'. 'saved' .'</td>'.'</tr>';
//    while( $row = mysqli_fetch_assoc( $result ) )
// 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></tr>");}
    echo '</table>'.'</td>'.'</tr>'.'</table>';
  }
    ?>
    </body></html>

lastused.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', true); // set to false for production

if(!empty($_POST['update_lastused']))
 {
    $dbconnect = mysqli_connect('localhost','root','cookie');
    mysqli_select_db($dbconnect, 'homedb') or die( "Unable to select database");

// let prepared statements with bound parameters take care of input sanitation
    $sql = "UPDATE emailtbl SET lastused = NOW() WHERE id = ?";
    $stmt = mysqli_prepare($dbconnect, $sql);

// make sure it worked
    if($stmt == false)
    {throw new Exception("Prepare failed".PHP_EOL.mysqli_error($dbconnect).PHP_EOL.$sql);}
    mysqli_stmt_bind_param($stmt, 'i', $sql);
    $update = mysqli_stmt_execute($stmt);

// ditto
    if($update == false)
    {throw new Exception("Update failed:".PHP_EOL.mysqli_stmt_error($stmt).PHP_EOL.$sql);}
 }
   ?> 
Member Avatar for diafol

In which format is lastused? yyyy-mm-dd (Y-m-d)? or something else?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.