I have a QR scanner that will read the text that is embedded and I would like it to store the information into the SQL database. The database is setup, and the php site handles the input correctly if I enter manually into the URL (ex. www.blah.com/input.php?name=Bob
). However, I cannot figure out how to get the information to submit to my php site and/or put the information into the database. I'm sure there is a better/easier way. Below is the code I am using:
NSString *url= [NSString stringWithFormat:@"http://blah.com/input.php?name=%@", name];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString: url]];
Then this is my current php setup:
<?php
header('Content-type: text/plain; charset=utf-8');
$db_conn = new PDO('mysql:host=host;dbname=db','user','pwd');
$db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$date = date("m/d/y");
$time = date("h:i:sa");
//$name = "";
$name = ($_GET['name']);
$qry = $db_conn->prepare('INSERT INTO CheckIn(`date`,`time`,`name`) VALUES (:date,:time,:name)');
$qry->bindParam(':date', $date);
$qry->bindParam(':time', $time);
$qry->bindParam(':name', $name);
$qry->execute();
if ($qry) { $message = "success"; }
else { $message = "failed"; }
echo utf8_encode($message);
?>