2011-04-02 78 views
0

下面是一個表單,應該提交信息到MySQL數據庫。HTML表單和PHP查詢沒有提交數據到MySQL數據庫

下面的提交表單及其相應的查詢文件不起作用。我填寫所有字段,然後單擊「提交」,並且不會收到錯誤消息。

關於submit2a.php,我有mysql_connect() or die(mysql_error());mysql_select_db() or die(mysql_error());,我沒有得到一個錯誤,所以我假設它連接到MySQL。

但是當我檢查MySQL數據庫時,我添加的新信息不存在。

有沒有人在下面的代碼中看到任何明顯的錯誤?

由於提前,

約翰

形式:

echo '<form enctype="multipart/form-data" action="http://www...com/.../submit2a.php" method="post"> 
    <input type="hidden" value="'.$_SESSION['loginid'].'" name="uid"> 

    <div class="submissiontitle"><label for="title">Blog Post Title:</label></div> 
    <div class="submissionfield"><input class="checkMax3" name="title" type="title" id="title" maxlength="80"></div> 


    <div class="texttitle"><label for="text1">Blog Post Text 1:</label></div> 
    <div class="textfield"><textarea class="checkMax" name="text1" type="comment" id="text1" maxlength="10000"></textarea></div> 

    <div class="imagetitle"><label for="image1">Image 1:</label></div> 
    <div class="imagefield"><input type="file" name="image1" /></div> 

    <div class="hyperlinktitle"><label for="url1">Hyperlink 1:</label></div> 
    <div class="hyperlinkfield "><input name="url1" type="title" id="url1" maxlength="200"></div> 



    <div class="texttitle2"><label for="text2">Blog Post Text 2:</label></div> 
    <div class="textfield2"><textarea class="checkMax" name="text2" type="comment" id="text2" maxlength="10000"></textarea></div> 

    <div class="imagetitle2"><label for="image2">Image 2:</label></div> 
    <div class="imagefield2"><input type="file" name="image2" /></div> 

    <div class="hyperlinktitle2"><label for="url2">Hyperlink 2:</label></div> 
    <div class="hyperlinkfield2"><input name="url2" type="text" id="url2" maxlength="200"></div> 



    <div class="texttitle3"><label for="text3">Blog Post Text 3:</label></div> 
    <div class="textfield3"><textarea class="checkMax" name="text3" type="comment" id="text3" maxlength="10000"></textarea></div> 

    <div class="imagetitle3"><label for="image3">Image 3:</label></div> 
    <div class="imagefield3"><input type="file" name="image3" /></div> 

    <div class="hyperlinktitle3"><label for="url3">Hyperlink 3:</label></div> 
    <div class="hyperlinkfield3"><input name="url3" type="text" id="url3" maxlength="200"></div> 



    <div class="texttitle4"><label for="text4">Blog Post Text 4:</label></div> 
    <div class="textfield4"><textarea class="checkMax" name="text4" type="comment" id="text4" maxlength="10000"></textarea></div> 

    <div class="imagetitle4"><label for="image4">Image 4:</label></div> 
    <div class="imagefield4"><input type="file" name="image4" /></div> 

    <div class="hyperlinktitle4"><label for="url4">Hyperlink 4:</label></div> 
    <div class="hyperlinkfield4"><input name="url4" type="text" id="url4" maxlength="200"></div> 





    <div class="submissionbutton"><input name="submit" type="submit" value="Submit"></div> 
</form> 
'; 

的查詢上submit2a.php:

$remove_array = array('http://www.', 'http://', 'https://', 'https://www.', 'www.'); 

$uid = $_POST['uid']; 

$title = $_POST['title']; 

$text1 = $_POST['text1']; 

$image1 = $_POST['image1']; 

$image1 = $_FILES['image1']; 

$url1 = $_POST['url1']; 



$text2 = $_POST['text2']; 

$image2 = $_POST['image2']; 

$image2 = $_FILES['image2']; 

$url2 = $_POST['url2']; 



$text3 = $_POST['text3']; 

$image3 = $_POST['image3']; 

$image3 = $_FILES['image3']; 

$url3 = $_POST['url3']; 



$text4 = $_POST['text4']; 

$image4 = $_POST['image4']; 

$image4 = $_FILES['image4']; 

$url4 = $_POST['url4']; 







$cleanurl1 = str_replace($remove_array, "", $_POST['url1']); 
$cleanurl1 = strtolower($cleanurl1); 
$cleanurl1 = preg_replace('/\/$/','',$cleanurl1); 
$cleanurl1 = stripslashes($cleanurl1); 
$cleanurl1 = mysql_real_escape_string(trim($cleanurl1)); 

$cleanurl2 = str_replace($remove_array, "", $_POST['url2']); 
$cleanurl2 = strtolower($cleanurl2); 
$cleanurl2 = preg_replace('/\/$/','',$cleanurl2); 
$cleanurl2 = stripslashes($cleanurl2); 
$cleanurl2 = mysql_real_escape_string(trim($cleanurl2)); 


