mysql - PHP _GET issue not refreshing data on multiple tries


I have a php script that is triggered from my app. This script uses the GET method to retrieve information from the url and put it into a database. I have got it to work so far except for the fact when I try to do multiple requests.

For example, I did a test where every time I would take the name of the database from the GET, put it into the appropriate database, retrieve the last entry, and then it would add 7 each time and echo it to the screen/put it back into the database as the newest number. I tried this within my browser hitting refresh every time and the first time it worked. Second time I hit refresh, it gave me the same results as the first time. I kept trying but same result so I closed the browser and tried it again. It worked as it should.

So the problem I think has to do with the script not receiving the connection the second, third, fourth... time around. It seems to only work the first time. I thought this was an issue with the data being cached but I turned off cache within the php script.

Can someone please tell me why it only works on the first attempt?



header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


function checkToken ()


$passed= $_GET['token'];

$pieces = explode(" ", $passed); /*Contains two pieces of information.  
                                       First is for the correct table and 
                                       and the second is the actually data 
                                       that will be put into the tables*/
$search= $pieces[1];

$table= $pieces[0];

echo $table." ".$search;

 $db= new mysqli('localhost', $username, $password, $database);

if (mysqli_connect_errno())
    echo 'Error: Could not connect';


$query = "SELECT * FROM `Tokens` WHERE `Number` LIKE '%$search%' ";

       echo "after";

$result = $db->query($query);
if ($result) {
    $num_results = $result->num_rows;

    $row = $result->fetch_assoc();

    echo $row;

    if (!$row)
        echo "No Token, insert into database";



   /*problem may be around here...? does not always go into (!row)
     after the first time when it is supposed too*/

echo $row['Numbers'];

} else {
   // echo "Query failed: {$db->error}\n";

    echo "No";



function insertToken ($daTable, $daToken)



 $con= mysql_connect("localhost",$username,$password);


  $res = mysql_query(
VALUES ('', '$token')");
if (!$res) {
die('Invalid query: ' . mysql_error());
 } else  {
echo "complete";





maybe a cache problem? try to make sure the code gets executed at all, like echoing the time

People are also looking for solutions to the problem: php - Search for matching subarray in parent or child of a multidimensional array


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.