Jump to content

trouble w/mysqli update


ckir5951

Recommended Posts

Hi, I am having trouble coding for mysqli update. Please, somebody
tell me the correct way. I'm trying to update the "lastused" (current date)
field in "emailtbl". Somebody please tell the best way to code this.
Below is the message and following, the current code:
 

  Quote
Fatal error: Call to undefined function curdate() in C:\xampp\htdocs\home\lastused.php on line 14

 

 
$db = new mysqli('localhost', 'root', 'pass', 'mydb');
if($db->connect_errno > 0)
{die('Unable to connect to database [' . $db->connect_error . ']');}
$sql = <<<SQL
    SELECT *
    FROM `emailtbl`
    WHERE `id` = '$id'
SQL;

if(!$result = $db->query($sql))
{die('There was an error running the query [' . $db->error . ']');}
$lastused = $_POST['lastused'];
$lastused = curdate();
echo "last date accessed is ".$data['lastused'];
$result->free();
$db->escape_string('This is an unescape "string"');
$db->close();
?>
$update 

= mysqli_query($dbconnect, "UPDATE emailtbl SET
   lastused = curdate() WHERE id ='$id'");
    if($update == false)
    { die("UPDATE FAILED: ".mysqli_error($dbconnect)); }
    echo "$lastused is the last date this account was accessed";
 

Link to comment
https://forums.phpfreaks.com/topic/289795-trouble-wmysqli-update/
Share on other sites

Your code is a mess and makes no sense to the issue you are asking about.  The update query you are asking about isn't even in the code posted.  In the code you are using mysqli in oop style but then using it in procedural in the update query example.  Also using $db for the connections in the code but $dbconnect in the update example.  the curdate should be in all caps CURDATE(), although it might work in lowercase too but that's not how is supposed to be coded.  Plus why in the heck would you use a herdoc for the sql string rather than just normal double quotes?

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.