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.

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

  • 2 weeks later...
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.