2014-07-20 1 views
0

ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1MySQL/SQL/PHP 구문 오류

양식 제출시 위의 오류가 발생합니다.

폼 (HTML) :

<form action="register.php" method="POST"> 
    <input type="text" name="username" maxlength="25" class="txtbx" placeholder="Username"><br> 
    <input type="password" name="password" maxlength="40" class="txtbx" placeholder="Password"><br> 
    <input type="password" name="confirm_password" maxlength="40" class="txtbx" placeholder="Confirm Password"><br> 
    <input type="text" name="email" maxlength="50" class="txtbx" placeholder="Email"><br> 
    <input type="text" name="confirm_email" maxlength="50" class="txtbx" placeholder="Confirm Email"><br> 
    <input type="submit"> 
</form> 

PHP의 :

$connect=mysqli_connect("[host (snip)]", "[username (snip)]", "[password (snip)", "[database name (snip)]"); 
if (mysqli_connect_errno()) 
{ 
    echo "<script>alert('Error connecting to MySQL:' . mysqli_connect_error())</script>"; 
} 
$username=mysqli_real_escape_string($connect, $_POST['username']); 
$password=mysqli_real_escape_string($connect, $_POST['password']); 
$password2=mysqli_real_escape_string($connect, $_POST['confirm_password']); 
$email=mysqli_real_escape_string($connect, $_POST['email']); 
$email2=mysqli_real_escape_string($connect, $_POST['confirm_email']); 
if($password!=$password2) 
{ 
    echo "<script>alert('The password and the password confirmation do not match.');</script>"; 
} 
if($email!=$email2) 
{ 
    echo "<script>alert('The email and the email confirmation do not match.');</script>"; 
} 
if($username && $password == $password2 && $email == $email2) 
{ 
    $addto=mysqli_query($connect,"INSERT INTO users (username, password, email) 
    VALUES ('$username', '$password', '$email')"); 
    if (!mysqli_query($connect,$addto)) 
    { 
    die('ERROR: ' . mysqli_error($connect)); 
    } 
    else 
    { 
    echo "Successful!"; 
    } 
} 
mysqli_close($connect); 

나는이 오류를 이해하지 않습니다. PHP 코드의 첫 번째 줄에는 문자 '1'이 없습니다. mysqli 대신 mysql이되어야하나요? 코멘트에서 언급 한 바와 같이

감사합니다, ~ 동음

+1

이 줄은'이해가되지 않는 경우 ($ 사용자 이름 && $ 암호 == $ 암호 2 && $ 이메일 == $ EMAIL2)' –

+0

게다가, 당신은 두 번'mysqli_query' 사용하고는.'변경하는 경우 (! mysqli_query ($ 연결, $의 addto) (! $의 addto) 프레드-II-라인 @' –

+0

당신이 아무튼 말한다면'에)' 'T는 말이 아마과 같이 기록 할 것으로 예상되는합니다 '경우 ($ 사용자 이름 && ($ 암호 == $ 암호 2) && ($ 이메일 == $ EMAIL2)) $ 사용자 이름은 제로에 대한 확인되고있다',/0이 아닌 값 –

답변

1

, 당신은 if ($addto === false)에 코드 if (!mysqli_query($connect,$addto))을 변경해야합니다. $addto은 혼합 된 값일 수 있기 때문에 === 사용자는 유형 변환없이 부울 false을 찾습니다. 그것은 당신의 문제를 해결할 것입니다. mysqli_query이 click here을 반환하고 반환 값을 아래로 스크롤 할 수 있는지의 문서에 대해서는

. "와 '의

0

잘못된 사용 :.

echo "<script>alert('Error connecting to MySQL: " . mysqli_connect_error() ."')</script>"; 

이 코드를 즐길 수

+0

따옴표가 잘못 사용 된 것은 맞지만 OP가 해결하려고하는 것은 아닙니다. 규칙이 아니라 미래의 참조를 위해 다음과 같이 주석을 달아보십시오. =) 좋은 캐치. – Mic1780

관련 문제