1

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".

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.

I'm posting the code here:

<?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);


?>
2
  • 2
    FYI, you need to read about SQL injection and prepared statements to avoid it ASAP. And stripslashes is only necessary on horribly misconfigured servers - but it should never be used unconditionally. Commented Sep 15, 2012 at 11:04
  • ok, thank you for the tips, I will try to avoid that, and read up a bit on it. Commented Sep 15, 2012 at 11:16

1 Answer 1

4

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.

Another observation was mysql_ functions. You should consider using PDO instead.

From php.net:

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:

And this was about functions starting with mysql_.

Sign up to request clarification or add additional context in comments.

1 Comment

@SimonRöstin If the answer was correct, please, accept it as an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.