I'm attempting a mysqli dropdown to select and print one record from table and update one
field, ("lastused" ($currdate))in that record. I get the following errors: Any help?

Notice: Undefined index: lastused in C:\xampp\htdocs\home\emaildrop.php on line 109

Notice: Undefined index: target in C:\xampp\htdocs\home\emaildrop.php on line 110
target Total results: 0

Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\xampp\htdocs\home\emaildrop.php on line 141
target username password emailused lastused purpose saved
could not retrieve data from database

<?php
 $db = new mysqli('localhost', 'root', 'cookie', 'homedb');
if($db->connect_errno > 0)
    {die('Unable to connect to database [' . $db->connect_error . ']');}

$lastused = $_POST['lastused']; // 108 ****************************
$target = $_POST['target']; // 109 *********************************

$currdate = date('Y-m-d');	
$lastused = $currdate;
if($target=="email"){$target=$username;}
//echo "lastused $lastused";
echo "target $target";
$sql = <<<SQL
SELECT * FROM `oocust` WHERE 'target' = '$target'
SQL;
if(!$result = $db->query($sql))
    {die('There was an error running the query [' . $db->error . ']');}
while($row = $result->fetch_assoc()) 
    {echo $row['username'] . '<br />';}
echo 'Total results: ' . $result->num_rows;

$result->free(); 
$db->escape_string('This is an unescape "string"');
$db->close();
?>
<center>
  <table cellspacing=2 cellpadding=0 border=1>
   <tr> 
    <th bgcolor="#ccffff">target</TH>      
<th bgcolor="#ccffff">username</TH> <th bgcolor="#ccffff">password</TH> <th bgcolor="#ccffff">emailused</TH> <th bgcolor="#ccffff">lastused</TH> <th bgcolor="#ccffff">purpose</TH> <th bgcolor="#ccffff">saved</TH> <?php while($data = mysql_fetch_array($result)) // 139 ******************************* { echo'<tr>'; // printing table row echo ' <td>'.$data['target'].'</td> <td>'.$data['username'].'</td> <td>'.$data['password'].'</td> <td>'.$data['emailused'].'</td> <td>'.$data['lastused'].'</td> <td>'.$data['purpose'].'</td> <td>'.$data['saved'].'</td>'; // looping all data to be printed till last row in the table echo'</tr>'; // closing table row } echo '</table>'; //closing table tag mysql_query("UPDATE emailtbl SET lastused=$lastused"); $result=mysql_query("select lastused from emailtbl") or die ("could not retrieve data from database"); $data=mysql_fetch_assoc($result); echo 'Total rows updated: ' . $db->affected_rows; echo "lastused ".$data['lastused']; mysql_close(); ?>

</table></center></body></html>

    Write a Reply...