ckir5951 Posted July 12, 2014 Share Posted July 12, 2014 Hi, I am having trouble coding for mysqli update. Please, somebodytell 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"; Quote Link to comment Share on other sites More sharing options...
fastsol Posted July 12, 2014 Share Posted July 12, 2014 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? Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 12, 2014 Share Posted July 12, 2014 And the error message is probably referring to this line: $lastused = curdate(); CURDATE() is a MYSQL function NOT a PHP function. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.