2014-10-26 77 views
0

我是一個業餘的Web開發人員學習PHP和MySQL,所以我可能會發送PHP/HTML表單數據到SQL服務器。不幸的是,當我在Web服務器上運行程序並單擊提交按鈕時,sql服務器不會檢索我輸入到表單中的數據。我一直在嘗試多次嘗試。任何幫助將不勝感激。插入PHP表單數據不發送到MySQL服務器

<!DOCTYPE> 
<html> 
<head> 
<title>Business Therapy</title> 
</head> 
<body bgcolor="ba2e2e"> 
<h1><center>Welcome To The Therapy of Business</center></h1> 

<?php 
if (isset($_POST['submit'])){ 

    $con = mysql_connect ("194.81.104.22", "xxxxx", "xxxx"); 

     if (!$con) { 
     die("Cannot connect : " . mysql_error()); 
     } 

mysql_select_db ("db12408543",$con); 

$sql = "INSERT INTO Business (idBusiness, Name, Description, Time, Date, Location, Room, Speakers) VALUES ('$_POST[idBusiness]','$_POST[Name]','$_POST[Description]','$_POST[Time]','$_POST[Date]','$_POST[Location]','$_POST[Room]','$_POST[Speakers]')"; 

mysql_query($sql,$con); 

mysql_close($con); 
} 
?> 
<h3>Create A Seminar</h3> 
<form action="adding.php" method"post"> 
idBusiness: <input type="text" name="idbusiness"><br /> 
Name: <input type="text" name="name"><br /> 
Description: <textarea name="description"></textarea><br /> 
Time: <input type="text" name="time"><br /> 
Date: <input type="text" name="date"><br /> 
Location: <input type="text" name="location"><br /> 
Room: <input type="text" name="room"><br /> 
Speakers: <input type="text" name="speakers"><br /> 
<input type="reset" name="reset"> 
<input type="submit" name="submit" value="Submit"> 




</form> 


</body> 

+0

想要檢索OR插入數據嗎? – 2014-10-26 18:00:55

+0

您必須學會使用以下三件事:W3C標記驗證程序:http://validator.w3.org/,CSS驗證程序:http://jigsaw.w3.org/css-validator/,以及開發人員工具在Firefox/Firebug或Chrome中。 – 2014-10-26 18:04:46

+0

我想插入數據到數據庫中,然後將其存儲在sql server中,例如phpymydmin。當我登錄到服務器時,我喜歡看錶中的記錄,但我沒有看到。 – 2014-10-26 18:06:37

回答

2

你有一個錯字改變這一點:

<form action="adding.php" method"post"> 

要這樣:

<form action="adding.php" method="post"> 
+0

謝謝,這是正確的答案,並表示相同的答案,謝謝。我真的很感謝你的幫助。 – 2014-10-26 18:20:05

+0

@GlennYemoh沒問題。錯字不幸地困擾着我們所有人! – gudthing 2014-10-26 18:23:12

0

也許錯字方法= 「後」,而不是方法 「後」

+0

正確,謝謝您的協助,先生。我很感激。 – 2014-10-26 18:24:30

-1

 
 

 
    
 
**My problem is unic plz help me....** 
 

 
> this is my full code but it normaly when i type information by 
 
> keyboard or menuarl this time it working but when i copy information 
 
> by othe website and fill the texarea or input text this time the info 
 
> dose't submit in MYSQL databse... 
 

 
plz help me its unic prblem 
 

 
<form action="?" enctype="multipart/form-data" method="post">  
 
    <table> 
 
    <caption><h1>Tours Places</h1></caption> 
 
    <tr> 
 
    <td><input type="text" name="place" onKeyUp="getplace(this.value)" autocomplete="off" placeholder="Tours Places" class="all" id="place" required></td><td><div id="result"></div><p>Only one Place</p></td> 
 
    </tr> 
 
    <tr> 
 
    <td><select name="states" class="all" id="staes" required> 
 
    <?php 
 
     $query = "select * from states"; 
 
\t \t $run = mysql_query($query); 
 
\t \t while($tours = mysql_fetch_array($run)) 
 
\t \t { 
 
\t \t \t $tourstates = $tours['states']; 
 
\t \t 
 
\t \t ?> 
 
    <!-- check box--> 
 
    
 
    \t \t <option value="<?php echo $tourstates ?>"><?php echo $tourstates ?></option> 
 
    
 
    <?php 
 
\t \t } 
 
\t ?> 
 
    </select></td><td><p>Choose States</p></td></tr> 
 
    
 
    <tr> 
 
    <td><select name="districts" class="all" id="districts"> 
 
    <option value="null">Choose Districts or None</option> 
 
    <?php 
 
     $querydistricts = "select * from districts"; 
 
\t \t $rundistricts = mysql_query($querydistricts); 
 
\t \t while($toursdistricts = mysql_fetch_array($rundistricts)) 
 
