Access denied selecting database

For debugging purposes I use the following:



  # content should be validated to prevent GIGO
  $contentOfPost = isset( $_POST['contentOfPost'] ) ? $_POST['contentOfPost'] : FALSE;

  if ( ! $contentOfPost && $submit != $_POST['submit'] )
  {
    echo '<pre>';
       print_r( $_POST );
    echo '</pre>';
    die;
  }
  else
  {
    $link = mysql_connect($host, $username, $password);

    if(!$link)
    {
      echo "link";
      die(mysql_error());
    }

    $db_selected = mysql_select_db($DbName, $link);
    if( ! $db_selected )
    {
        echo "dbselect";
        die(mysql_error());
     }

     $insertionToDatabase=
     "
       INSERT INTO $tableName
       (
         PostNumber, Date, Time, Content
       )
       VALUES
       (
        NULL, $date, $time, $contentOfPost
       )
     ";
     $result = mysql_query($insertionToDatabase);
    # check your SQL on error
    if ( ! $result )
    {
       echo $insertionToDatabase;
       echo '<br />';
       die( 'Invalid query: ' . mysql_error() );
    }
    echo $result;
    mysql_close($link);
  }//endelse
?>


Also, check your table Field type, Defaults and Attributes and let the database do all the work :slight_smile:

Field Type => TIMESTAMP

Default => CURRENT _TIMESTAMP

Attributes => on update CURRENT_TIMESTAMP

Yes the time field in my database is correct. It matches what you wrote down for me to have.

As for that code, what am I replacing it with? I posted a new thread describing my issue along with my full code.

@RyanReese

Yes the time field in my database is correct. It matches what you wrote down for me to have.

As for that code, what am I replacing it with? I posted a new thread describing my issue along with my full code.

If the time field is set to TIMESTAMP then changing the Default and Attributes in the table structure field dropdowns eliminate the need to pass the date and current time on updates.


   #  Defaults inserted for PostNumber, Date, Time
   $insertionToDatabase= "INSERT INTO $tableName   (  Content )  VALUES  ( $contentOfPost )";


As for that code, what am I replacing it with? I posted a new thread describing my issue along with my full code.

On errors encountered the code I posted displays more informative error messages.

I changed the attributes to “null”

And ok thanks for the debugging tools :).