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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.