이 작업을 수행하기 위해 열심히 노력하고 있으며 잘못된 것을 알지 못합니다. 나는 데이터를 폼에 삽입하고 jQuery와 AJAX를 사용하여 데이터베이스에 INSERT하는 등록 페이지를 가지고있다. 나는 AJAX와 jQuery에 익숙하지 않으므로 온화합니다. : PI 내가 addMembers.jsphp, ajax 및 jQuery를 사용하여 데이터베이스에 값 삽입
을 포함sign_up.php ... 당신에게 (나는 모든 페이지에 포함) 내 header.php에서
<?php
include 'connect.php';
include 'header.php';
echo '<h2>Register</h2>';
if($_SERVER['REQUEST_METHOD'] != 'POST')
{
echo '<br/>';
echo '
<div class="container">
<form id="submit" method="post" action="">
<fieldset>
<legend> Enter Information </legend>
<br/>
<label for="user_name">Your username: </label>
<br/>
<input id="user_name" class="text" name="user_name" size="20" type="text">
<br/>
<br/>
<label for="user_pass">Your password: </label>
<br/>
<input id="user_pass" class="text" name="user_pass" size="20" type="password">
<br/>
<br/>
<label for="user_pass_check">Confirm password: </label>
<br/>
<input id="user_pass_check" class="text" name="user_pass_check" size="20" type="password">
<br/>
<br/>
<label for="user_email">Email: </label>
<br/>
<input id="user_email" class="text" name="user_email" size="20" type="email">
<br/>
<br/>
<button class="button positive" type="submit"> <img src="like.png" alt=""> Register </button>
</fieldset>
</form>
<div class="success" style="display: none;"> You are now a registered user!</div>
</div>';
}
else {
$errors = array();
//Checks the errors
if(isset($_POST['user_name']) == NULL)
{
//if the user name is larger than 30 characters
$errors[] = 'Please enter your username.';
}
//Checks the password
if(isset($_POST['user_pass']) == NULL)
{
$errors[] = 'Please enter your password.';
}
else
{
if($_POST['user_pass'] != $_POST['user_pass_check'])
{
$errors[] = 'The two passwords did not match.';
}
}
if(!empty($errors)) //Checks for empty fields
{
echo 'Please check that all the fields are filled in.<br /><br />';
echo '<ul>';
foreach($errors as $key => $value) //walk through the array so all the errors get displayed
{
echo '<li>' . $value . '</li>'; //this generates a list with errors
}
echo '</ul>';
}
}
?>
을 내가 가지고있는 파일을 보여줍니다
$(document).ready(function(){
$("form#submit").submit(function() {
// we want to store the values from the form input box, then send via ajax below
var user_name = $('#user_name').val();
var user_email = $('#user_email').val();
var user_pass= $('#user_pass').val();
//$user_name = $('#user_name').val();
//$user_email = $('#user_email').val();
//$password = $('#password').val();
alert(user_name);
$.ajax({
type: "POST",
url: "ajax.php",
data: "user_name="+ user_name +"&user_email="+ user_email +"$user_pass=" + user_pass,
success: function(){
$('form#submit').hide(function(){$('div.success').fadeIn();});
}
});
//alert("ji");
return false;
});
});
그리고 내 ajax.php는 데이터를 가져 와서 데이터베이스에 삽입해야하지만 그렇지 않습니다. ! :(
<?php
include 'connect.php';
include 'header.php';
// CLIENT INFORMATION
$user_name = $_POST['user_name'];
$user_email = $_POST['user_email'];
$user_pass = $_POST['user_pass'];
mysql_query("INSERT INTO
users(`user_name`, `user_pass`, `user_email` , `user_date` , `user_level`)
VALUES('$user_name', '$user_pass', '$user_email', NOW() , 0)" OR trigger_error(mysql_error()));
?>
도와주세요 ...
덕분에 많은
조
? 또한 필드 값을 얻으려면'$ ('# user_name') .val();'을 사용하십시오. 그리고 당신의 삽입은 어디 있습니까? –
data : "user_name ="+ user_name + "& user_email ="+ user_email + "& password ="+ password, user_email 앞에 표시가 없습니다. –
sidenote :이'if (! ctype_alnum ($ _ POST [ 'user_name'])) { $ errors [] = '그 사용자 이름은 이미 취해졌습니다.';}'오해의 소지가 있습니다. 반드시 –