2017-01-20 3 views
0

MYSQL 쿼리를 입력하여 PHP를 통해 실행할 수있는 HTML 양식을 만들려고합니다. 난 당신이 사용자 입력을 통해 MySQL의 쿼리를 실행할 수 있도록하려면, 만약 내가 제대로 이해하고 실행하는이

쿼리 실행 후 오류/성공 메시지 표시

<?php 
    if(isset($_POST['submit']) && !empty($_POST['query'])){ 
$query = $_POST['query'];  
mysql_query($query); 

} 

    ?> 

<form action="" method="post"> 
    <div> 
     <textarea name="query"></textarea> 
     <input type="submit" name="submit" value="submit" /> 
    </div> 
</form> 
+0

임은 확실하지 이해. 쿼리를 입력 할 수있는 양식을 만든 다음 제출 단추를 클릭하여 해당 쿼리를 실행하도록 하시겠습니까? 그렇다면 Google HTML 양식과 PHP PDO 만 있으면 함께 넣을 수 있습니다. – SaggingRufus

+0

일부 PHP 코드를 작성하여 작성 했습니까? – Naruto

+0

아니요 아직은 없지만 그 일을하고 싶습니다. –

답변

0

를 조회 한 후 내가 ERROR/성공 메시지를 표시하려면 지금이 코드를 사용? 제출 버튼을 사용자 입력 (예 : $ _REQUEST [ 'query'])을 잡고 해당 데이터베이스에 연결하고 쿼리하는 PHP 스크립트로 리디렉션하십시오. 코드 예제 :

PHP :

<?php 

    /* query.php */ 
    $query = $_REQUEST['query']; //do SQLi prevention 
    $conn = new mysqli('localhost', 'root', '', 'db'); 
    if($conn->connect_error) throw new \Exception('Failed to connect to MySQL server.'); //have the script handle the exception elsewhere 
    if($conn->query($query) !== false) 
    { 
     echo 'Query executed successfully.'; 
    } 
    else 
    { 
     throw new \Exception('MySQL error: ' . $conn->error); //have the script handle the exception elsewhere 
    } 
    $conn->close(); 

HTML : 정확히 무엇을 요구

<!DOCTYPE html> 
    <!-- index.html --> 
    <html> 
    <head> 
    </head> 
    <body> 
     <form method='POST' action='query.php'> 
     <input type='text' name='query' /> 
     <br /> 
     <input type='submit' /> 
     </form> 
    </body> 
    </html> 
관련 문제