2016-10-13 2 views
-1

내가 데이터베이스 값 연결 확인 값을 삽입 할 때. 모든 것은 정확하지만 항상 동일한 오류를줍니다. 이 페이지는 질문을 추가 할 때 사용하는 퀴즈입니다. 때마다 내가 DB 연결을 확인하시기 바랍니다 가치를 삽입 오전라고. 모든 것이 정확합니다. 사용자 이름 암호 데이터베이스 이름도 정확합니다. 그러나 같은 오류가데이터베이스에 값을 삽입 할 수 없습니다.

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8" /> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<title>!deal Banker</title> 
<style type="text/css"> 

body{ 
margin:0; 
padding:0; 
line-height: 1.5em; 
} 

b{font-size: 110%;} 
em{color: red;} 

#topsection{ 
background: #EAEAEA; 
height: 90px; /*Height of top section*/ 
} 

#topsection h1{ 
margin: 0; 
padding-top: 15px; 
} 

#contentwrapper{ 
float: left; 
width: 100%; 
} 

#contentcolumn{ 
margin: 0 200px 0 230px; /*Margins for content column. Should be "0 RightColumnWidth 0 LeftColumnWidth*/ 
} 

#leftcolumn{ 
float: left; 
width: 230px; /*Width of left column*/ 
margin-left: -100%; 
background: #C8FC98; 
} 

#rightcolumn{ 
float: left; 
width: 200px; /*Width of right column*/ 
margin-left: -200px; /*Set left marginto -(RightColumnWidth)*/ 
background: #FDE95E; 
} 

#footer{ 
clear: left; 
width: 100%; 
background: black; 
color: #FFF; 
text-align: center; 
padding: 4px 0; 
} 

#footer a{ 
color: #FFFF80; 
} 

.innertube{ 
margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/ 
margin-top: 0; 
} 

/* ####### responsive layout CSS ####### */ 

@media (max-width: 840px){ /* 1st level responsive layout break point- drop right column down*/ 

    #leftcolumn{ 
    margin-left: -100%; 
    } 

    #rightcolumn{ 
    float: none; 
    width: 100%; 
    margin-left: 0; 
    clear: both; 
    } 

    #contentcolumn{ 
    margin-right: 0; /*Set margin to LeftColumnWidth*/ 
    } 
} 

@media (max-width: 600px){ /* 2nd level responsive layout break point- drop left column down */ 
    #leftcolumn{ 
    float: none; 
    width: 100%; 
    clear: both; 
    margin-left: 0; 
    } 

    #contentcolumn{ 
    margin-left: 0; 
    } 
} 

</style> 



</head> 
<body> 
<div id="maincontainer"> 

<div id="topsection"><div class="innertube"> 
<?php 
include'menu.php'; 

?></div></div> 

<div id="contentwrapper"> 
<div id="contentcolumn"> 
<?php 

$conn = mysql_connect("localhost","banker","[email protected]"); 
$db = "idealbanker"; 
$table = "pp"; 
mysql_select_db($db,$conn); 

if(isset($_REQUEST['submit'])) 
{ 
if($_POST['question'] == '') 
{ 
echo 'cannot submit field empty'; 
} 
elseif($_POST['answer1'] == '') 
{ 
echo 'cannot submit field empty'; 
} 
elseif($_POST['answer2'] == '') 
{ 
echo 'cannot submit field empty'; 
} 
elseif($_POST['answer3'] == '') 
{ 
echo 'cannot submit field empty'; 
} 
elseif($_POST['answer4'] == '') 
{ 
echo 'cannot submit field empty'; 
} 
elseif($_POST['answer5'] == '') 
{ 
echo 'cannot submit field empty'; 
} 
else 
{ 
function clean($str) { 
       $str = @trim($str); 
       if(get_magic_quotes_gpc()) { 
         $str = stripslashes($str); 
       } 
       return mysql_real_escape_string($str); 
     } 

$question = clean($_POST['question']); 
$answer1 = clean($_POST['answer1']); 
$answer2 = clean($_POST['answer2']); 
$answer3 = clean($_POST['answer3']); 
$answer4 = clean($_POST['answer4']); 
$correctanswer = clean($_POST['answer5']); 
$qry = "INSERT INTO $table(question, answer1, answer2, answer3, answer4, correctanswer)VALUES('$question','$answer1','$answer2','$answer3','$answer4','$correctanswer')"; 
     $result = @mysql_query($qry); 
if(!$result) 
{ 
echo 'Question Cannot Submit Check DB Connection'; 
echo "<br><a href=".$_SERVER['PHP_SELF'].">Add Again</a>"; 
} 
else 
{ 
echo 'Question Submitted Successfully'; 
} 
echo "<br><a href=".$_SERVER['PHP_SELF'].">Add More</a>"; 
} 
} 
else 
{ 
echo '<form name="form1" method="post" action="'.$_SERVER['PHP_SELF'].'"> 
    <table width="500" border="0"> 
    <tr> 
     <td width="100">Question</td> 
     <td width="242"> 
     <input name="question" type="text" size="60"> 
</td> 
    </tr> 
    <tr> 
     <td>Answer 1 </td> 
     <td><input name="answer1" type="text" size="30"></td> 
    </tr> 
    <tr> 
     <td>Answer 2 </td> 
     <td><input name="answer2" type="text" size="30"></td> 
    </tr> 
    <tr> 
     <td>Answer 3 </td> 
     <td><input name="answer3" type="text" size="30"></td> 
    </tr> 
    <tr> 
     <td>Answer 4 </td> 
     <td><input name="answer4" type="text" size="30"></td> 
    </tr> 
    <tr> 
     <td>Correct Answer </td> 
     <td><input name="answer5" type="text" size="30"></td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td><label> 
     <input type="submit" name="submit" value="Submit"> 
     </label></td> 
    </tr> 
    </table> 
</form> 
'; 
} 
?> 
</div> 
</div> 

<div id="leftcolumn"> 
<?php 
include 'left.php'; 
?> 

</div> 

<div id="rightcolumn"> 
<?php 
include 'right.php'; 
?> 
</div> 

<div id="footer"><?php 
include'footer.php'; 

?></div> 

</div> 

</body> 
</html> 
+0

왜 더 이상 사용되지 않는 mysql_connect를 사용합니까? http://php.net/manual/en/function.mysql-connect.php –

+1

[Little Bobby] (http://bobby-tables.com/)에서 *** [귀하의 스크립트는 SQL 주입 공격의 위험이 있습니다 .] (http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) ***. 심지어 [이스케이프 문자열] (http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) 안전하지 않습니다! –

답변

3

귀하의 "체크 DB 연결"오류 메시지가 발생하는되어 완전히 쓸모가 없다. 고정 된 변경되지 않은 메시지를 출력하지 마십시오.

if (!$result) { 
    die(mysql_error()); 
} 

을 그리고 당신은 단순히 연결이 작동을 가정하고 있습니다 : 쿼리가 실패한 이유 당신을 말해 DB를 되세요. 연결 및 select_db 호출의 반환 값을 확인하는 것은 결코 어렵지 않습니다.

관련 문제