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
https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/
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

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

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());?>

 

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]

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();?>

 

 

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();

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();

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();

$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());

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.