Jump to content

not inserting to database


Dracolas

Recommended Posts

Without even seeing your code I can tell you that it does not have any logic in it for error checking, error reporting (and logging), and error recovery to get it to tell you why it did not insert anything into the database, so it will be a little hard for anyone in a forum to tell you why either.

 

If you look at any of the existing threads at phpfreaks.com where queries fail to work, you will find that in almost every case, the suggestion is to add some logic to test for and display any errors that are occurring.

 

Short-answer: If you are sure the query is actually being executed, echo mysql_error() right after the query to find out why the query failed.

code is at the link he gave and yes you are right, it is his logical flow.

because you are not running the mysql_query call through an if clause.

if (isset($_POST['submit'])) 
{ 
   // now we insert it into the database
   $insert = "INSERT INTO wars (`username`, `date`, `opponent`, `osite`, `type`, `player1`, `player2`, `opponent1`, `opponent2`, `cshot`, `r1shot`, `r2shot`,    `r3shot`, `result`, `comments`)
   VALUES ( $username, getdate(), '".$_POST['opponent']."' , '".$_POST['osite']."' , '".$_POST['type']."' , '".$_POST['player1']."' , '".$_POST['player2']."' ,    '".$_POST['opponent1']."' , '".$_POST['opponent2']."' , '".$_POST['cshot']."' , '".$_POST['r1shot']."' , '".$_POST['r2shot']."' , '".$_POST['r3shot']."' , '".$_POST['result']."' ,    '".$_POST['comments']."')";
   if ($add_member = mysql_query($insert))
   {
      ?>
      <h1>War Added</h1>
      <p>Thank you, War added.</p>
      <?php 
   } 
   else 
   { 
      ?>
      <h1><center>Add War Report</center></h1><p>
      // etc
   }
   // etc
}

  • 2 weeks later...

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.