2012-10-08 3 views
-1

나는 악몽을 꾼다. 그리고 html과 php를 수정하여 mysql에 등록 양식에 대한 정보를 삽입하려고한다. 아래는 html 양식과 PHP 제출 페이지입니다. 필자는 데이터베이스에 대한 SQL 연결을 시작했고 추가 기능을위한 몇 가지 변수를 설정했습니다. 어떤 도움이 될 것 팹 :-)PHP mysql signup 양식

<?php 

$dbcnx = @mysql_connect('localhost', 'user', 'pass'); 
     if (!$dbcnx) { 
       exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); 
     } 
     if ([email protected]_select_db('signp',$dbcnx)) { 
       exit('<p>Unable to locate the file ' . 'database at this time.</p>'); 
     } 



if ($action == "add") { 
/* ****************************** Do this if we are adding a new record */ 
     $query = "INSERT INTO connect VALUES()"; 

     $result = mysql_query($query);   
     if(!$result){ 
       die ("could not query database: <br />".mysql_error()); 
     }  
     $d_id = $inserted_id = mysql_insert_id(); 
     $dname = ""; 
     $demail = ""; 
     $dpassword = ""; 
} 

// Error reporting: 
error_reporting(E_ALL^E_NOTICE); 

// This is the URL your users are redirected, 
// when registered succesfully: 

$redirectURL = 'http://ip/index.html'; 

$errors = array(); 

// Checking the input data and adding potential errors to the $errors array: 

if(!$_POST['name'] || strlen($_POST['name'])<3 || strlen($_POST['name'])>50) 
{ 
     $errors['name']='Please fill in a valid name!<br />Must be between 3 and 50 characters.'; 
} 

if(!$_POST['email'] || !preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $_POST['email'])) 
{ 
     $errors['email']='Please fill in a valid email!'; 
} 

if(!$_POST['pass'] || strlen($_POST['pass'])<5) 
{ 
     $errors['pass']='Please fill in a valid password!<br />Must be at least 5 characters long.'; 
} 
// Checking whether the request was sent via AJAX 
// (we manually send the fromAjax var with the AJAX request): 

if($_POST['fromAjax']) 
{ 
     if(count($errors)) 
     { 
       $errString = array(); 
       foreach($errors as $k=>$v) 
       { 
         // The name of the field that caused the error, and the 
         // error text are grouped as key/value pair for the JSON response: 
         $errString[]='"'.$k.'":"'.$v.'"'; 
       } 

       // JSON error response: 
       die  ('{"status":0,'.join(',',$errString).'}'); 
     } 

     // JSON success response. Returns the redirect URL: 
     echo '{"status":1,"redirectURL":"'.$redirectURL.'"}'; 

     exit; 
} 

// If the request was not sent via AJAX (probably JavaScript 
// has been disabled in the visitors' browser): 

if(count($errors)) 
{ 
     echo '<h2>'.join('<br /><br />',$errors).'</h2>'; 
     exit; 
} 



// Directly redirecting the visitor: 

header("Location: ".$redirectURL); 
?> 

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>sign up</title> 

<link rel="stylesheet" type="text/css" href="styles.css" /> 

</head> 

<body> 
<FORM ACTION="submit.php" METHOD=get> 
<div id="carbonForm"> 
     <h1>Signup</h1> 

    <form action="submit.php" method="post" id="signupForm"> 

    <div class="fieldContainer"> 

     <div class="formRow"> 
      <div class="label"> 
       <label for="name">Name:</label> 
      </div> 

      <div class="field"> 
       <input type="text" name="name" id="name" /> 
      </div> 
     </div> 

     <div class="formRow"> 
      <div class="label"> 
       <label for="email">Email:</label> 
      </div> 

      <div class="field"> 
       <input type="text" name="email" id="email" /> 
      </div> 
     </div> 

     <div class="formRow"> 
      <div class="label"> 
       <label for="pass">Password:</label> 
      </div> 

      <div class="field"> 
       <input type="password" name="pass" id="pass" /> 
      </div> 
     </div> 



    </div> <!-- Closing fieldContainer --> 
    <div class="signupButton"> 
     <input type="submit" name="submit" id="submit" value="Signup" /> 
    </div> 

    </form> 

</div> 


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript" src="script.js"></script> 

</body> 
</html> 
+4

실제 ** 문제 **가 무엇인가요? – didster

+1

실제로 테이블에 값을 삽입하지 않습니다. – RightHandedMonkey

+0

안녕하세요, HTML 및 PHP MySQL에 값을 삽입 점점 - 아직 꽤 작동하지 않습니다 – Grimlockz

답변

1

첫째, $action ISN '-

그 월요일과 나는 나 자신을 조금 잃었다 고 생각했습니다 정의되지 않았습니다.

두 번째로 $query = "INSERT INTO connect VALUES()";에는 소식 데이터가 삽입되지 않습니다.

셋째, mysql_ * 함수를 사용하면 안되며 php.net에서 사용하지 않는 것이 좋을 것입니다.

넷째, 각주의 더 많은 것으로 @을 사용하여 오류를 억제하지 마십시오.

관련 문제