Data is not getting inserted in database - php

I am working on Flight portal. Lets assume that there are two pages (Search.php, Result.php).
In search page we will select the source,destination,date of journey..etc.(Now we will click on search button)
After clicking on the search button page will redirect to Result.php and there we will display the results.
Here before displaying the results on the page i am trying to insert those result in the database as below.
$q=0;
foreach($array_data['AvailResponse']['OriginDestinationOptions']['OriginDestinationOption'] as $main)
{
$basefare[$q]=$array_data['AvailResponse']['OriginDestinationOptions']['OriginDestinationOption'][$q]['FareDetails']['ActualBaseFare'];
$tax[$q]=$array_data['AvailResponse']['OriginDestinationOptions']['OriginDestinationOption'][$q]['FareDetails']['Tax'];
$stax[$q]=$array_data['AvailResponse']['OriginDestinationOptions']['OriginDestinationOption'][$q]['FareDetails']['STax'];
$tcharge[$q]=$array_data['AvailResponse']['OriginDestinationOptions']['OriginDestinationOption'][$q]['FareDetails']['TCharge'];
$scharge[$q]=$array_data['AvailResponse']['OriginDestinationOptions']['OriginDestinationOption'][$q]['FareDetails']['SCharge'];
$totalfare[$q]=$basefare[$q]+$tax[$q]+$stax[$q]+$tcharge[$q]+$scharge[$q];
$s=0;
foreach($array_data['AvailResponse']['OriginDestinationOptions']['OriginDestinationOption'][$q]['onward']['FlightSegments']['FlightSegment'] as $array)
{
$z1=$flightnumber[$q][$s]=$array['FlightNumber'];
$z2=$departureloc[$q][$s]=$array['DepartureAirportName'];
$z3=$departurecode[$q][$s]=$array['DepartureAirportCode'];
$z4=$arrivalloc[$q][$s]=$array['ArrivalAirportName'];
$z5=$arrivalcode[$q][$s]=$array['ArrivalAirportCode'];
$z6=$departuretime[$q][$s]=$array['DepartureDateTime'];
$z7=$arrivaltime[$q][$s]=$array['ArrivalDateTime'];
$z8=$airlinename[$q][$s]=$array['OperatingAirlineName'];
$z9=$airlineflightnumber[$q][$s]=$array['OperatingAirlineFlightNumber'];
$z10=$airlinecode[$q][$s]=$array['OperatingAirlineCode'];
echo $mysql_query="insert into RviewInternationalFlight (q,s,FlightNumber,OperatingAirlineName,OperatingAirlineFlightNumber,OperatingAirlineCode,DepartureAirportName,DepartureAirportCode,ArrivalAirportName,ArrivalAirportCode,DepartureDateTime,ArrivalDateTime,ip) values('$q','$s','$z1','$z2','$z3','$z4','$z5','$z6','$z7','$z8','$z9','$z10','$ip'
)";
mysql_query($mysql_query) or die(mysql_error());
$s++;
}
$q++;
}
It should work fine but i am getting the error MySQL server has gone away.
At top of the page the i am connecting the database. But still why that error is coming...
Any suggestions...?
Thanks

The server connection timed out and closed the connection. By default, the connection times out after 8 hours. If you have been leaving it open that long, it's probably not a good plan. See #JohnBlake comment.

Related

header redirect with include file

I've looked around on here and couldn't locate any solution for my little problem.
I currently have this following IF statment
if($page==1) {
$sql = "UPDATE page SET page='1' WHERE id=1";
INCLUDE 'month.php';
header("Refresh: 10; url=http://XXXXX.co.uk/?p=2");
}
Which currently updates a database according to what page it is on and then includes the current month calendar file and I hoped I could redirect it to page number 2 which is very much similar but loads another calendar and the SQL adds +2 to the database.
In essence it's just a loop I've made and it just reads a SQL database to see what page it needs to load next< I know there's better ways to create a loop (just to scroll through 3 PHP pages) but I'm not that great at PHP..
So i'm just wondering really, could anybody help me to have that include statement along with the header refresh?
Like said the purpose is so that the pages rolls a loop, I've managed to get it all to work with an iframe (instead of the header) but it takes a few seconds longer for the frame window to load.
#Mario that's perfect - I echoed the following:
if($page==1) {
$sql = "UPDATE page SET page='1' WHERE id=1";
echo '<meta http-equiv="refresh" content="5;url= http://XXXXX.co.uk/?p=2"/>';
INCLUDE 'month.php';
}
Which now loads the loop flawlessly - I've been up all night trying to get that working.
Thank you so much
Can I push page transitions I wonder?
Such as 'push out' or 'scroll out' ?

Mysterious issue in my php script

