Jump to content

help w/mysqli


88f615f6

Recommended Posts

Hi, 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>



 

Link to comment
https://forums.phpfreaks.com/topic/289029-help-wmysqli/
Share on other sites

Please use the forum's code tags when posting code.

 

CURDATE() is a SQL function and you cannot use it directly in PHP, only inside a query. You need to call an update query

$target = $con->real_escape_string($_POST['target']);
$sql = "UPDATE emailtbl SET lastused = CURDATE() WHERE target = '$target' ";
$con->query($sql);
Link to comment
https://forums.phpfreaks.com/topic/289029-help-wmysqli/#findComment-1482137
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.