Question

I am trying to update mysql table with AJAX and php script, but I am still receiving "304 Not modified" message. I have searched many questions here and also searched for it with google but without any luck... I am 100% sure all variables are sent with AJAX and received by PHP in correct form, I have checked it like this:

$tabulka=$_SESSION["uzivatel"];
$slovensky=testVstupov($_POST["slovensky"]);
$prelozene=testVstupov($_POST["prelozene"]);
$druh=testVstupov($_POST["druh"]);
$lekcia=testVstupov($_POST["lekcia"]);
$reset=testVstupov($_POST["reset"]);
$id=testVstupov($_POST["id"]);
$nula=0;
//echo $tabulka."#".$slovensky."#".prelozene."#".$druh."#".$lekcia."#".$reset."#".$id."#".$nula;

function testVstupov($data)
{
    $data=trim($data);
    $data=stripslashes($data);
    $data=htmlspecialchars($data);
    return $data;
}

that echo is just to make sure all variables are filled with correct value

Then I try to update table, but it results with 304 message, variable $hodnoty is returned empty:

$pripojenie=mysqli_connect("localhost","user","password","database");

if (mysqli_connect_errno($pripojenie))
{
echo "Zlyhalo pripojenie do databázy: ".mysqli_connect_error();
}
if($reset == "false")
{
    $hodnoty = mysqli_query($pripojenie, "UPDATE `$tabulka` SET slovensky=$slovensky, preklad=$prelozene, druh=$druh, lekcia=$lekcia WHERE id='$id'");
}

if(mysqli_error()) 
{ 
die('Zápis do databázy sa nepodaril. Chyba: ' . mysqli_error() ); //skjurajozimy.
}
//ukncenie spojenia s databazou
mysqli_close($pripojenie);

Same code in other php file but only to modify different collumns in same table works. This code works:

$pripojenie=mysqli_connect("localhost","user","password","database");

if (mysqli_connect_errno($pripojenie))
{
echo "Zlyhalo pripojenie do databázy: ".mysqli_connect_error();
}

$vysledok=mysqli_query($pripojenie, "SELECT skusane,spravne FROM `$tabulka` WHERE preklad='$data1'");
if(mysqli_error()) 
{ 
die('Výpis z databázy sa nepodaril. Chyba: ' . mysqli_error() ); //`skjurajozimy`.
}

$hodnoty = mysqli_fetch_array($vysledok);
$noveSkusane = $hodnoty['skusane']+1;
$noveSpravne = $hodnoty['spravne']+$data2;
$uspesnost = round($noveSpravne*$noveSkusane);

$hodnoty = mysqli_query($pripojenie, "UPDATE `$tabulka` SET skusane=$noveSkusane, spravne=$noveSpravne, uspesnost=$uspesnost WHERE preklad='$data1'");
if(mysqli_error()) 
{ 
die('Zápis do databázy sa nepodaril. Chyba: ' . mysqli_error() ); //`skjurajozimy`.
}
//ukncenie spojenia s databazou
mysqli_close($pripojenie);

collumns in my table are: id slovensky preklad druh lekcia skusane spravne uspesnost , where id is autoincrement.

Please, any suggestions, why update code doesn't work?

Was it helpful?

Solution 2

Finally solution, problem was with ticks and spaces, so correct code here:

$hodnoty = mysqli_query($pripojenie, "UPDATE  `$databaza`.`$tabulka` SET  `slovensky` =  '$slovensky',  `preklad` = '$prelozene',  `druh` = '$druh',  `lekcia` = '$lekcia'  WHERE  `$tabulka`.`id` =$id;");

OTHER TIPS

Have you tried:

header( 'Cache-Control: no-store, no-cache, must-revalidate' ); 
header( 'Pragma: no-cache' ); 

at the beginning of your PHP function?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top