\t \t { 
 
\t \t \t $distprint = $toursdistricts['districts']; 
 
\t \t 
 
\t \t ?> 
 
    <!-- check box--> 
 
    
 
    \t \t <option value="<?php echo $distprint ?>"><?php echo $distprint ?></option> 
 
    
 
    <?php 
 
\t \t } 
 
\t ?> 
 
    </select></td><td><p>Choose Districts</p></td></tr> 
 
    
 
    <tr> 
 
    <td> 
 
    <input type="file" name="images" class="all" required> 
 
    <td><p>1260 x 400</p></td> 
 
    </td> 
 
    </tr> 
 
    <tr> 
 
    <td><input name="language" type="text" class="all" placeholder="Language" required></td><td><p>Language</p></td> 
 
    </tr> 
 
    <tr> 
 
    <td><input name="weather" type="text" class="all" placeholder="Weather" required></td><td><p>Weather</p></td> 
 
    </tr> 
 
    <tr> 
 
    <td><input name="famousfor" type="text" class="all" placeholder="Famous for" required></td><td><p>Famous for</p></td> 
 
    </tr> 
 
    <tr> 
 
    <td><input name="howtorich" type="text" class="all" placeholder="How to reach" required></td><td><p>How to reach</p></td> 
 
    </tr> 
 
    <tr> 
 
    <td><input name="besttimev" type="text" class="all" placeholder="Best Time for visit" required></td><td><p>Language</p></td> 
 
    </tr> 
 
    <tr> 
 
    <td><input name="mostpreffer" type="text" class="all" placeholder="Most Preffer by" required></td><td><p>Most Preffer by</p></td> 
 
    </tr> 
 
    <tr> 
 
    <td> 
 
    <textarea placeholder="Tags" name="tags" class="all" required></textarea> 
 
    </td> 
 
    <td> 
 
    <p>Tags</p> 
 
    </td> 
 
    </tr> 
 
    <tr> 
 
    <td> 
 
    <textarea placeholder="About" name="about" class="all" required></textarea> 
 
    </td> 
 
    <td> 
 
    <p>about</p> 
 
    </td> 
 
    </tr> 
 
    <tr><td><textarea placeholder="Where to go from this location" name="wheretogo" class="all" required></textarea></td><td><p>Where to go from this location</p></td></tr> 
 
\t <tr><td><textarea placeholder="Past the google map's iframe link" name="map" class="all" required></textarea></td><td><p>Where to go from this location</p></td></tr> 
 

 
    
 
    
 
    <tr> 
 
    <td colspan="2"> 
 
    \t <table width="100%" class="checkbox"> 
 
     \t <tr> 
 
      <td width="17%" align="right">Package</td><td width="83%" align="left"><input type="checkbox" name="package" value="Package"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Weekend</td><td width="83%" align="left"><input type="checkbox" name="weekend" value="Weekend"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Adventure</td><td width="83%" align="left"><input type="checkbox" name="adventure" value="Adventure"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Educational</td><td width="83%" align="left"><input type="checkbox" name="educational" value="Educational"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Pilgrimage</td><td width="83%" align="left"><input type="checkbox" name="pilgrimage" value="Pilgrimage"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Corporate</td><td width="83%" align="left"><input type="checkbox" name="corporate" value="Corporate"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Cultural</td><td width="83%" align="left"><input type="checkbox" name="cultural" value="Cultural"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Wild Life</td><td width="83%" align="left"><input type="checkbox" name="wildlife" value="WildLife"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Honeymoon</td><td width="83%" align="left"><input type="checkbox" name="honeymoon" value="Honeymoon"></td> 
 
      </tr> 
 
      
 
      
 
      <td width="17%" align="right">Beach</td><td width="83%" align="left"><input type="checkbox" name="beach" value="Beach"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Mountain</td><td width="83%" align="left"><input type="checkbox" name="mountain" value="Mountain"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">Historical</td><td width="83%" align="left"><input type="checkbox" name="historical" value="Historycal"></td> 
 
      </tr> 
 
      <tr> 
 
      <td width="17%" align="right">River</td><td width="83%" align="left"><input type="checkbox" name="river" value="River"></td> 
 
      </tr> 
 
     </table> 
 
    </td> 
 
    </tr> 
 
    
 
    <tr><td class="offbeat"><input type="checkbox" value="offbeat" name="offbeat" class="all">Off - Beat</td><td><p>Confirm its offbeat or not</p></td></tr> 
 
\t 
 
    <tr><td class="dspacial"><input type="checkbox" value="diganta_spacial" name="dspacial" class="all">Diganta - Spacial</td><td><p>Confirm its Diganta Spacial or not</p></td></tr> 
 
    <tr> 
 
    <td colspan="2" align="center"><input type="submit" value="Submit" class="button" name="submit"> 
 
    <input type="reset" value="Discart" class="button"></td> 
 
    </tr> 
 

 
    </table> 
 
    
 
    </form> 
 

 

 

 
