I am trying to build a web app so i want to pass values from a php file to an html file with jquery $.get
function.
Although $.get("url/file.php")
works fine,the internal function of $.get("url/file.php",function(data){ alert("test123");});
doesn't work.
I found a sample script from w3schools and it works fine, I tried to replace the sample's file with my own file (url/file.php
) and the internal function won't work, I also tried to replace my file with the sample file in my script and again the internal function won't work.
EDIT: Here is my code.What i am trying to do is to send username,password,email to the php file by clicking the signup button in order to register the user in the database and get back a string from the php file
The inde6.html file that contains the javascript is:
<html>
<head>
<title>Array Review</title>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<link href="css/index2.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<style type="text/css">
p {display:none}
input[type=text],input[type=password] {padding:5px; border:2px solid #ccc;
-webkit-border-radius: 5px;
border-radius: 5px;
}
input[type=text],input[type=password]:focus {border-color:#333; }
input[type=submit] {padding:5px 15px; background:#5A57B2; border:0 none;
cursor:pointer;
-webkit-border-radius: 5px;
border-radius: 5px; }
.stoixisi {
color:white;
}
#eikona {
background-image: url("owl.png");
background-repeat: no-repeat;
background-position: center top;
height:11.28%;
width:99%;
}
body {
height:470px;
width:330px;
background-image:url("bi2.png");
background-repeat:repeat;
}
#whole,#page1 {
height:100%;
width:100%;
}
#demo {
margin-left:6%;
margin-top:1%;
color:#FCE94D;
}
#demo1 {
margin-left:6%;
margin-top:0%;
color:#FCE94D;
}
#form1 {
margin-top:-2%;
height:42.55%;
width:75.76%;
}
#form2 {
margin-top:2%;
height:30%;
width:75.76%;
}
</style>
<script>
window.onload= function () {
document.getElementById("ii").style.height=window.innerHeight+"px";
document.getElementById("ii").style.width=window.innerWidth+"px";
document.getElementById("whole").style.height=window.innerHeight+"px";
document.getElementById("whole").style.width=window.innerWidth+"px";
};
$(document).ready(function(){
$("#signupp").click(function(){
var url="http://giannisgoulias.co.nf/Connect/welcome.php?"+"name="+$("#name").val()+"&password="+$("#password").val()+"&email="+$("#email").val();
$.get(url,function(data){alert('test');});
});
});
</script>
</head>
<body id="ii">
<div data-role="page" data-control-title="Home" id="page1">
<div id="whole">
<div id="eikona"></div>
<h2 id="demo1">Hi!Please Sign Up!</h2>
<p>
<form action="inde6.html" method="post" id="form1">
<div class="stoixisi">Username:</div> <input type="text" name="name" id="name"><br>
<div class="stoixisi">Password:</div> <input type="password" name="password" id="password"><br>
<div class="stoixisi">E-mail:</div> <input type="text" name="email" id="email"><br>
<input type="Submit" value="Sign Up" id="signupp">
</form>
<h2 id="demo1">Sign In!</h2>
<form action="signin.php" method="post" id="form2">
<div class="stoixisi">Username:</div> <input type="text" name="name"><br>
<div class="stoixisi">Password:</div> <input type="password" name="password"><br>
<input type="Submit" value="Sign In" onclick="signin()">
</div>
</form>
</p>
</body>
</html>
AND the php file is
<html>
<head></head>
<body>
<p>
<?php
$dbhost=****;
$dbuser=*****;
$dbpass=*****;
$db=*****;
$conn= mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($db);
mysql_query ("set character_set_results='utf8'");
$nname = mysql_real_escape_string($_GET["name"]);
$ppassword = mysql_real_escape_string($_GET["password"]);
$mmail=mysql_real_escape_string($_GET["email"]);
$query2="SELECT User_Name FROM table1 WHERE User_Name IN ('$nname')";
$query3="SELECT User_Mail FROM table1 WHERE User_Mail IN ('$mmail')";
$result2=mysql_query($query2);
$result3=mysql_query($query3);
$num_rows = mysql_num_rows($result2);
$num_rows2 = mysql_num_rows($result3);
$user_exists=0;
$mail_exists=0;
if ($num_rows>0 ) {
$user_exists=1;
}
if ($num_rows2>0) {
$mail_exists=1;
}
if ($user_exists==0 && $mail_exists==0)
{
$query1="INSERT INTO table1
(User_Name,User_Password,User_Mail) VALUES ('$nname','$ppassword','$mmail')";
$result1=mysql_query($query1);
$queryy="INSERT INTO table2
(UserName) VALUES ('$mmail')";
$resultt=mysql_query($queryy);
$queryyl="INSERT INTO NGames
(player,gnumber) VALUES ('$mmail',0)";
$resulttl=mysql_query($queryyl);
}
if ($user_exists==1 && $mail_exists==1) {
$out="Username and mail already exists!";
}
else if ($user_exists==1) {
$out= "This username already exists!";
}
else
{
if ($mail_exists==1) {
$out="This mail already exists!";
}
else {
$out="Sign in to play!";
};
}
echo $out;
?>
</p>
</body>
</html>