$cleanurl3 = str_replace($remove_array, "", $_POST['url3']); 
$cleanurl3 = strtolower($cleanurl3); 
$cleanurl3 = preg_replace('/\/$/','',$cleanurl3); 
$cleanurl3 = stripslashes($cleanurl3); 
$cleanurl3 = mysql_real_escape_string(trim($cleanurl3)); 

$cleanurl4 = str_replace($remove_array, "", $_POST['url4']); 
$cleanurl4 = strtolower($cleanurl4); 
$cleanurl4 = preg_replace('/\/$/','',$cleanurl4); 
$cleanurl4 = stripslashes($cleanurl4); 
$cleanurl4 = mysql_real_escape_string(trim($cleanurl4)); 



//$url = $_POST['url']; 

//$subcheck = (isset($_POST['subcheck'])) ? 1 : 0; 
$title = mysql_real_escape_string($title); 
$title = stripslashes($title); 
$slug = str_replace(' ', '-', $title); 




echo '-'.$site1.'-'; 



$site1 = 'http://' . $cleanurl1; 
$site2 = 'http://' . $cleanurl2; 
$site3 = 'http://' . $cleanurl3; 
$site4 = 'http://' . $cleanurl4; 

$displayurl = parse_url($site1, PHP_URL_HOST); 




    $query = sprintf("INSERT INTO submission VALUES (NULL, '$title', '$text1', '$text2', '$text3', '$text4', '$site1', '$site2', '$site3', '$site4', NULL)")or die(mysql_error()); 


mysql_query($query, $db); 

     $id = (int) mysql_insert_id($db); 

$submissionid = $id;   



$info1 = getImageSize($image1['tmp_name']); 

$queryimage1 = sprintf(
      "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data) 
       values ('%s', '%s', '%s', %d, '%s')", 
      $submissionid, 
      mysql_real_escape_string($image1['name']), 
      mysql_real_escape_string($info1['mime']), 
      $image1['size'], 
      mysql_real_escape_string(
       file_get_contents($image1['tmp_name']) 
      ) 
     )or die(mysql_error()); 





$info2 = getImageSize($image2['tmp_name']); 

$queryimage2 = sprintf(
      "insert into images (NULL, ubmissionid, filename, mime_type, file_size, file_data) 
       values ('%s', '%s', '%s', %d, '%s')", 
      $submissionid, 
      mysql_real_escape_string($image2['name']), 
      mysql_real_escape_string($info2['mime']), 
      $image2['size'], 
      mysql_real_escape_string(
       file_get_contents($image2['tmp_name']) 
      ) 
     )or die(mysql_error());  




$info3 = getImageSize($image3['tmp_name']); 

$queryimage3 = sprintf(
      "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data) 
       values ('%s', '%s', '%s', %d, '%s')", 
      $submissionid, 
      mysql_real_escape_string($image3['name']), 
      mysql_real_escape_string($info3['mime']), 
      $image3['size'], 
      mysql_real_escape_string(
       file_get_contents($image3['tmp_name']) 
      ) 
     )or die(mysql_error()); 



$info4 = getImageSize($image4['tmp_name']); 

$queryimage4 = sprintf(
      "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data) 
       values ('%s', '%s', '%s', %d, '%s')", 
      $submissionid, 
      mysql_real_escape_string($image4['name']), 
      mysql_real_escape_string($info4['mime']), 
      $image4['size'], 
      mysql_real_escape_string(
       file_get_contents($image4['tmp_name']) 
      ) 
     )or die(mysql_error());  










header("Location: http://www...com/.../"); 
exit(); 
+0

首先:嘗試爲您的變量命名更好,其次,更乾淨的代碼是可管理的代碼!這就是說,如果你有輸出緩衝,頭(「位置:」)將工作,你不會看到任何錯誤。你確定你沒有從腳本中得到任何錯誤? – Khez 2011-04-02 02:26:55

回答

1

在第一種情況下,在我看來你在大多數語句中沒有調用「mysql_query」。即$ queryimage1,queryimage2,......

當前語句:

$queryimage1 = sprintf(
      "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data) 
       values ('%s', '%s', '%s', %d, '%s')", 
      $submissionid, 
      mysql_real_escape_string($image1['name']), 
      mysql_real_escape_string($info1['mime']), 
      $image1['size'], 
      mysql_real_escape_string(
       file_get_contents($image1['tmp_name']) 
      ) 
     )or die(mysql_error()); 

是:

$queryimage1 = mysql_query(sprintf(
      "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data) 
       values ('%s', '%s', '%s', %d, '%s')", 
      $submissionid, 
      mysql_real_escape_string($image1['name']), 
      mysql_real_escape_string($info1['mime']), 
      $image1['size'], 
      mysql_real_escape_string(
       file_get_contents($image1['tmp_name']) 
      ) 
     ))or die(mysql_error()); 
+0

謝謝...這有助於很多。它似乎引導我朝着正確的方向前進。 – John 2011-04-02 02:48:50

+0

不客氣,我很高興它幫助你 – 2011-04-03 15:11:05

0

您使用mysqli或MYSQLI_PREPARE!

相關問題