不能将数据插入我的Mysql数据库?

时间:2015-07-27 08:20:43

标签: php mysql

我需要这个错误的帮助我不能将数据插入我的数据库,你能看到我的代码,我刚刚在PHP中所以请帮助我。谢谢你的帮助,并给出了一个好的答案,

它总是说“发送时发生的错误”是基于我的其他情况

<?php
if(isset($_SESSION['username']))
{
$form = true;
$orfvp_destination = '';
$oreq_approver= '';
$oreq_noter = '';
$orfvp_duration = '';
$orfvp_purpose = '';

//to check if the form has been sent
if(isset($_POST['rfvp_destination'], $_POST['req_approver'], $_POST['req_noter'], $_POST['rfvp_duration'], $_POST['rfvp_purpose']))
{
  $orfvp_destination = $_POST['rfvp_destination'];
  $oreq_approver = $_POST['req_approver'];
  $oreq_noter = $_POST['req_noter'];
  $orfvp_duration = $_POST['rfvp_duration'];
  $orfvp_purpose = $_POST['rfvp_purpose'];
  //to remove slashes depending on the configuration
  if(get_magic_quotes_gpc())
  {
    $orfvp_destination = stripslashes($orfvp_destination);
    $oreq_approver = stripslashes($oreq_approver);
    $oreq_noter = stripslashes($oreq_noter);
    $orfvp_duration = stripslashes($orfvp_duration);
    $orfvp_purpose = stripslashes($orfvp_purpose);
  }
  //to check if all the fields are filled
  if($_POST['rfvp_destination']!='' and $_POST['req_approver']!='' and $_POST['req_noter']!='' and $_POST['rfvp_duration']!='' and $_POST['rfvp_purpose']!='')
  {
    //to protect the variables
    $rfvp_destination = mysql_real_escape_string($orfvp_destination);
    $req_approver = mysql_real_escape_string($oreq_approver);
    $req_noter = mysql_real_escape_string($oreq_noter);
    $rfvp_duration = mysql_real_escape_string(nl2br(htmlentities($orfvp_duration, ENT_QUOTES, 'UTF-8')));
    $rfvp_purpose = mysql_real_escape_string($orfvp_purpose);
    //to check if the recipient exists
   
    $dn1 = mysql_fetch_array(mysql_query('select count(user_id) as req_approver, user_id as req_approverid, (select count(*) from request) as npm from users where user_username="'.$req_approver.'"'));
    $dn2 = mysql_fetch_array(mysql_query('select count(user_id) as req_noter, user_id as req_noterid, (select count(*) from request) as npm from users where user_username="'.$req_noter.'"'));
    if($dn1['req_approver'] and $dn2['req_noter']==1)
    {
      //to check if the recipient is not the actual user
      if($dn1['req_approverid']!=$_SESSION['userid'] and $dn2['req_noter']!=$_SESSION['userid'])
      {
        $id = $dn1['npm']+1 and $dn2['npm']+1;

        //We send the message
        if(mysql_query('insert into rfv (rfv_id, rfv_code, rfv_driver, rfv_vehicle)values("'.$id.'", "RFV2015-'.$id.'", "", "")') 
          and mysql_query('insert into rfv-p (rfv_code, rfvp_destination, rfvp_purpose, rfvp_duration)values("RFV2015-'.$id.'", "rfvp_destination", "rfvp_purpose", "rfvp_duration")')
          and mysql_query('insert into request (req_code, req_date, req_status, req_dateneeded, req_requestor, req_approver, req_noter, form_id)values( "RFV2015-'.$id.'", NOW(), "Waiting for Approval", "'.$_POST['req_dateneeded'].'", "'.$_SESSION['userid'].'", "'.$dn1['req_approverid'].'","'.$dn2['req_noterid'].'",  2)'))
        
        {

?>
<p style="color:red" align="center" >Request Successfully Created!</p>
<p style="color:red" align="center" ><a href="http://localhost/xampp/elev8log/index2.php">Home</a></p>
<?php
          $form = false;
        }
        else
        {
          //Otherwise, we say that an error occured
          $error = 'An error occurred while sending the message';
        }
      }
      else
      {
        //Otherwise, we say the user cannot send a message to himself
        $error = 'You cannot send a message to yourself.';
      }
    }
    else
    {
      //Otherwise, we say the recipient does not exists
      $error = 'The recipient does not exists.';
    }
  }
  


  else
  {
    //Otherwise, we say a field is empty
    $error = 'A field is empty. Please fill of the fields.';
  }
}
elseif(isset($_GET['req_approver'], $_GET['req_noter']))
{
  //We get the username for the recipient if available
  $oreq_approver = $_GET['req_approver'];
  $oreq_noter = $_GET['req_noter'];
}
if($form)
{
//We display a message if necessary
if(isset($error))
{
  echo '<div class="message" align="center" style="color:red">'.$error.'</div>';
}
//We display the form





?>

1 个答案:

答案 0 :(得分:0)

在上面的脚本中,2 if未关闭。第一个是if(isset($_SESSION['username'])),第二个是if($form)。在正确的位置关闭大括号},这应该按预期工作。

相关问题