upon data retrieval, form populates and then clears - javascript

I have a weird problem. I have a form that populates with a button click event. This all works fine, except that once the form populates, it clears itself. Even Firebug gets cleared. I have stripped everything down to its most basic level, and cannot figure out what the issue is.
HTML:
<?php
require_once('../hyperlink.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Shipment Assignment</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<link rel="stylesheet" href="book.css">
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
<link rel="stylesheet" href="../css/tabletheme/style.css" type="text/css" id="" media="print, projection, screen" />
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.js"></script>
<script type="text/javascript" src="../barcode/jquery-barcode.js"></script>
<script type="text/javascript" src="../js/tablesorter.min.js"></script>
<script src="book.js"></script>
</head>
<body>
<div id="header">
<?php display_user_hyperlinks(); ?>
<?php include ('../version.php'); ?> | Tip: Shipping Info</p>
</div>
<form>
<fieldset>
<legend>Shipping Assignments</legend>
Enter the PO that you would like to review: <input id="po"/><input type="submit" id="getPo" value="Retrieve"/>
</fieldset></form>
<form id="result">
<div id="hide">
<div id="cl" class="width border">
CL<input id="cl"/>
</div>
<div id="recv" class="width border">
REC<input id="rec"/>
</div>
<div id="pricePd" class="width border">
<input id="price" placeholder="Price Paid"/>
</div>
<div id="box" class="border">
<input id="title" style="width: 445px;" placeholder="Title"/><br>
<input id="isbn10" style="width: 445px;" placeholder="ISBN10"/><br>
<input id="isbn13" style="width: 445px;" placeholder="ISBN13"/><br>
</div>
</div></form>
<div id="remain"class="border">
Qty Rem: <input type="text" id="qtyRem"/>
</div>
</body>
</html>
book.js
$(document).ready(function() {
$("#getPo").click(function() {
$.ajax ({
type: "POST",
url: "poInfo.php",
async:false,
dataType: "json",
data: ({po: $('#po').val()}),
success: function(data){
console.log(data);
$("#isbn13").val(data.isbn);
$("#isbn10").val(data.isbn10);
$("#title").val(data.title);
}
}); //END OF AJAX
}); // END OF GETPO FUNCTION
});
poInfo.php:
<?php
ini_set('display_errors',"1");
require_once ('../db.php');
$conn = db_connect();
$i=0;
$po = 'JJD090969';
$result = $conn->query("select * from ship_assign where po = '$po'");
while ($row = $result->fetch_assoc()) {
$isbn10 = $row['isbn10'];
$isbn = $row['isbn13'];
$azLow = $row['azLow'];
$buyback101 = $row['Buyback101'];
$textRecycle = $row['textBookRecycle'];
$textRush = $row['textBookRush'];
$bookStores = $row['bookStores'];
$textBooks = $row['textBooks'];
$bookJingle = $row['bookJingle'];
$cash4Books = $row['cash4Books'];
$bookbyte = $row['bookbyte'];
$sellBack = $row['sellBack'];
$cheggBs = $row['chegg'];
$valore = $row['valore'];
$powell = $row['powell'];
$amzBuyBack = $row['amazonBuyBack'];
$collegeBooksDir = $row['collegeBooksDirect'];
$result2 = $conn->query("select title from book where isbn13 = '$isbn'");
$row1 = $result2->fetch_assoc();
$title = $row1['title'];
} //END OF WHILE STATEMENT
$guides= array('isbn10'=>$isbn10,'isbn'=>$isbn,'title'=>$title);
$conn->close();
echo json_encode($guides);
?>
Everything works as it should, except that the form clears once populated. I am hard coding in the po that I want to use instead of having to type it in every time, but the result is the same either way. Any ideas on how to fix this??

Try this:
$(document).ready(function() {
$("#getPo").click(function(event) {
event.preventDefault();
$.ajax ({
type: "POST",
url: "poInfo.php",
// async:false, deprecated
dataType: "json",
data: ({po: $('#po').val()}),
success: function(data){
console.log(data);
$("#isbn13").val(data.isbn);
$("#isbn10").val(data.isbn10);
$("#title").val(data.title);
}
}); //END OF AJAX
}); // END OF GETPO FUNCTION
});

Related

Getting an ajax request to update a column in a SQL Table

I am trying to get the current code to take the on or off value from the form and put it into an SQL database using a function call to a JS function that contains an AJAX request that then posts it to a PHP page that runs the actual query. I am not sure what I have done wrong and the API has been more confusing than helpful. I appreciate any help!
Current Page Code:
<?php require('../php/validation.php');?>
<?php require('../php/background.php');?>
<?php
if(isset($_POST['selectonoff'])){
$_SESSION['onoff'] = $_POST['selectonoff'];
$query = 'UPDATE onoff SET onoroff = $_POST["selectonoff"] WHERE ID = 1;';
$update = mysqli_query($db, $query);
}
?>
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>User Settings Dropdown Menu</title>
<link rel="stylesheet" href="../css/settings.css">
<script type="text/javascript">
function load() {
document.getElementById("selectonoff").value = '<?php echo $_SESSION['onoff'];?>';
}
</script>
<script src="jquery.js"></script>
<script>
function rel(id)
{
jQuery.ajax({
type: "POST",
data: 'id='+id,
url: "../php/update.php",
cache: false,
success: function(response)
{
alert("Record successfully updated");
}
});
}
</script>
</head>
<body onload="load();">
<!-- <div id="wrap"> -->
<br><br><br><br>
<h1>Admin Settings Menu</h1>
<form method="post" action="adminconfig.php">
<p>Toggle BBQ Form</p>
<select id="selectonoff" name="selectonoff" onchange="this.form.submit(); rel();">
<option value="NONE">Select</option>
<option value="ON">Toggle ON</option>
<option value="OFF">Toggle OFF</option>
</select>
</form>
<form action="../index.php">
<input type="submit" value="Home" />
</form>
<script type="text/javascript">
</script>
</body>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="../js/index.js"></script>
</html>
Current PHP Code:
<?php
require ('php/server.php');
$db = mysqli_connect('localhost', 'root', '', 'dedricks');
if(!$db){
die("Connection Failed: ".mysqli_connect_error());
}
$var = #$_POST['id'] ;
$query = 'UPDATE onoff SET onoroff = $var WHERE ID = 1;';
mysqli_query($db, $query);
?>
Few corrections needed here.
ERRORS
You are not reading the value of the select control anywhere in your code that needs to be sent in the ajax call
onchange for the selectonoff list is trying to submit the form and at the same time calling rel function (without any parameter). It seems like it needs to trigger the ajax call when the selectonoff selection is changed.
The jquery needs to be added once either via cdn or from local directory
It needs to be added before the script tag in the head.
TODO
Remove this.form.submit(); and rel from onchange. Rather remove the entire onchange
A code based on your page that is working and submitting the data to the php page is as below. You can make the changes according to your needs.
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>User Settings Dropdown Menu</title>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script type="text/javascript">
function rel(id){
var formData = {"id": id};
$.ajax({
type: "POST",
data: formData,
url: "../app/update.php",
cache: false,
success: function(response){
console.log("response", response);
alert("Record successfully updated");
},
error: function(error){
console.log("error", error);
}
});
}
$(document).ready(function(){
$("#selectonoff").change(function(){
var val = $("#selectonoff option:selected").val();
rel(val);
});
});
</script>
</head>
<body>
<!-- <div id="wrap"> -->
<br><br><br><br>
<h1>Admin Settings Menu</h1>
<form method="post" action="adminconfig.php">
<p>Toggle BBQ Form</p>
<select id="selectonoff" name="selectonoff">
<option value="NONE">Select</option>
<option value="ON">Toggle ON</option>
<option value="OFF">Toggle OFF</option>
</select>
</form>
<form action="../index.php">
<input type="submit" value="Home" />
</form>
</body>
</html>
NOTE
I have now tested the above code to be working and submitting the ajax request to a php script.

Search in PHP did not work [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm not really good in PHP and AJAX I need your help guys for this. A cannot get a simple search using PHP and AJAX here's my code guys. The load_data function in AJAX was functioning but I'm not sure if it calls the .php function in my files but the files are not separated.
Here's my HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TESTING</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<br />
<h2 align="center">TESTING</h2>
<br />
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Search</span>
<input type="text" name="search_text" id="search_text" placeholder="Search" class="form-control" />
</div>
</div>
<br />
<div id="result"></div>
</div>
</body>
</html>
And here's my AJAX script
<script>
$(document).ready(function() {
load_data();
function load_data(query) {
//alert('testing');
$.ajax({
url: "functions.php",
method: "POST",
data: {
query: query
},
success: function(data) {
$('#result').html(data);
}
});
// alert(query);
}
$('#search_text').keyup(function() {
var search = $(this).val();
//alert(search);
if (search != '') {
load_data(search);
} else {
load_data();
}
});
});
</script>
And here's my PHP
<?php
//fetch.php
$connect = mysqli_connect("localhost", "root", "", "erpts_system");
$output = '';
if (isset($_POST["query"])) {
$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "
SELECT * FROM users
WHERE firstname LIKE '%".$search."%'
OR middlename LIKE '%".$search."%'
OR lastname LIKE '%".$search."%'
OR email LIKE '%".$search."%'
OR username LIKE '%".$search."%'
";
} else {
$query = "
SELECT * FROM users ";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>Customer Name</th>
<th>Address</th>
<th>City</th>
<th>Postal Code</th>
<th>Country</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["firstname"].'</td>
<td>'.$row["middlename"].'</td>
<td>'.$row["lastname"].'</td>
<td>'.$row["email"].'</td>
<td>'.$row["username"].'</td>
</tr>
';
}
echo $output;
} else {
echo 'Data Not Found';
}
?>
I copied the code and launched it on my local machine, its working just perfectly. I think your problem comes from linking your js file. I haven't seen a script tag linking your js file. If you don't intend to use an external script i would suggest you insert your javascript code at the end of your document like this
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TESTING</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<br />
<h2 align="center">TESTING</h2>
<br />
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Search</span>
<input type="text" name="search_text" id="search_text" placeholder="Search" class="form-control" />
</div>
</div>
<br />
<div id="result"></div>
</div>
<script>
$(document).ready(function() {
//load_data();
function load_data(query) {
//alert('testing');
$.ajax({
url: "functions.php",
method: "POST",
data: {
query: query
},
success: function(data) {
$('#result').html(data);
}
});
// alert(query);
}
$('#search_text').keyup(function() {
var search = $(this).val();
//alert(search);
if (search != '') {
load_data(search);
} else {
load_data();
}
});
});
</script>
</body>
Please note how i commented the load function you called just before the function declaration. Ensure that the php file is in the same directory with the php file containing this code. All the best
Take a look at my setup...similar to yours...
$.ajax({
url:'checkin_ajax.php',
type:'POST',
data:'id=' + id + '&address=' + address2 + '&latitude=' + latitude2 + '&longitude=' + longitude2 + '&business=' + businessname2,
success: function(msg){
if($.trim(msg) == "failed"){
alert('You must be logged in');
}
else {
alert('Check in successful');
/*
var datad = $(msg).text();
console.log(datad);
var resultstring = datad.replace(',]',']');
var JsonParseData = JSON.parse(resultstring);
*/
}
}//ends success code
});//ends ajax

jquery form validation and php script in one page

after implementing a jquery form validation and redirecting with function btn_onclick()
{ window.location.href = "http://localhost/loginprivate.php";} from index.php to loginprivate.php my webapps php script wont be executed. The user become trough a javascript function and window.location.href from index.php redirected loginprivate.php you can see here. After the first pageload the page become loaded again with <script src="loadagain.js"></script> this works fine too.
Now the problem is that if I click the submit button the php code wont become executed, that can I see because no cookies become created, and the user become redirected to index.php.
my php code:
if(isset($_POST["submit"]))
{
$hostname='localhost';
$username='root';
$password='';
unset($_POST['password']);
$salt = '';
for ($i = 0; $i < 22; $i++) {
$salt .= substr('./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', mt_rand(0, 63), 1);
}
$_POST['password'] = crypt($_POST['password'],'$2a$10$'.$salt);
$new = 0;
try {
$dbh = new PDO("mysql:host=$hostname;dbname=search",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql = "INSERT INTO users (username, password)
VALUES ('".$_POST["username"]."','".$_POST["password"]."')";
if ($dbh->query($sql)) {
echo "New Record Inserted Successfully";
}
else{
echo "Data not successfully Inserted.";
}
$new = $dbh->lastInsertId();
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
if ($new > 0)
{
$t = time() + 60 * 60 * 24 * 1000;
setcookie("username", $_POST['username'], $t);
setcookie("userid", $new , $t);
}
else
{
}
}
my html code:
<head>
<meta charset="UTF-8" />
<title>
HTML Document Structure
</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" href="themes/my-costum-theme.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js"></script>
<!-- Einstellungen zur Defintion als WebApp -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script src="loadagain.js"></script>
<script>
$(document).ready(function () {
$('#myform').ajaxForm();
$('#myform').validate({ // initialize the plugin
rules: {
username: {
required: true,
minlength: 2,
maxlength: 30
},
password: {
required: true,
minlength: 3,
maxlength: 30
}
},
submitHandler: function (form) { // for demo
$.ajax({
type: 'post',
url: 'loginprivate.php' //url where you want to post the stuff.
data:{
username: 'root',
password: 'maxicora123'
},
success: function(res){
//here you will get res as response from php page, either logged in or some error.
window.location.href = "http://localhost/loc/main.php";
}
});
return false; // for demo
}
});
});
</script>
</head>
<body>
<div class="ui-page" data-theme="b" data-role="page">
<div data-role="header"><h1>localcorps</h1></div>
<div id="wrapper1" style=" width: 90%; padding-right:5%; padding-left:5%" name="wrapper1">
<form name="login-form" id="myform" class="login-form" action="./loginprivate.php" method="post">
<div class="header1"></div>
<div class="content1">
<div data-role="fieldcontain">
<label for="username">Username:</label>
<input name="username" type="text" class="input username" id="username"/>
</div>
</div>
<div data-role="fieldcontain">
<label for="password">Password:</label>
<input name="password" type="password" class="input password" id="password"/>
</div>
<div class="footer">
<input type="submit" name="submit" value="Login" class="button"/>
</div>
</form>
</div>
</div>
</div>
</body>
According to your comment, I get now only this "Array ( )" on my screen. it means that you ain't posting anything to PHP page.
That's just because, you're redirecting the control to PHP page instead of submitting the form.
so, you can validate the code using jQuery and on successful validation do a ajax post request instead of shifting the control.window.location.href = "http://localhost/lak/main.php";
instead of shifting control, do a post.
$.ajax({
type: 'post',
url: 'loginprivate.php' //url where you want to post the stuff.
data:{
username: 'someUserName',
password: 'xxxxxxxxxxxx'
},
success: function(res){
//here you will get res as response from php page, either logged in or some error.
//and if you're logged in successfully, redirect here now.
}
});
Hope this will help.

get JSON from PHP with JQUERY

I have a html form in my index.php
I have my connection.php who receive the login and the password... check it into the database... and return true if the user is auth or false if not..
I return this into a json format with json_encode(array('result' => 1));
but when I try to display the result with my jquery, I have a blank page.
index.html
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<title>Ticket v1.0 Administration</title>
<meta name="description" content="Système de ticket par Sami Jnih" />
<meta name="keywords" content="ticket" />
<meta name="author" content="Sami Jnih" />
<!-- <link rel="shortcut icon" href="../favicon.ico"> -->
<link rel="stylesheet" type="text/css" href="skins/css/form.css" />
<link href="http://fonts.googleapis.com/css?family=PT+Sans+Narrow" rel="stylesheet" type="text/css" />
</head>
<body id="index">
<div class="container">
<section class="main_login">
<form id="connection" class="form_login" name="form1" action="connection.php" method="POST">
<h1><span class="log-in">Connexion</span> ou <span class="sign-up">inscription</span></h1>
<p class="float">
<label for="login"><i class="icon-user"></i>Login</label>
<input type="text" id="login" name="login" placeholder="Login" required="required" />
</p>
<p class="float">
<label for="password"><i class="icon-lock"></i>Mot de passe</label>
<input type="password" id="password" name="password" placeholder="Password" class="showpassword" required="required" />
</p>
<p class="clearfix">
Inscription
<input id="submit" type="submit" value="Connexion"/>
</p>
<br />
<p id="auth"></p>
</form>​​
</section>
</div>
<footer>
<script src="js/modernizr.custom.63321.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="js/admin.login.js"></script>
<script type="text/javascript" src="js/login.js"></script>
</footer>
</body>
</html>
jquery file:
$("#connection").submit(function(event){
event.preventDefault();
$.ajax({
type: "POST",
dataType: "json",
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(json){
if (json.auth === 1)
{
$("#auth").css({
fontSize: '15px',
color: 'green'
}).text('Connexion réussi, redirection en cours..').show().fadeOut(3000);
window.location.replace("http://sami.fr/admin/contents/home/index.php");
}
else
{
$("#auth").css({
fontSize: '15px',
color: 'red'
}).text('Erreur, identifiants incorrects!').show().fadeOut(6000);
}
},
error: function(jqXHR, error){
$("#auth").text('Erreur : ');
$("#auth").after('<p>' + jqXHR.responseText + '</p>');
$("#auth").after('<p>' + error + '</p>');
}
});
});
connection.php
$rootPath = '';
require_once ($rootPath . 'application.php');
session_id(generateID($_REQUEST));
session($_REQUEST['login']);
if ( $user = authUserAccess($_REQUEST) )
{
if ( !fetchSession(session_id()) && !checkSession(session_id()) )
addSession($user, session_id());
else
updateSession($user, session_id());
$result = array('auth' => 1);
echo json_encode($result);
}
else
{
closeSession();
$result = array('auth' => 0);
echo json_encode($result);
}
Now All is working!
Thanks!
Do not use return in your php file, you need to actually output the data, via echo (with the correct header):
if ( $user = authUserAccess($_REQUEST) )
{
if ( !fetchSession(session_id()) && !checkSession(session_id()) )
addSession($user, session_id());
else
updateSession($user, session_id());
$result = json_encode(array('return' => 1));
header('Content-Type: application/json');
echo $result;
// header('Location: ' . $adminContentPath . 'home/index.php?sid=' . session_id());
}
else
{
closeSession();
header('Content-Type: application/json');
echo json_encode(array('return' => 0));
}
Also, as noted by pmandell, your callback has inconsistent names for the returned data
Lastly, you must stop the form from submitting normally else the user will get redirected:
$('#connection').submit(function(ev){
ev.preventDefault();
$.ajax({ ...
In your code:
success: function(json){
alert(data);
if ( data == 0 )
$("#resultat").html("<p>Vous êtes connecté.</p>");
else
$("#resultat").html("<p>Erreur, login ou mot de passe incorrect.</p>");
}
You are attempting to reference data which is not defined.
data is frequently what jQuery developers name the .ajax() success parameter. You can name it whatever you want. You could change your code to:
success: function(data) {
...
}
Also, the parameter of the success callback will be the JSON that the AJAX request responds with. In this case, it is an object with one attribute, response. You will need to check the value of response with:
if ( data.response === 0 ) {
$("#resultat").html("<p>Vous êtes connecté.</p>");
...
}

ajax code200 error can't connect to the url

I am using ajax to run a test id, but it does not work with code: 200 error.
And since ajax is not returning a value, it keeps getting error and prints "failed"
The id of add_user.html is checked in real time through the ajax of id_check.js.
However, memid_check.php, which sends data from id_check.js, does not seem to run.
to confirm
memid_check.php
echo "<script> alert('test!!!'); </script>";
.....
But did not run.
All files are in one folder, so the path seems to be fine
id_check.js
$(function(){
var id = $('.id_tbox');
var pwd =$('.pwd_tbox');
var name =$('.name_tbox');
var email =$('.email_tbox');
var idCheck = $('.idCheck');
$(".memcheck_button").click(function(){
console.log(id.val());
$.ajax({
type: 'post',
dataType: 'json',
url: "memid_check.php",
data:{id:id.val()},
success: function(json){
if(json.res == 'good'){
console.log(json.res);
alert("사용가능한 아이디");
idCheck.val('1');
}
else{
alert("다른 아이디 입력");
id.focus();
}
},
error:function(request,status,error){
alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
console.log("failed");
}
});
});
});
memid_check.php
<?php
echo "<script> alert('test!!!'); </script>";
include "db_c.php";
$id = $_POST['id'];
$sql = "SELECT * FROM add_user WHERE id = '{$id}'";
$res = $database -> query($sql);
if( res->num_rows >= 1){
echo json_encode(array('res'=>'bad'));
}
else{
echo json_encode(array('res'=>'good'));
}
?>
add_user.html
<?php
include "database.php";
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, target-densitydpi=medium-dpi">
<link rel="stylesheet" href="add_user_style.css">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="js/default.js"></script>
<link href="https://fonts.googleapis.com/css?family=Nothing+You+Could+Do&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Cinzel|Permanent+Marker|Rajdhani&display=swap" rel="stylesheet">
<script type="text/javascript" src="id_check.js"></script>
</head>
<body>
<div class="aus_portrait"></div>
<div class ="aus_form" align ="center">
<div class="aus_box">Sign Up</div>
<form action="loginP.php" method="post">
<p class = "id">ID</p><input type="text" name="id" class="id_tbox">
<p class = "pwd">PASSWORD</p><input type="text" name="pwd" class="pwd_tbox">
<p class = "name">MAIL</p><input type="text" name="email" class="email_tbox">
<p class = "email">NAME</p><input type="text" name="name" class="name_tbox">
<input type="submit" class="sub_button" value="Submit">
<input type="button" class="exit_button" value="Cancel">
<input type="hidden" name="idCheck" class="idCheck">
<div class="memcheck_button">중복확인</div>
</form>
</div>
</body>
</html>
<script>
$(document).ready(function() { $(".exit_button").on("click", function(){ location.href="login.html"});}); </script>

Categories