2014-03-12 2 views
0

나는 데이터를 삽입하려고 할 때마다 $content이 삽입되지 않을 때 다음 코드를 사용합니다. 어디에 문제가 있을까요? 보안 관련 문제에 대해 기능 테스트 입력을 사용하고 있습니다.mysql 게시물 누락 된 데이터 SERQU REQUEST_METHOD

<form method="POST" action="artPro.php"> 
    <fieldset> 
    <legend>Create New Article</legend> 
    <br/> 
    Article Title: 
    <input type="text" placeholder="enter title here" class="span3" name="title" required> 

      Image/Video Path : 

      <input type="text" placeholder="enter image name e.g k.jpg or k.mp4 for video" name="path" class="span3" required/> 

      File Type : 
      <input type="text" name="file_type" class="span3" required placeholder="e.g: image or video"/> 

    <br/> 

      <label>Article Content:</label> 

      <textarea name="content" rows="20" class="jqte-test span12" required id="txtmsg"></textarea> 


<br><button type="submit" class="btn btn-primary btn-large pull-right">Publish</button> 
    </fieldset> 
</form> 
+0

양식을 볼 수 있습니까? 또는 데이터를 게시하는 방법? mysqli_query ($ con, $ sql)을 실행하기 전에 –

+0

을 실행하면'echo $ sql'을 실행하고 질문을 출력 할 수 있습니까? – anurupr

+0

echo $ sql INSERT INTO articles (title, Content, Image_VideoLink_Path, file_type) – Samueln8

답변

0

이 쿼리를보십시오 : 당신이 기술 자료를 제공하고 있기 때문에

$sql="INSERT INTO articles (Title,Content,Image_VideoLink_Path,file_type) VALUES ('$title','$content','$path',' $file_type')";

$ 내용이 삽입되지 않았습니다 여기

<?php 
// define variables and set to empty values 
$title = $content = $path = $file_type =""; 

if ($_SERVER["REQUEST_METHOD"] == "POST") 
{ 
    $title = test_input($_POST["title"]); 
    $content = test_input($_POST["content"]); 
    $path = test_input($_POST["path"]); 
    $file_type = test_input($_POST["file_type"]); 

} 

function test_input($data) 
{ 
    $data = trim($data); 
    $data = stripslashes($data); 
    $data = htmlspecialchars($data); 
    return $data; 
} 

$con=mysqli_connect("localhost","---","---","---"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 


$sql="INSERT INTO articles (ArtID,Title,Content,Image_VideoLink_Path,file_type) 
VALUES 
('','$title','$content','$path',' $file_type')"; 

if (!mysqli_query($con,$sql)) 
    { 
    die('Error: ' . mysqli_error($con)); 
    } 
echo "<h2 >Article Published</h2>"; 
echo"<a href='../mag/index.php'> View it Now </a>"; 

mysqli_close($con); 
?> 

는 폼의 코드입니다. 아티클 ID가 기본 키가되며 자동 증가됩니다. 따라서 sql query (statement)에서 Article ID를 언급 할 필요가 없습니다.

+0

변경하려고 시도했지만 $ SQL을 echo하는 경우 : INSERT INTO articles (Title, Content, Image_VideoLink_Path, file_type) VALUE ('benb', '', 'rr.jpg', 'image') – Samueln8

+0

왜 $ sql을 표시합니까? 데이터베이스에 삽입하려면 쿼리를 실행해야합니다. $ sql이 입력 할 때 값을 주면 $ sql이 올바른 것입니다. 쿼리를 실행하면됩니다. 다음과 같이 쿼리를 실행할 수 있습니다 : if (! mysqli_query ($ con, $ sql)) { die ('Error :'. mysqli_error ($ con)); } –

관련 문제