Jump to content

[SOLVED] Why does this not work?


fry2010

Recommended Posts

<?php session_start();
require_once('bookmark.php');

  $user = 'fry2010';

      try
      {
      $conn2 = db_connect();
      $result = $conn2->query("INSERT INTO accountuser (joined) VALUES (CURDATE())");
       if(!$result)
        throw new Exception('error');
      }
      catch(Exception $e)
{

echo $e->getMessage();
}

$conn = db_connect();
$result = $conn->query(" SELECT joined FROM useraccount WHERE username = '$user' ");

while($row = $result->fetchObject())
{

  print $row->joined;
}
?>

 

The table has already been filled with a member. It finds the information correctly, but it doesnt perform the INSERT CURDATE() part. So it basically returns the default value which is '0000-00-00'.

 

This is the part that is not inserting:

 

      $result = $conn2->query("INSERT INTO accountuser (joined) VALUES (CURDATE())");

 

I have tried putting the CURDATE() in quotes aswell but still doesnt work. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/146944-solved-why-does-this-not-work/
Share on other sites

aha...that has helped. well it hasnt worked, but it helps by actualy telling me what is incorrect. Thank you.

 

It says 'field username doesnt have a default value...'

 

Ok i added a WHERE clause to select it with a given username. Now it says I have incorrect syntax with my where clause.

 

this:

      $result = $conn2->query("INSERT INTO useraccount (joined) VALUE (CURDATE()) WHERE username = '$user'");

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.