topflight Posted November 1, 2008 Share Posted November 1, 2008 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 More sharing options...
topflight Posted November 1, 2008 Author Share Posted November 1, 2008 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 https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680149 Share on other sites More sharing options...
Mchl Posted November 1, 2008 Share Posted November 1, 2008 <?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 https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680151 Share on other sites More sharing options...
topflight Posted November 1, 2008 Author Share Posted November 1, 2008 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 https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680156 Share on other sites More sharing options...
Mchl Posted November 1, 2008 Share Posted November 1, 2008 Could you paste line 64 (and also preferably a few lines above it)? Link to comment https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680170 Share on other sites More sharing options...
topflight Posted November 1, 2008 Author Share Posted November 1, 2008 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 https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680172 Share on other sites More sharing options...
Mchl Posted November 1, 2008 Share Posted November 1, 2008 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 https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680182 Share on other sites More sharing options...
topflight Posted November 1, 2008 Author Share Posted November 1, 2008 Still the same error. Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\pirep_phrase.php on line 64 Link to comment https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680188 Share on other sites More sharing options...
Mchl Posted November 1, 2008 Share Posted November 1, 2008 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 https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680208 Share on other sites More sharing options...
topflight Posted November 1, 2008 Author Share Posted November 1, 2008 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 https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680219 Share on other sites More sharing options...
dropfaith Posted November 1, 2008 Share Posted November 1, 2008 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 https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680223 Share on other sites More sharing options...
Mchl Posted November 1, 2008 Share Posted November 1, 2008 Heh... I see it now... or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680224 Share on other sites More sharing options...
topflight Posted November 1, 2008 Author Share Posted November 1, 2008 I am confused, PID is field on the form. Link to comment https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680225 Share on other sites More sharing options...
dropfaith Posted November 1, 2008 Share Posted November 1, 2008 prid,login,dep,arr,rte,dur,ac,hub,date,callsign,event,vflight,fcomments right pid is a field on the form but its not listed here prid is not pid Link to comment https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680229 Share on other sites More sharing options...
topflight Posted November 1, 2008 Author Share Posted November 1, 2008 oo I forgot to tell u guys that Login is PID so I apologize about that but I am still getting the error message. Link to comment https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680234 Share on other sites More sharing options...
Mchl Posted November 1, 2008 Share Posted November 1, 2008 $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 https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680235 Share on other sites More sharing options...
topflight Posted November 1, 2008 Author Share Posted November 1, 2008 yes PID is instering into the log in field Link to comment https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680264 Share on other sites More sharing options...
dropfaith Posted November 1, 2008 Share Posted November 1, 2008 ahh my bad then the code mchl posted looks like it should work i was just trying to find any errors i saw and that struck me as a possible error Link to comment https://forums.phpfreaks.com/topic/131009-not-insterting-into-database/#findComment-680268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.