<?php 
 
\t if(isset($_POST['submit'])) 
 
\t { 
 
@$place_name = mysql_real_escape_string($_POST['place']); 
 

 
@$placecode = str_replace(' ', '', $place_name); 
 
@$placecode = strtolower($placecode); 
 

 
@$place_states = mysql_real_escape_string($_POST['states']); 
 
@$place_districts = mysql_real_escape_string($_POST['districts']); 
 
@$place_img = mysql_real_escape_string($_POST['images']); 
 
@$place_language = mysql_real_escape_string($_POST['language']); 
 
@$place_weather = mysql_real_escape_string($_POST['weather']); 
 
@$place_famousfor = mysql_real_escape_string($_POST['famousfor']); 
 
@$place_howtorich = mysql_real_escape_string($_POST['howtorich']); 
 
@$place_besttimev = mysql_real_escape_string($_POST['besttimev']); 
 
@$place_mostpreffer = mysql_real_escape_string($_POST['mostpreffer']); 
 
@$place_tags = mysql_real_escape_string($_POST['tags']); 
 
@$place_about = mysql_real_escape_string($_POST['about']); 
 
@$place_wheretogo = mysql_real_escape_string($_POST['wheretogo']); 
 
@$place_map = mysql_real_escape_string($_POST['map']); \t 
 
@$place_option_package = mysql_real_escape_string($_POST['package']); 
 
@$place_option_weekend = mysql_real_escape_string($_POST['weekend']); 
 
@$place_option_adventure = mysql_real_escape_string($_POST['adventure']); 
 
@$place_option_educational = mysql_real_escape_string($_POST['educational']); 
 
@$place_option_pilgrimage = mysql_real_escape_string($_POST['pilgrimage']); 
 
@$place_option_corporate = mysql_real_escape_string($_POST['corporate']); 
 
@$place_option_cultural = mysql_real_escape_string($_POST['cultural']); 
 
@$place_option_wildlife \t = mysql_real_escape_string($_POST['wildlife']); 
 
@$place_option_honeymoon = mysql_real_escape_string($_POST['honeymoon']); 
 
@$place_option_beach = mysql_real_escape_string($_POST['beach']); 
 
@$place_option_mountain \t = mysql_real_escape_string($_POST['mountain']); 
 
@$place_option_historical = mysql_real_escape_string($_POST['historical']); 
 
@$place_option_river = mysql_real_escape_string($_POST['river']); 
 
@$place_option_offbeat = mysql_real_escape_string($_POST['offbeat']); 
 
@$place_option_dspacial = mysql_real_escape_string($_POST['dspacial']); 
 

 
\t \t 
 
\t if($place_districts == "null") 
 
\t { 
 
\t \t $place_districts == ''; 
 
\t } 
 
\t elseif($place_districts != "null") 
 
\t { 
 
\t \t $place_districts = mysql_real_escape_string($_POST['districts']); 
 
\t } 
 
\t \t 
 
\t echo @$place_img = $_FILES["images"]["name"]; 
 
\t echo @$fileTmpLoc = $_FILES["images"]["tmp_name"]; 
 
\t echo @$filesize = $_FILES["images"]["size"]; 
 
\t echo @$filetype = $_FILES["images"]["type"]; 
 
\t 
 
\t $submitquery = "INSERT INTO tours(placecode, place, states, districts, images, language, weather, famousfor, howtorich, besttimev, mostpreffer, tags, about, wheretogo, map, package, weekend, adventure, educational, pilgrimage, corporate, cultural, wildlife, honeymoon, beach, mountain, historical, river, offbeat, dspacial, datetime) 
 
\t VALUES ('{$placecode}', '{$place_name}', '{$place_states}', '{$place_districts}', '{$place_img}', '{$place_language}', '{$place_weather}', '{$place_famousfor}', '{$place_howtorich}', '{$place_besttimev}', '{$place_mostpreffer}', '{$place_tags}', '{$place_about}', '{$place_wheretogo}', '{$place_map}', '{$place_option_package}', '{$place_option_weekend}', '{$place_option_adventure}', '{$place_option_educational}', '{$place_option_pilgrimage}', '{$place_option_corporate}', '{$place_option_cultural}', '{$place_option_wildlife}', '{$place_option_honeymoon}', '{$place_option_beach}', '{$place_option_mountain}', '{$place_option_historical}', '{$place_option_river}', '{$place_option_offbeat}', '{$place_option_dspacial}', NOW())"; 
 
\t \t if(mysql_query($submitquery)) 
 
\t \t { 
 
\t \t \t move_uploaded_file($fileTmpLoc,"../images/tours/$place_img"); \t \t 
 
\t \t \t echo "<script>window.open('sightseeing.php?placesight=$placecode','_self')</script>"; 
 
\t \t } 
 

 
\t } \t 
 
\t ?>