I've been developing a news letter system locally and everything works fine . The mystery begun when I uploaded the whole content to my server , I could see the index page but when I enter the username / Password to log in (in the index page), I get redirected to "authenticate.php " where the Post data are processed this way :
<?php include("includes/initialize.php");
if(!isset($_POST['username']) OR !isset($_POST['password']))
{
// no data were given
redirect_to("error.php");
}
elseif(!$user = User::authenticate($_POST['username'],$_POST['password']))
{
// user not found in the database
redirect_to("error.php");
}
else {
$session->login($user);
redirect_to("enewsletter.php");
}
?>
On this page I get stuck (not on localhost ) , the server is rendering a blank page . after some tests , I tell you what happens : If I fall in the if situation i get redirected to error.php , but when I enter some credentials , It's doing nothing :/
So I added an echo statement to keep trace of the code :
and I had this remark, every time the script meets to a line containing a method that looks in the database (OOP approach) the server is always rendering blank pages , I tried it on many pages and it's always the same . I changed the database connection type from PDO to mysqli (because I thought the server is not supporting PDO) but no change !!
Does any one has a clue , what could be the reason?
well ,
it was just a " Self instead of self " problem ...
Thank you all for your help ;)

This add new member code worked fine until I switched webhosts for my site now it does not and I have no idea why

I am having an issue with my adding a new member page,, also having an issue with my login page which is similar in code. Both worked fine, tested multiple times and ways and then I switched hosting companies. The rest of the database driven site works fine still except this part. Have no idea why and possibly just need fresh eyes on it. I am fairly new to php and mysql to begin with,,, then attempting to learn the newer versions to keep my code upgraded has me at this point unable to figure out why the code is no longer working. Any help would be much appreciated. Thanks.
The page will run up to this point,, I have confirmed that using echo, then it fails. The page itself, does not load, justs stays completely blank and the little loading wheel in the tab corner just spins and spins.
$sql="SELECT * FROM table WHERE field LIKE'$username'";
$rs=$db->query($sql);
$arr = $rs->fetch_all(MYSQLI_ASSOC);
// test to make sure there was not an issue loading the db
if($rs != true) { // start second if in nested section
// if any errors in reading the db redirect to a general db is down error page
//close db connection
mysqli_close($db);
// redirect header goes here, removed for this post
} else { // else to go with second if
// get number of rows returned in this case should be 0 or 1
$rows_returned = $rs->num_rows;
echo "num of rows are $rows_returned";
} // end second if

mysql data not being updated

Whilst moving from one host to another (to hostgator) we've received many errors. We did have a news editor edit code error once we moved, but we've fixed that. Now, we have an error updating data in page editor.
It can pull/select data and says saved, but it doesn't update the data in mysql.
Hosting error? was working before.
»Events Page
»Jobs Page
»Maintenance Page
»Staff Page
Thank you,
Maybe your previous host had autocommit=on, meaning you do not have to COMMIT.
Try a COMMIT statement at the end of each data update to actually save the data
echo("The CMS for the credits page has been updated!");
is just the php saying what you want it to say, it did not actually go into the database and check...
use
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else
{
echo("maintenance page updated");
}
to identify that your query is working fine or not

Echo SQL query on new page with PHP

I know this is probably a really amateur question, but I can't figure this out and I don't know much about PHP or MySQL.
So I have a really simple script that basically allows a user to submit a couple lines of text and their zipcode, then it write it to a database and returns the results on the site. It's a shoutbox essentially.
My client wants the users to be able to filter the results by zipcode. So I have it all setup, and I have a search input where people type in their zipcode, search, and then the PHP returns the submissions from that zipcode.
While I can get the results to show by themselves echoed from the PHP script, how do I get them to display within a specified div within the site? I want it essentially to store a variable, the zipcode, that a user search by, and then use that once the page refreshes to display an updated list that filters out the results that aren't from that zipcode.
Thanks so much for the help.
Chris
Without getting into rewriting etc.:
When you redirect your page, add a query at the end of it that is the zipcode making sure that you don't send any whitespace and that you have an input in a given format:
search.php?zipcode=90210
Then on your search results page, fetch the variable passed and work as usual:
$zipcode = $_GET['zipcode'];
make sure that the zipcode is properly escaped and filtered for nasties.
Make the HTML page a PHP page (usually by making the extension .php). Replace the target div's content with <?php stuff to get and print results ?>.
If you have PHP installed and configured on the web server, it will take certain files (usually those ending in .php) and run them through PHP's interpreter. The PHP interpreter is invoked anytime there is a <?php in the document and it stops parsing content anytime it meets a ?> within the <?php block.
For instance, to get a web page to print "Hello World!" into a div through PHP, I would do:
<div><?php
print 'Hello World!';
?></div>
OK, I figured it out. I just stored my answer in a SESSION variable so that I could call it in my other PHP files.
Now I have one file processing the request, creating the session and the variable, and then redirecting the page. Then I have a PHP included in the page that grabs the SESSION variable and plugs it into my mysql_query to return the proper result!
Not sure if this is the best way of doing it, but it's working.... If anyone knows of a more elegant solution I would love to know it.
Thanks,
Chris
I suggest you do some tutorials on using PHP and database retrieval with mysqli.
<?php
/* Connect to a MySQL server */
$link = mysqli_connect(
'localhost', /* The host to connect to */
'user', /* The user to connect as */
'password', /* The password to use */
'world'); /* The default database to query */
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
/* Send a query to the server */
if ($result = mysqli_query($link, 'SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {
print("Very large cities are:\n");
/* Fetch the results of the query */
while( $row = mysqli_fetch_assoc($result) ){
printf("%s (%s)\n", $row['Name'], $row['Population']);
}
/* Destroy the result set and free the memory used for it */
mysqli_free_result($result);
}
/* Close the connection */
mysqli_close($link);
?>

Categories