mysql data not being updated - php

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

Related

PHP Form Posting Worked Yesteday But Not Today

I have a form that up to yesterday was working with post to insert the form data into mysql table. Today it all stopped working and I changed nothing. This is driving me crazy.
Allot of the answers provided on line are based on correcting incorrect code. My code is correct, at least i think it is. It all worked fine after I wrote it and used it for several days. Then one day it just stopped working.
My post code is as follows.
<?php
include 'quality_module_connect.php';
// Don't forget to properly escape your values before you send them to DB
// to prevent SQL injection attacks
echo "<p>Content variables $_POST is:</p>";
print_r($_POST);
$field1 = $mysqli_real_escape_string($_POST['field1']);
$sql = "INSERT INTO test(test)
VALUES ('$field1')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
The results are that nothing is getting posted into the mysql table and I get no error message. When I insert with an insert statement without using post it all works fine.
How do I solve the problem?
I found the answer and it was not in the code, at least I do not think it was. I was opening the form using a hypelink with target="_blank"in the hyperlink statment so that it would open on a new tab. For some reason the new tab requirements with target="_blank" was causing the POST to be empty. Once I got rid of that everything is back to normal and fine. It would be nice to understand why.

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

Data is not getting inserted in database

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.

Problem with UPDATE MySQL

I have a bit of an issue with my code.
I'm making an administrative panel for users to add things to the database. On occasion, they might try to save data without changing it (open a dialog, click save without changing anything). This, of course, will make mysql_affected_rows() return '0' when checking to see if the UPDATE query worked.
Is there another query to make that will always UPDATE regardless of whether the data is the same or not (or can I modify a simple UPDATE query to always update)?
EDIT
This is for users who don't have programming experience. Of course you wouldn't want to update if there's no reason to, but when a user tries to update and it doesn't happen I end up showing a failure message. Rather than there being something wrong, its just it doesn't need to be updated. I need a way to show the user that, instead of a generic 'failure' message. If it failed for another reason, I still need to know.
From the MySQL Documentation:
If you set a column to the value it currently has, MySQL notices this
and does not update it.
Instead of checking mysql_affected_rows, just check to see if the query was successful:
if(!mysql_query("UPDATE ..."))
{
//failure
}
else
{
$verification = mysql_query("SELECT ROW_COUNT() as rows_affected");
$row = mysql_fetch_row($verification);
$rows_affected = $row[0];
if ($rows_affected > 0)
{
//update was performed
}
else
{
//no update was needed
}
}

Categories