[英]Passing space in parameters to php file
I have a table name "User" writen in MySQL with the fields: UserID, UserName, Password, eMail, DisplayName, Score, timeStamp. 我在MySQL中写了一个表名“ User”,其中包含以下字段:UserID,UserName,Password,电子邮件,DisplayName,Score,timeStamp。 The field UserID is int AUTO_INCREMENT and time stamp is dateTime.
字段UserID为int AUTO_INCREMENT,时间戳为dateTime。 I'm trying to insert values into the table using php file.
我正在尝试使用php文件将值插入表中。 This is my php file:
这是我的php文件:
mysql_connect("mysql.1freehosting.com","u948577195_uname","p7CraCuRAw");
mysql_select_db("u948577195_dbnam");
$uName = $_GET['uname'];
$pass = $_GET['password'];
$mail = $_GET['email'];
$disName = $_GET['disnam'];
$date = $_GET['dt'];
$sql=mysql_query("INSERT INTO User
VALUES ('$uName', '$pass', '$mail', '$disName', 0, '$date')");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>
I activate the file using this connection string: 我使用以下连接字符串激活文件:
http://pickupfriend.fulba.com/android_project/query3.php?uname=Test&password=p1&email=ml&disnam=Test&dt=21:12:30 2014-07-07
I have a space between the seconds and the year in the date, is it OK? 我在日期的秒数和年份之间有一个空格,可以吗? After I run the connection string I receive this error:
运行连接字符串后,我收到此错误:
Parse error: syntax error, unexpected T_STRING in /home/u948577195/public_html/android_project/query3.php on line 13
What am I doing wrong? 我究竟做错了什么? How to correct my connection string?
如何更正我的连接字符串? Thank you in advance!
先感谢您!
And what do you expect to happen? 您期望发生什么?
INSERT INTO [USER]
VALUES ('$uName', '$pass', '$mail', '$disName', 0, '$date')
That is NOT php! 那不是PHP! You forgot to use it in a query or something.
您忘记了在查询或其他内容中使用它。
Your link shows that you are getting the parameters wrong in the $_GET
part. 您的链接显示
$_GET
部分中的参数错误。
Hence you must delete this line as it's not php 因此,您必须删除此行,因为它不是php
INSERT INTO [USER]
VALUES ('$uName', '$pass', '$mail', '$disName', 0, '$date')
Change your code as as below. 如下更改代码。
mysql_connect("mysql.1freehosting.com","u948577195_uname","p7CraCuRAw");
mysql_select_db("u948577195_dbnam");
$uName = $_GET['uname'];
$pass = $_GET['pass'];
$mail = $_GET['mail'];
$disName = $_GET['disName'];
$date = $_GET['date'];
$sql = mysql_query("INSERT INTO User VALUES ('$uName', '$pass', '$mail', '$disName', 0, '$date')");
if (!$sql) {
$message = 'Invalid query: ' . mysql_error() . "\n";
die($message);
}
mysql_close();
And your are not fetching anything within your query, if your aim is to see all add this before mysql_close()
而且,如果您的目的是要在
mysql_close()
之前添加所有内容,则您不会在查询中获取任何内容
$query = mysql_query('SELECT * FROM User');
if (!$query) {
$message = 'Invalid query: ' . mysql_error() . "\n";
die($message);
}
$output = array();
while ($row = mysql_fetch_assoc($query) !== false) {
$output[] = $row;
}
echo json_encode($output);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.