Jump to content

Not Insterting into database


topflight

Recommended Posts

I am trying to create a report sciprt and nothing is not being imported into the database. I am not receiving any errors, it is just not importing into the database. Also I have another question how can I set this code up so that every time the use input a number in the dur it will add it to the database.(i.e 5 hours are in the database, but when a user type in 2 hours in the dur field on the script it should be 7 in the database.)

 

Here is my code

<?php
if(!$_COOKIE['login'])
{
header("Location:login.php");
}
?> 
<?php
include 'db.php';
?>
<?php
$pid = $_POST['pid'];
$hub = $_POST['hub'];
$dep = $_POST['dep'];
$arr = $_POST['arr'];
$rte = $_POST['rte'];
$dur = $_POST['dur'];
$event = $_POST['event'];
$callsign = $_POST['callsign'];
$date = $_POST['date'];
$ac = $_POST['ac'];
$vflight = $_POST['vflight'];

if((!$dep) || (!$arr) || (!$date) || (!$hub) || (!$ac) || (!$rte) || (!$vflight)){ 
echo '<font color="#FF0000"><center>You did Not Submit The Following Information!</center></font>';

      if(!$dep){

         echo"<br />No Deparure Airport!<br /><br />";

     }
     
     if(!$arr){
	echo"<br />No Arrival Airport!<br /><br />";
}

if(!$dur){
	echo"<br />No Duration Time!<br /> <br />";
}

if(!$dur){
	echo"<br />No Duration Time!<br /> <br />";
}
if(!$rte){
	echo"<br />No Route!<br /><br />";
}
if(!$date){
	echo"<br />No Date<br /><br />";
}
if(!$ac){
	echo"<br>Please tell us if this flight was on VATSIM<br /><br />";
}
if(!$event){
	echo"<br>Please tell us if this was a flyin event<br /><br />";
}

die;

}

else {
include("db.php");

mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments) 
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight',','$_POST[fcomments])')");?>

<script>
javascript:alert("Pirep Submitted Into Database!")
window.location="127.0.0.1";
</script>
<?php

}
?>

 

Link to comment
Share on other sites

I changed

<?php
mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments) 
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight',','$_POST[fcomments])')");?>
?>

to

<?php
mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments) 
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight',','$_POST[fcomments])')")or die mysql_error());?>

 

and now I am recceviong the following error Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\pirep_phrase.php

Link to comment
Share on other sites

<?php
mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments) 
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight','{$_POST['fcomments']}')")or die mysql_error());?>

 

Note {} around $_POST['fcomments']

Link to comment
Share on other sites

Mchi, I changed it and now I am receiving the following error

 

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\pirep_phrase.php on line 64

 

line 64 is

<?php
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight','{$_POST['fcomments']}')")or die mysql_error());?>

 

Link to comment
Share on other sites

This is the entire code

<?php
if(!$_COOKIE['login'])
{
header("Location:login.php");
}
?> 
<?php
include 'db.php';
?>
<?php
$pid = $_POST['pid'];
$hub = $_POST['hub'];
$dep = $_POST['dep'];
$arr = $_POST['arr'];
$rte = $_POST['rte'];
$dur = $_POST['dur'];
$event = $_POST['event'];
$callsign = $_POST['callsign'];
$date = $_POST['date'];
$ac = $_POST['ac'];
$vflight = $_POST['vflight'];

if((!$dep) || (!$arr) || (!$date) || (!$hub) || (!$ac) || (!$rte) || (!$vflight)){ 
echo '<font color="#FF0000"><center>You did Not Submit The Following Information!</center></font>';

      if(!$dep){

         echo"<br />No Deparure Airport!<br /><br />";

     }
     
     if(!$arr){
	echo"<br />No Arrival Airport!<br /><br />";
}

if(!$dur){
	echo"<br />No Duration Time!<br /> <br />";
}

if(!$dur){
	echo"<br />No Duration Time!<br /> <br />";
}
if(!$rte){
	echo"<br />No Route!<br /><br />";
}
if(!$date){
	echo"<br />No Date<br /><br />";
}
if(!$ac){
	echo"<br>Please tell us if this flight was on VATSIM<br /><br />";
}
if(!$event){
	echo"<br>Please tell us if this was a flyin event<br /><br />";
}

die;

}

else {


mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments) 
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight','{$_POST['fcomments']}')")or die mysql_error());?>

<script>
javascript:alert("Pirep Submitted Into Database!")
window.location="127.0.0.1";
</script>
<?php

}
?>

This is Line 64

<?php
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight','{$_POST['fcomments']}')")or die mysql_error());?>
[code]

Link to comment
Share on other sites

Unpaired parentheses at mysql_error()

 

mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments) 
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight','{$_POST['fcomments']}')")or die mysql_error();?>

 

 

Link to comment
Share on other sites

Well.. what if you add this after line 21

$fcomments = $_POST['fcomments']

(BTW: you should sanitize all those values before inserting into database)

 

 

and change your query like this

 

mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments) 
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight','$fcomments')")or die mysql_error();

Link to comment
Share on other sites

I changed the query to look like u said it to look and no I am receiving this error

 

 

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\pirep_phrase.php on line 65

 

this line

 

 

mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments)

VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight','$fcomments')")or die mysql_error();

Link to comment
Share on other sites

prid is not defined and i assume its auto incremented in the database and therefor you dont need to insert it as its not php defined by the post

$pid = $_POST['pid'];

 

is defined and not in the  insert

 

mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments)

VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight','$fcomments')")or die mysql_error();

Link to comment
Share on other sites

$pid is inserted into 'login' field. Wether it's wrong or not, we don't know.

The reason for 'T_STRING' error is that 'die' construct needs parentheses, when it gets parameter (obvious now...)

so:

 

 

mysql_query("INSERT INTO pirep(prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments)
VALUES('','$pid','$dep','$arr','$rte','$dur','$ac','$hub','$date','$callsign','$event','$vflight','$fcomments')")or die(mysql_error());

 

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.