Jump to content

mySQL Insert (PHP)


a1amattyj

Recommended Posts

Hello,

 

When someone fills in my form, its meant to record such variables into the database. Im just developing it but it wont inset them into the database and nor does it show any errors:

 

<?php
//Grab captcha from form and template header..
session_start();
include("header.php");
?>

<?
//Grab the index form for report
if(!$_GET){
include("form.php");
}
?>

<?
//Check for errors in form 
if($_GET['act']=='report'){
   //Check security code is correct
   if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {

         //Swap post's to variables..
         $visitormail = $_POST['email'];
         $name = $_POST['name'];
         $forumname = $_POST['forumname'];
         $domain = $_POST['domain'];
         $type = $_POST['type'];
         $comment = $_POST['comment'];
         $sure = $_POST['sure'];
         $ip = $_POST['ip'];
         $httpref = $_POST['httpref'];
         $httpagent = $_POST['httpagent'];
         $date = date("F j, Y, g:i a");

                   $a = 0;

                  //Check fields arn't empty..
                  if(empty($visitormail) || empty($name) || empty($domain) || empty($forumname) || empty($type) || empty($sure) || empty($comment )) {
                  echo "Please go back and fill in all fields\n";
                  $a = 1;
                  }

                  //Check the email is valid..
                  if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")) && $a==0)
                  {
                  echo "<h1>Error!</h1><p>Sorry, you did not enter a valid email. Go back a try again\n</p>";
                  $a = 1;
                  }


//If all is correct make database query
if($a==0){
?>
<h1><center>Forum Reported..</center></h1>
<p>
<table width="300"><tr width="20"><td>Thanks for reporting, <span style="color:green; font-weight:bold"><? echo "$name"; ?></span>.</td></tr></table>

<? 
//Grab mySQL Details
include("config.php");
//Inset into the database
mysql_query("INSERT INTO `easyfor1_reports`.`reports` (`forumname`, `name`, `email`, `type`, `ip`, `date`, `status`, `comments`) VALUES (\'$forumname\', 
\'$name\', \'$visitormail\', \'$type\', \'$ip\', \'$date\', \'Pending\', \'$comment\');'");
?>

<?
}


   //Give errror if security code is incorrect
   unset($_SESSION['security_code']);
   } else {
    echo "Enter a valid captcha image please..";
   }

} 


?>


<?
//Grab footer template
include("footer.php");
?>

 

Thanks

Link to comment
Share on other sites

Use <?php instead of just <?

Use mysql_error() after your query and it will show you the error.

Remove all those slashes in your VALUES variables in your INSERT statement.

 

Thanks,

 

After submitted now i get this error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';'' at line 2

Link to comment
Share on other sites

Looks like you have a stragler single quote left, maybe this one

 

$comment);'  <---

 

Repost just the query line.

 

Thanks alot, it works now.

 

FROM :

 

mysql_query("INSERT INTO `easyfor1_reports`.`reports` (`forumname`, `name`, `email`, `type`, `ip`, `date`, `status`, `comments`) VALUES ('$forumname', 
'$name', '$visitormail', '$type', '$ip', '$date', 'Pending', '$comment');'") or die(mysql_error());

 

TO

 

mysql_query("INSERT INTO `easyfor1_reports`.`reports` (`forumname`, `name`, `email`, `type`, `ip`, `date`, `status`, `comments`) VALUES ('$forumname',

'$name', '$visitormail', '$type', '$ip', '$date', 'Pending', '$comment')") or die(mysql_error());

 

Thanks alot.

Link to comment
Share on other sites

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.