2013-09-02 2 views
-1

몇 가지 이유 때문에 POST 문자열 값 또는 데이터베이스에 해당 값을 보낼 수 없습니다. 모든 열은 올바른 길이의 varchar를 사용하고 메신저를 설정합니다. SQL 쿼리 문을 올바르게. 나는이 질문에 답을 찾았지만 답변을 찾지 못했습니다. 그러나 여전히 작동하지는 않으며 ive는 문법 오류가없는 PHP validator을 여러 번 실행했습니다.내 PHP 코드가 mysql 데이터베이스에 아무 것도 입력하지 않는 이유는 무엇입니까

Apply.php

<?php 
$required = array('name', 'age', 'position', 'email', 'desc'); 
$name= $_POST["name"]; 
$age= $_POST["name"]; 
$email= $_POST["email"]; 
$position= $_POST["position"]; 
$desc= $_POST["desc"]; 
$error = false; 
foreach($required as $field) { 
    if (empty($_POST[$field])) { 
    $error = true; 
    } 
} 

if ($error) { 
    echo "You must fill in all fields"; 
} 
else { 
    echo "Application Submitted, You will receive an email with a validation code in 1-2 days </br>Ask the owner in game for faster service"; 
    mysqli_connect("localhost","root","password","apply"); 
    mysqli_query("INSERT INTO applications (name, age, email, position, desc) VALUES ('$name', '$age', '$email', '$position', '$desc')"); 
    mysqli_close(); 
    } 
?> 

read_database.php

<?php 
$username="root"; 
$password="password"; 
$database="apply"; 
mysql_connect(localhost,$username,$password); 
$result = mysqli_query("SELECT * FROM applications") ; 

echo "<table border='1'> 
<tr> 
<th> Name </th> 
<th> Age </th> 
<th> Email Address </th> 
<th> Position </th> 
<th> Reasoning </th> 
</tr>"; 

while($row = mysqli_fetch_array($result)) 
{ 
echo "<tr>"; 
echo "<td>" . $row['Name'] . "</td>"; 
echo "<td>" . $row['age'] . "</td>"; 
echo "<td>" . $row['email'] . "</td>"; 
echo "<td>" . $row['position'] . "</td>"; 
echo "<td>" . $row['desc'] . "</td>"; 
echo "</tr>"; 

} 

echo "</table>"; 
mysqli_close(); 
?> 
+0

검사()'. 'false'를 반환하면 mysql_error()를 호출하여 오류를 확인합니다. – Barmar

+0

두 번째 스크립트에서는 mysql과 mysqli 함수를 혼합하고있다. 그것은 작동하지 않습니다. – Barmar

+0

MySQL을 사용합니다. 이 PHP 문서를 참고하여 스크립트의 보안을 강화하십시오 http://www.php.net/manual/en/mysqli.real-escape-string.php –

답변

0

mysqli_queryhttp://de2.php.net/manual/en/mysqli.query.php

에 대한 설명서를 읽기 : 아래

내 코드입니다 는 mysql_query`에서 오류
$link=mysqli_connect("localhost","root","password","apply"); 
mysqli_query($link,"INSERT INTO applications (name, age, email, position, desc) VALUES ('$name', '$age', '$email', '$position', '$desc')"); 
mysqli_close(); 

또는

$mysqli=mysqli_connect("localhost","root","password","apply"); 
$mysqli->query("INSERT INTO applications (name, age, email, position, desc) VALUES ('$name', '$age', '$email', '$position', '$desc')"); 
mysqli_close(); 
+0

고마워요. 실제로 수정 된 원본 코드가 $ 링크와 쿼리 사이에 쉼표가 없기 때문에 새로운 튜토리얼로 바뀌 었습니다. 필요하지 않다고 가정하고 삭제했습니다. – PotatoPotato

관련 문제