Problem getting values back from php

Hello guys,

For a test i was making a system for checking in and out to register my times in an online system. I am using an arduino uno, ethernet shield and a RDM6300 rfid module.

Now here is my problem. When I scan a tag it is inserted in the database and I let my php echo out the table from my database. My arduino receives this perfect.
As soon as i edit my php and change "SELECT voornaam, checkedin FROM users" to "SELECT voornaam, checkedin FROM users WHERE tagid='$arduinobericht" my arduino receives all data but not the 2 values from the database. When i open the php page in a browser it displays it without any problem.

Anyone can help me with the problem ?

database tables (tablename - field1, field2 ...)
log - id, tagid, timestamp
users - id, voornaam, achternaam, tagid, checkedin

php code:

<?php
   include("connect.php");
   $arduinobericht=$_GET["tagid"];
   $Sql="insert into log(tagid)  values ('".$_GET["tagid"]."')";     
   mysqli_query($con,$Sql);

   $result = mysqli_query($con,"select * from users WHERE tagid='$arduinobericht' ");
   //$response=mysql_fetch_array($result);


If ($response [4] == "1")
  {
    mysqli_query($con,"UPDATE users SET checkedin=0 WHERE tagid='$arduinobericht' ");
    //echo "$response[1]";
    echo " checked out";
  }
  else
  {
    mysqli_query($con,"UPDATE users SET checkedin=1 WHERE tagid='$arduinobericht' ");
    //echo "$response[1]";
    echo " checked in";
  }

$query = "SELECT voornaam, checkedin FROM users WHERE tagid='$arduinobericht'";
$result = mysqli_query($con, $query);

$row = $result->fetch_array(MYSQLI_ASSOC);
printf ("%s (%s)\n", $row[voornaam], $row[checkedin]);


//$result=mysqli_query($con,"select * from users");
//$row = mysqli_fetch_array($result);
//echo $row["voornaam"];
//printf("<arduino> %s %s </arduino>", $row["voornaam"], $row["checkedin"]);
   

mysqli_free_result($result);
?>

arduino code:

#include <SoftwareSerial.h>
#include <Ethernet.h>
#include <SPI.h>


byte mac[] = {  
  *my adruino mac is here* }; 
byte server[] = { 
  server.ip.adress.here }; // 		




EthernetClient client;

String http_response  = "";
int    response_start = 0;
int    response_end   = 0;



SoftwareSerial rfid(5,6);
String tagString;
char tagNumber[14];
boolean receivedTag;


void setup()
{
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) 
  {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600);
  Serial.print("arduino ip = ");
  Serial.println(Ethernet.localIP());
  //lcd.begin(16, 2);
  //lcd.print("systeem opgestart");
  Serial.println("ethernet started");
  rfid.begin(9600); // the RDM6300 runs at 9600bps
  Serial.println("Systeem klaar voor een tag!");
  delay(2000);
}


void loop()                                           
{

  checkrfid();

  if (receivedTag)
  {
    tagString=tagNumber;
    Serial.println();
    Serial.print("Tag Number: ");
    Serial.println(tagString);
    sendrfid();  // send rfid to database
    delay(2500); // a delay of 1500ms and a flush() seems to stop tag repeats
    rfid.flush();
  }
  memset(tagNumber,0,sizeof(tagNumber)); //erase tagNumber                 
}

void checkrfid()
{
  receivedTag=false;
  while (rfid.available())
  {
    int BytesRead = rfid.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag 
    receivedTag=true;
  }
}


void sendrfid()
{
  if (client.connect(server,80))
  {
    Serial.println("Connected!");      
    client.print( "GET /rfid/view.php");
    client.println( " HTTP/1.1");
    client.println( "Host: *my server domain" );
    client.println("Connection: close");
    client.println();
    Serial.print("Tag ");
    Serial.print(tagString);
    Serial.println(" submitted to database.");
    Serial.println("disconnecting.");
    delay(1500);
    while (client.available()>0) 
    {
      char c = client.read();
      http_response += c;   // We store the response in a string
    }
    Serial.println(http_response);
    filterresponse();
    client.stop();
    
    
    
  }

  else
  {
    Serial.println("Cannot connect to Server");               
  }
  

}

void checkedin ()
{
    tone(8, 250,150);
    delay(150);
    tone(8, 350, 250);
}

void checkedout ()
{
  
}

void filterresponse()
{
  if((http_response.indexOf("<arduino>") > -1 )&&(http_response.indexOf("</arduino>") > -1 )){ 
                                                                     // We check if the <arduino></arduino> are there.
      response_start = http_response.indexOf("<arduino>")+9; 
                                                                     // Where it begins, the 9 is the length of ' <arduino> ', 
                                                                     // since we dont want it to appear in the response.
      response_end = http_response.indexOf("</arduino>"); 
                                                                     // Where it ends
      http_response = http_response.substring(response_start,response_end); 
                                                                     // We keep only the response of the website
      Serial.print("Website response : ");
      Serial.println(http_response);
      Serial.println();
    } 
    else {
      Serial.println("No response detected...");
      Serial.println();
    } 
}
   $arduinobericht=$_GET["tagid"];
   $Sql="insert into log(tagid)  values ('".$_GET["tagid"]."')";

You've already copied the value from the _GET name/value list. Why do it twice?

You are assuming that $arduinobericht actually gets valued. That's not necessarily a valid assumption.

   //$response=mysql_fetch_array($result);


If ($response [4] == "1")

With the declaration of $response commented out, how can you meaningfully use the 4th element of the non-existent array?

$result = mysqli_query($con, $query);

