Get Request using arduino, ethernet shield and rfid to sql database

I want to send a htttp request by arduino to check the database on my server, I want to pass the uid scanned from rfid module as a parameter in the request. Please Help!

I am not getting any data when i pass the uid as a variable in http request function.

Here are my codes:

ARDUINO CODE-

/*
 * 
 SDA------------------------Digital 7

SCK------------------------Digital 13

MOSI----------------------Digital 11

MISO----------------------Digital 12

IRQ------------------------unconnected

GND-----------------------GND

RST------------------------Digital 9

3.3V------------------------3.3V (DO NOT CONNECT TO 5V) 
 * 
 * 
 */
 
#include <SPI.h>
#include <MFRC522.h>
#include <Ethernet.h>

#define SS_PIN 7
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "123abc.com"; /// server name
IPAddress ip(192, 168, 0, 177);
EthernetClient client;


void setup() 
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init(); 
  // Initiate MFRC522
  Ethernet.begin(mac, ip);
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
  Serial.println("Approximate your card to the reader...");
  Serial.println();

}
void loop() 
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    //Serial.println("12345");
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    //Serial.println("qwertyu");
    return;
    
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : "");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : ""));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
 
  content.toUpperCase();
 // Serial.println(content);

 http_request(content);
  delay(5000);
}


void http_request(String id){
  
  if (client.connect(server,80)) {
    Serial.println("connected");
    // Make a HTTP request:
    
   client.print( "GET /check.php?"); // php??
   client.print("username=");
   client.print(id);
   client.println( " HTTP/1.1");
   client.println( "Host: 123abc.com" );//ur web server
   client.println( "Content-Type: application/x-www-form-urlencoded" );
   client.println( "Connection: close" );
   client.println();
   delay(4000);
  while(true)
  {
    if (client.available()) {
    char c = client.read();
    //String s(c);
    Serial.print(c);
  
  }
  
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println("not ok");
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
   // while(true);
  }
  
  
  }

  }  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  
  
  }
  
  }

PHP file:

<?php
$servername = "localhost";
$username = "123";
$password = "abc";


// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
//echo "Connected successfully";

if (mysqli_select_db($conn,"id1196731")) {
   
//echo "Connected successfully";
}

$user=$_GET['username'];

$query="SELECT * FROM `users` WHERE `id` LIKE '$user';";
$res=mysqli_query($conn,$query);
$obj=mysqli_fetch_assoc($res);
echo ($obj['was']);

$conn->close();
?>

Do you get any serial output? Care to share it?

I have a library of functions for PHP scripts. One of them dumps all the GET variables to a file:

function PrintGetVars()
{
	$received = "Get vars\r\n\r\n";
	
	foreach($_GET as $key=>$value)
	{
		$received .= "$key = [$value]\r\n";
	}
	
	$printout = fopen("C:\\tmp\\get_variables.txt",'a');
	fwrite($printout, "Number of get variables: ");
	fwrite($printout, count($_GET));
	fwrite($printout, "\r\n");
	fwrite($printout, $received);
	fwrite($printout, "\r\n");
	fclose($printout);
}

Put this function in your PHP file, and call it:

   PrintGetVars();

Some clue may present itself. Change the file name, if needed. Looking at the server logs may prove useful, too.

Hey,
I think there is a problem in Your Ino Code. You have only declare the “String Id” But not assigned the Value of the Rfid tag Number. In the Place of “id” You have To use the "string content " On which the UID of rfid is Store.

By the Way i am attaching the Wright Code below.

/****INO.-/

/*
*
SDA------------------------Digital 7

SCK------------------------Digital 13

MOSI----------------------Digital 11

MISO----------------------Digital 12

IRQ------------------------unconnected

GND-----------------------GND

RST------------------------Digital 9

3.3V------------------------3.3V (DO NOT CONNECT TO 5V)
*
*
*/

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

#define SS_PIN 7
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server = “123abc.com”; /// server name
IPAddress ip(192, 168, 0, 177);
EthernetClient client;

void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init();
// Initiate MFRC522
Ethernet.begin(mac, ip);
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println(“connecting…”);
Serial.println(“Approximate your card to the reader…”);
Serial.println();

}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
//Serial.println(“12345”);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
//Serial.println(“qwertyu”);
return;

}
//Show UID on serial monitor
Serial.print(“UID tag :”);
String content= “”;
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : “”);
_ Serial.print(mfrc522.uid.uidByte*, HEX);_
_ content.concat(String(mfrc522.uid.uidByte < 0x10 ? " 0" : “”));
content.concat(String(mfrc522.uid.uidByte, HEX));
}
Serial.println();
content.toUpperCase();
// Serial.println(content);
http_request(content);
delay(5000);
}*_

void http_request(content){

* if (client.connect(server,80)) {*
* Serial.println(“connected”);*
* // Make a HTTP request:*

* client.print( “GET /check.php?”); // php??*
* client.print(“username=”);*
* client.print(content);*
* client.println( " HTTP/1.1");*
* client.println( “Host: 123abc.com” );//ur web server*
* client.println( “Content-Type: application/x-www-form-urlencoded” );*
* client.println( “Connection: close” );*
* client.println();*
* delay(4000);*
* while(true)*
* {*
* if (client.available()) {*
* char c = client.read();*
* //String s(c);*
* Serial.print(c);*

* }*

* // if the server’s disconnected, stop the client:*
* if (!client.connected()) {*
* Serial.println(“not ok”);*
* Serial.println(“disconnecting.”);*
* client.stop();*
* // do nothing forevermore:*
* // while(true);*
* }*

* }*
* } else {*
* // kf you didn’t get a connection to the server:*
* Serial.println(“connection failed”);*

* }*

* }*

By the Way i am attaching the Wright Code below.

I'm sure your code looks nothing like the crap you posted. You are SUPPOSED to use code tags to post code. Why couldn't you be bothered?