I'm trying to add variables into MySQL. The Column Slot is of type INT and B1 -> B12 is of type VARCHAR(20).
我正在尝试将变量添加到MySQL中。列槽的类型为INT,B1 - > B12的类型为VARCHAR(20)。
$slot1 to $slot4 is a string.(Ex: 4PMTo6PM).The database connects and everything works well when I add hard coded data into the query. However
$ slot1到$ slot4是一个字符串。(例如:4PMTo6PM)。当我将硬编码数据添加到查询中时,数据库连接并且一切正常。然而
However when I pass it over using an NSURL, I dont seem to insert the data. Any help would be appreciated.
但是,当我使用NSURL传递它时,我似乎没有插入数据。任何帮助,将不胜感激。
<?php
$DB_hostname = "localhost";
$DB_Name = "root";
$DB_pass = "pwd";
if(isset($_GET["tabName"])){
$tableName = $_GET["tabName"];
$slot1 = $_GET["slot1Timing"];
$slot2 = $_GET["slot2Timing"];
$slot3 = $_GET["slot3Timing"];
$slot4 = $_GET["slot4Timing"];
}
$con = mysql_connect($DB_Hostname,$DB_Name,$DB_pass) or die(mysql_error());
mysql_select_db("booking", $con);
mysql_query("INSERT INTO $tableName (Slot,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12)VALUES
('1',$slot1,$slot1,$slot1,$slot1,$slot1,$slot1,$slot1,$slot1,$slot1,$slot1,$slot1,$slot1)");
mysql_query("INSERT INTO $tableName (Slot,B1, B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12)
VALUES ('2',$slot2,$slot2,$slot2,$slot2,$slot2,$slot2,$slot2,$slot2,$slot2,$slot2,$slot2,$slot2)");
mysql_query("INSERT INTO $tableName (Slot,B1, B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12)
VALUES ('3',$slot3,$slot3,$slot3,$slot3,$slot3,$slot3,$slot3,$slot3,$slot3,$slot3,$slot3,$slot3)");
mysql_query("INSERT INTO $tableName (Slot,B1, B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12)
VALUES ('4',$slot4,$slot4,$slot4,$slot4,$slot4,$slot4,$slot4,$slot4,$slot4,$slot4,$slot4,$slot4)");
mysql_close($con);
?>
sample data (Working)
样本数据(工作)
mysql_query("INSERT INTO $tableName (Slot,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12)VALUES
('1','1','1','1','1','1','1','1','1','1','1','1','1',)");
NSURL Connection
@"http://ip/booking/insertSlotsTable.php?tabName=%@&slot1Timing=%@&slot2Timing=%@&slot3Timing=%@&slot4Timing=%@",slotTableName,@"10AMTo12PM",@"12PMTo2PM",@"2PMTo4PM",@"4PMTo6PM"
Any one know what went wrong on the query variables?
任何人都知道查询变量出了什么问题?
2 个解决方案
#1
2
you have to use '
for string data to insert in query, same goes for all other queries.
您必须使用'用于在查询中插入字符串数据,对于所有其他查询也是如此。
mysql_query("INSERT INTO $tableName (Slot,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12)VALUES
('1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1')");
#2
0
Check the values of $slot1
if it is empty it will not insert it will show error.
检查$ slot1的值,如果它是空的,它将不会插入它将显示错误。
Better put '$slot1'
, single quotes and try
最好把'$ slot1',单引号和尝试
mysql_query("INSERT INTO $tableName (Slot,B1, B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12)
VALUES ('2','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."')");
#1
2
you have to use '
for string data to insert in query, same goes for all other queries.
您必须使用'用于在查询中插入字符串数据,对于所有其他查询也是如此。
mysql_query("INSERT INTO $tableName (Slot,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12)VALUES
('1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1','$slot1')");
#2
0
Check the values of $slot1
if it is empty it will not insert it will show error.
检查$ slot1的值,如果它是空的,它将不会插入它将显示错误。
Better put '$slot1'
, single quotes and try
最好把'$ slot1',单引号和尝试
mysql_query("INSERT INTO $tableName (Slot,B1, B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12)
VALUES ('2','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."','".$slot2."')");