$row = $result->fetch_array(MYSQLI_ASSOC);
printf ("%s (%s)\n", $row[voornaam], $row[checkedin]);

You ought to verify that $result contains something before dereferencing it.
You ought to verify that $row contains something before dereferencing it.

You ought not assume that the query will succeed or that it will return more than 0 records.

PaulS:
You've already copied the value from the _GET name/value list. Why do it twice?

You are assuming that $arduinobericht actually gets valued. That's not necessarily a valid assumption.

I did this to test if it would make a difference (but it didn't)

PaulS:
With the declaration of $response commented out, how can you meaningfully use the 4th element of the non-existent array?

Also a test to see if it would make a difference, even when not commented out not working on arduino, but working perfectly on php page

PaulS:
You ought to verify that $result contains something before dereferencing it.
You ought to verify that $row contains something before dereferencing it.

You ought not assume that the query will succeed or that it will return more than 0 records.

If no results I get it, but when there are results my arduino displays everything but the table values when using "WHERE tagid='$arduinobericht" if i delete that it will display my conplete table on arduino and cell values do work.
So i still have no idea why the "WHERE tagid='$arduinobericht" gives a problem, because my php page gives a correct page including the values where my arduino gives me a response like:

arduino ip = 192.168.1.39
ethernet started
Systeem klaar voor een tag!

Tag Number: 05004788FE34
Connected!
Tag 05004788FE34 submitted to database.
disconnecting.
HTTP/1.1 200 OK
Date: Tue, 25 Jun 2013 14:52:34 GMT
Server: Apache/2
Vary: Accept-Encoding,User-Agent
Content-Length: 15
Connection: close
Content-Type: text/html

 checked in ()

No response detected...

so it gets "checked in ()" from the php page but no values, same data imported in php page gives me: "checked inUser1 (1)"

When a RFID tag is scanned, this is the code that is executed, to send data to the server.

    client.print( "GET /rfid/view.php");
    client.println( " HTTP/1.1");
    client.println( "Host: *my server domain" );
    client.println("Connection: close");
    client.println();

Do you see a RFID tag in there, anywhere? I don't. Therefore,

$arduinobericht=$_GET["tagid"];

is going to result in $arduinobericht being equal to "".

Then,

$query = "SELECT voornaam, checkedin FROM users WHERE tagid='$arduinobericht'";
$result = mysqli_query($con, $query);

$row = $result->fetch_array(MYSQLI_ASSOC);
printf ("%s (%s)\n", $row[voornaam], $row[checkedin]);

is going to execute the SELECT statement:
SELECT voornaam, checkedin FROM users WHERE tagid=''

which, I suspect, is going to result in an error or, at a minimum, no rows being selected.

Which is consistent with the results you are getting.

How are you testing the code from a browser? The EXACT URL, please.

sorry for the confusion, code is a bit messed because i tried a lot of possible solutions.

exact url is: http://timvanhulst.nl/rfid/add.php?tagid=050045E47BDF
you see that it displays everything perfectly there.

using that same url in the arduino using:
client.print( "GET /rfid/add.php?");
client.print("tagid=");
client.print( tagString ); // tagstring is inserted correct because i see it inserted in mySQL database

gives me arduino response:

Tag Number: 050045E47BDF
Connected!
Tag 050045E47BDF submitted to database.
disconnecting.
   HTTP/1.1 200 OK
Date: Tue, 25 Jun 2013 15:58:43 GMT
Server: Apache/2
Vary: Accept-Encoding,User-Agent
Content-Length: 37
Connection: close
Content-Type: text/html

 checked in
<arduino>   </arduino>
Website response :

current php code:

<?php
   include("connect.php");
   $arduinobericht=$_GET["tagid"];
   $Sql="insert into log(tagid)  values ('".$_GET["tagid"]."')";     
   mysqli_query($con,$Sql);

   $result = mysqli_query($con,"select * from users WHERE tagid='$arduinobericht' ");
   $response=mysqli_fetch_array($result);


If ($response [4] == "1")
  {
    mysqli_query($con,"UPDATE users SET checkedin=0 WHERE tagid='$arduinobericht' ");
    echo "$response[1]";
    echo " checked out";
  }
  else
  {
    mysqli_query($con,"UPDATE users SET checkedin=1 WHERE tagid='$arduinobericht' ");
    echo "$response[1]";
    echo " checked in";
  }

$query = "SELECT voornaam, checkedin FROM users WHERE tagid='$arduinobericht'";
$result = mysqli_query($con, $query);

//$row = $result->fetch_array(MYSQLI_ASSOC);
//printf ("%s (%s)\n", $row[voornaam], $row[checkedin]);


$result=mysqli_query($con,"select * from users WHERE tagid='$arduinobericht'");
$row = mysqli_fetch_array($result);
printf("
<arduino> %s %s </arduino>", $row["voornaam"], $row["checkedin"]);
   

mysqli_free_result($result);
?>

*maybe some help, arduino always displays "checked in"
url must be correct in arduino because i have the correct value in my Database

   $result = mysqli_query($con,"select * from users WHERE tagid='$arduinobericht' ");
   $response=mysqli_fetch_array($result);


If ($response [4] == "1")

What is supposed to be in the 4th element of this array? I would never expect a specific number of values to the in the response to a query. There are other ways to get the results, one row at a time, as name/value pairs. Then, the value is not array position dependent.

url must be correct in arduino because i have the correct value in my Database

That URL is to the add.php script. The earlier code was pointing to the read.php script. Did you rename the script? Or, do you need to make different requests depending on whether you are checking in or out? How is the php script supposed to know whether you are coming or going?