0

I created a sql database on my localhost machine later on i'd like to connect it to an online sql server for now i'd like to read the qr code using php code:

<?php
mysql_connect(“localhost“,”root“,”root“) or die(mysql_error());
mysql_select_db(“omi“) or die(mysql_error());
$data = mysql_query(“insert into $_GET[table] values ($_GET[id])”)
or die(mysql_error());
?>

which must take the input via a url localhost.com/get.php?table=id,id=1234 but there is an error saying parsing error on line 4, for reading via QRcode i will insert the server address in the QRcode along with the php values and read it via a barcode reader and push the code to insertion. how do i get the code working ??

Omi Harjani
  • 737
  • 1
  • 8
  • 20
  • 1
    You're using MS Word to code? See those curly quotes `“ ”` replace them with regular quotes `"` if that is your actual code. – Funk Forty Niner Jan 04 '15 at 15:18
  • so should it be like: – Omi Harjani Jan 04 '15 at 15:19
  • What's the error? There are a lot of things that could be going wrong here. One thing that you might want to look at is the URL itself. `localhost.com/get.php?table=id,id=1234` doesn't have an "ID" field that would be accessable via $_GET[id]. You might need to change the URL to `localhost.com/get.php?table=id&id=1234` (replace the , with an &) – Brian Hoover Jan 04 '15 at 15:20
  • also I think you have to specify the collumn name you want insert $_get['id'] into, like this: `INSERT INTO tbl_name (col1,col2) VALUES(col2*2,15); ` – Richard87 Jan 04 '15 at 15:20
  • ok ill change it to & richard87 i think it should work i tried the query. – Omi Harjani Jan 04 '15 at 15:22
  • 3
    *"so should it be like..."* - Sure, sort of. However, doing this leaves you open to a massive [**SQL injection**](http://stackoverflow.com/q/60174/). – Funk Forty Niner Jan 04 '15 at 15:23
  • on doing the changes Table 'omi.id' doesn't exist error occurs even though i have executed the query create table id(id int primary key); – Omi Harjani Jan 04 '15 at 15:26
  • ok so it becomes highly insecure – Omi Harjani Jan 04 '15 at 15:27
  • `get.php?table=TABLE_NAME&id=1234` – Funk Forty Niner Jan 04 '15 at 15:27
  • it worked for local host but when im trying to connect to a remote server say 123.12.123.76:3306 how do i run it using the url?? so i can connect the php code with it?? – Omi Harjani Jan 04 '15 at 15:45

0 Answers0