PHP脚本返回"undefined"(未定义)提交时 [英] PHP script returning "undefined" on submit
问题描述
我正在构建一个小型应用程序,该应用程序基本上是用HTML和jQuery mobile构建的表单,已经将其部署到了Web上以及应用程序的iOS版本中,它的工作原理很吸引人.但是现在,当尝试在应用程序的android版本上进行部署时,提交时我只是在屏幕上看到"undefined",没有"undefined variable"或其他任何东西,而仅仅是"undefined".
I'm building a small app, which is basicly a form built in HTML and jQuery mobile, I've deployed it to the web, and to my iOS-version of the app, and it works like a charm. But now when trying to deploy on the android-version of the app, I just get "undefined" on the screen when submiting, no "undefined variable" or anything else, just "undefined".
有人对此问题有某种解决方案吗?我正在使用PhoneGap部署HTML/CSS/JQuery
Do anyone have some form of solution to this problem? I'm using PhoneGap to deploy HTML/CSS/JQuery
我非常感谢您提供的任何帮助.
I'm very grateful for any help given.
我在这里发布代码:
<?php
$con = mysql_connect("db-ip","username","password");
if (!$con)
{
die('errormessage: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$myusername=$_POST['username'];
$myusername = stripslashes($myusername);
$myusername = mysql_real_escape_string($myusername);
$sql2="SELECT * FROM users WHERE username='$myusername'";
$result=mysql_query($sql2);
$count=mysql_num_rows($result);
if (empty($myusername))
{
header('Location:error2.html');
exit;
}
if($count==1)
{
$sql="INSERT INTO testresult(slider1, slider2, slider3, slider4, time, user) VALUES('$_POST[slider1]', '$_POST[slider2]', '$_POST[slider3]', '$_POST[slider4]', NOW(),'$myusername')";
}
else
{
header('Location:error.html');
exit;
}
if (!mysql_query($sql,$con))
{
die('errormessage:' . mysql_error());
}
header('Location:done.html');
exit;
mysql_close($con);
?>
推荐答案
如果错误只是undefined
,则不能由PHP引起.在JavaScript中,undefined
表示未定义您要使用的变量.
If the error is just undefined
, it can't be caused by PHP. In JavaScript, undefined
means that the variable which you are trying to use isn't defined.
另一个观察结果是mysql_函数.您应该考虑改用PDO.
Another observation was mysql_ functions. You should consider using PDO instead.
从php.net:
不鼓励使用此扩展名.相反,应使用MySQLi或PDO_MySQL扩展.另请参见MySQL:选择API指南和相关的FAQ,以获取更多信息.此功能的替代方法包括:
Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
这是关于以mysql_开头的函数的.
And this was about functions starting with mysql_.
这篇关于PHP脚本返回"undefined"(未定义)提交时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!