2015-07-27 7 views
-1

Мне нужна помощь от этой ошибки, я не могу вставить данные в свою базу данных, вы можете увидеть мои коды, im new in php, поэтому, пожалуйста, помогите мне в этом. Благодарим Вас за помогает и дает хороший ответ,Не удается вставить данные в мою базу данных Mysql?

он всегда говорит «ошибка eccurred при отправке» оно основано на моем еще состоянии

<?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

какая у вас ошибка? –

+2

Вы должны переключиться на более современный интерфейс базы данных, такой как PDO или mysqli, и добавить обработку ошибок во все вызовы базы данных. – jeroen

+1

Вы уверены, что нормально писать _ "'. $ Id.'" _? по-моему, это должно быть _ ". $ id." _ – Buzka91

ответ

0

В приведенном выше сценарии 2 if не закрыты. Первый - if(isset($_SESSION['username'])), а второй - if($form). Закройте фигурные скобки } в правильном месте, и это должно работать должным образом.

+0

Последняя Последняя ошибка: У вас возникла ошибка в синтаксисе SQL; проверьте руководство, соответствующее версии вашего сервера MySQL, для правильного синтаксиса для использования вблизи значений -p (rfv_code, rfvp_destination, rfvp_purpose, rfvp_duration) («RFV2015-2», «в строке 1 –

+0

@DannyAbuan: используйте' insert into \ 'rfv-p \' 'во втором запросе' INSERT' (обратите внимание на обратные выходы). – D4V1D

+0

Сэр, я получил его !!! Большое спасибо всем вам, все ваши предложения работают :) Godbless :) –

Смежные вопросы