I am having tough time to transfer my RFID tag no. to mysql database. When I compile the given code server gets connected so and prints the rfid no. and also says data sent to server but when I open my php file (also mysql) there is no data stored. What am I doing wrong!! P.s sorry for my bad english.
#include <Ethernet.h>
#include <SPI.h>
#include <Client.h>
#include<SoftwareSerial.h>
SoftwareSerial RFID(2,3);
int i;
int rfid;
char newtag[14];// = {2,49,51,48,48,57,69,66,48,51,57,48,52,3};
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte subnet[] = {255,255,255,0};
//IPAddress gateway(192,168,1,1);
//IPAddress DBserver(192, 168, 1, 2);
IPAddress server(192,168,1,7);
//char server[] = "localhost/te";
IPAddress ip(192,168,1,2);
EthernetClient client;
void setup()
{
Serial.begin(9600);
RFID.begin(9600);
delay (1000);
Serial.print("*********Initializing Ethernet*********n");
if (Ethernet.begin(mac) == 0)
{
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
//Ethernet.begin(mac, server, gateway);
delay(1000);
Serial.println("connecting...");
Serial.print("IP Address:");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask:");
Serial.println(Ethernet.subnetMask());
Serial.print("Default Gateway IP:");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server IP:");
Serial.println(Ethernet.dnsServerIP());
}
void loop()
{
// while(1)
{
if (client.connect(server, 80))
{
Serial.print("Connected to server:");
Serial.println(Ethernet.dnsServerIP());
while(1)
{
if (RFID.available() > 0)
{
Serial.println("reading rfid tags");
delay(100);
for (i=0; i < 14; i++)
{
rfid = RFID.read();
newtag[i]=rfid;
}
RFID.flush();
Serial.print("rfid tag no:");
Serial.print(newtag);
Serial.println("Sending to Server...");
client.println("GET 192.168.1.7/te/add_data.php?sensor=2323 HTTP/1.1");
client.print(newtag);
client.println(" HTTP/1.1");
client.println("Host: 192.168.1.7/te/");
client.println("User-Agent: Arduino");
client.println("Accept: text/html");
Serial.println("data sent to server");
}
}
}
else
{
Serial.println("Cannot connect to Server");
}
}
and my php code is
<?php
// Start MySQL Connection
include('dbconnect.php');
?>
<html>
<head>
<title> Log</title>
<style type="text/css">
.table_titles, .table_cells_odd, .table_cells_even {
padding-right: 20px;
padding-left: 20px;
color: #000;
}
.table_titles {
color: #FFF;
background-color: #666;
}
.table_cells_odd {
background-color: #CCC;
}
.table_cells_even {
background-color: #FAFAFA;
}
table {
border: 2px solid #333;
}
body { font-family: "Trebuchet MS", Arial; }
</style>
</head>
<body>
<h1>Arduino Log</h1>
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="table_titles">ID</td>
<td class="table_titles">Date and Time</td>
<td class="table_titles">RFID tag</td>
</tr>
<?php
// Retrieve all records and display them
$result = mysql_query("SELECT * FROM FYP ORDER BY id ASC");
// Used for row color toggle
$oddrow = true;
// process every record
while( $row = mysql_fetch_array($result) )
{
if ($oddrow)
{
$css_class=' class="table_cells_odd"';
}
else
{
$css_class=' class="table_cells_even"';
}
$oddrow = !$oddrow;
echo '<tr>';
echo ' <td'.$css_class.'>'.$row["id"].'</td>';
echo ' <td'.$css_class.'>'.$row["event"].'</td>';
echo ' <td'.$css_class.'>'.$row["tag"].'</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>