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:
 

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
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?

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.