2017-02-20 23 views
-4

私はPHPコードを持っていますので、フォームデータをdatataseに保存します。私はテスト、私は "データベースに直接挿入することができますテーブル値()"に書き込むことができます、それはデータベースに挿入することができます。私はsubmitボタンをクリックするとフォームデータをdbに保存できません

私のUIで、[送信]ボタンをクリックすると、DBに保存できません。

<?php 
    include('connectWorkbench.php'); 
    $sql=mysql_query("SELECT * FROM Properties"); 
    $epr = ''; 
    $msg = ''; 
    if(isset($_GET['epr'])) 
     $epr=$_GET['epr']; 
    //++++++++++++++++++++++++++++++save record++++++++++++++++++ 
    if($epr=='save') 
    { 
     $pid=$_POST['pid']; 
     $aid=$_POST['aid']; 
     $uid=$_POST['uid']; 
     $code=$_POST['code']; 
     $name=$_POST['name']; 
     $description=$_POST['description']; 
     $parking=$_POST['parking']; 
     $sfeet=$_POST['sfeet']; 
     $price=$_POST['price']; 
     $distance=$_POST['distance']; 
     $owner=$_POST['owner']; 

     $a_sql=mysql_query("INSERT INTO Properties VALUES($pid,$aid,$uid,$code,'$name','$description','$parking',$sfeet,'$price','$distance','$owner')"); 
     if($a_sql) 
      header("location:index.php"); 
     else 
     { 
      $msg='Error:'.mysql_error(); 
      echo '$msg'; 
     } 


    } 

?> 
<!--$query = mysql_query("SELECT * FROM Contact"); 
    while($row = mysql_fetch_array($query)) 
    { 
     $id = $row['contact_ID']; 
     $fname = $row['first_name']; 
     $midname = $row['middle_name']; 
     $lname = $row['last_name']; 
     echo '<br />' .$id. ':' . $fname . '<br />'; 
    } 
$query2 = mysql_query("SELECT * FROM Properties"); 
    while($row = mysql_fetch_array($query2)) 
    { 
     $id = $row['property_ID']; 
     $addressID = $row['property_address_ID']; 
     $ownerID = $row['owner_user_ID']; 
     $propertyCode = $row['property_type_code']; 
     echo '<br />' .$id. ':' . $addressID . ':' . $ownerID .':'. $propertyCode .'<br />'; 
    } 

    <IMG SRC=""> 
    --> 
<html> 
    <head> 
    </head> 
    <body> 

     <h2 align="center">Contact Us</h2> 
     <table align="center" border="1" cellspacing="0" cellpadding="0" width="700"> 
      <thead> 
       <th>First Name</th> 
       <th>Middle Name</th> 
       <th>Last Name</th> 
       <th>Email Address</th> 
       <th>Message</th> 
      </thead> 
     </table> 

     <h2 align="center">Edit Property</h2> 
     <form method="POST" action='index.php?epr=save'> 
      <table align="center" width="700"> 
       <tr> 
        <td>property id</td> 
        <td><input type='text' name='pid'></td> 
       </tr> 
       <tr> 
        <td>Property address ID</td> 
        <td><input type='text' name='aid'/></td> 
       </tr> 
       <tr> 
        <td>Owner user ID</td> 
        <td><input type='text' name='uid'/></td> 
       </tr> 

       <tr> 
        <td>Property type code</td> 
        <td><input type='text' name='code'/></td> 
       </tr> 
       <tr> 
        <td>Property name</td> 
        <td><input type='text' name='name'/></td> 
       </tr> 
       <tr> 
        <td>Property description</td> 
        <td><input type='text' name='description'/></td> 
       </tr> 
       <tr> 
        <td>Parking</td> 
        <td><input type='text' name='parking'/></td> 
       </tr> 
       <tr> 
        <td>Square feet</td> 
        <td><input type='text' name='sfeet'/></td> 
       </tr> 
       <tr> 
        <td>Rent price</td> 
        <td><input type='text' name='price'/></td> 
       </tr> 
       <tr> 
        <td>Distance from campus</td> 
        <td><input type='text' name='distance'/></td> 
       </tr> 
       <tr> 
        <td>Property owner</td> 
        <td><input type='text' name='owner'/></td> 
       </tr> 
       <tr> 
        <td></td> 
        <td><input type='submit' name='submitbutton' value="Submit"></td> 
       </tr> 

      </table> 

     </form> 
     <!--+++++++++++++++++++++++++Show Data++++++++++++++++++++--> 

     <h2 align="center">Property List</h2> 
     <table align="center" border="1" cellspacing="0" cellpadding="0" width="1200"> 
      <thead> 
       <th>Property ID</th> 
       <th>Property address ID</th> 
       <th>Owner user ID</th> 
       <th>Property type code</th> 
       <th>Property name</th> 
       <th>Property description</th> 
       <th>Parking</th> 
       <th>Square feet</th> 
       <th>Rent price</th> 
       <th>Distance from campus</th> 
       <th>Property owner</th> 
       <th>Action</th> 
      </thead> 
      <?php 
      $i=1; 
      while ($row=mysql_fetch_array($sql)) 
      { 
       echo"<tr> 
        <td>".$i."</td> 
        <td>".$row['property_address_ID']."</td> 
        <td>".$row['owner_user_ID']."</td> 
        <td>".$row['property_type_code']."</td> 
        <td>".$row['property_name']."</td> 
        <td>".$row['property_description']."</td> 
        <td>".$row['parking']."</td> 
        <td>".$row['square_feet']."</td> 
        <td>".$row['rent_price']."</td> 
        <td>".$row['distanceFromCampus']."</td> 
        <td>".$row['property_owner']."</td> 
        <td align='center'> 
         <a href='#'>Delete</a> | 
         <a href='#'>Edit</a> | 
         <a href='#'>New</a> 
        </td> 

       <tr>"; 
       $i++; 
      } 
      ?> 
     </table> 

    </body> 
</html> 
+2

新しいコードを書いてください。** _ please_は、mysql_ *関数を使わないでください**。彼らは古くて壊れていて、PHP 5.5では廃止されました(セキュリティアップデートをもはや受け取っていなくなっています)、PHP 7では完全に削除されました。['PDO'](https://secure.php.net/manual /en/book.pdo.php)または['mysqli_ *'](https://secure.php.net/manual/en/book.mysqli.php)を_prepared statements_と_parameter binding_で置き換えてください。詳細については、http://stackoverflow.com/q/12859942/354577を参照してください。 – Chris

+0

ありがとうございます。私は後でそれを変更します。私の現在のコード/問題を修正できますか? – AngularFan

+1

おそらく。質問をもっとはっきりと聞かせていただけますか?正確には何が問題なのですか? – Chris

答えて

1

SQLクエリが間違っているようです。あなたは、各項目が提出されている場所含める必要があります。

あなたのコード:

あなたが好きなものに変更する必要がある

INSERT INTOプロパティVALUES($ PID、$援助は、$ UID)

INSERT INTOプロパティ(pidrow、aidrow、uidrow)VALUES($ PID、$援助は、$ UID)

pidrowする$ pidの入力を行うであろうと、$援助入力ようにaidrow、とします。

+0

ここに情報を書き込む方法について説明します:https://www.w3schools.com/php/php_mysql_insert.asp –

0

雅は、あなたにクエリでも、列名を指定する必要があります。

INSERT INTO Properties(col1, col2, col3) 
VALUES(val1, val2, val3) 

ます。また、データベース

の使用に接続する必要があります。「あなたの場合は

mysqli($con, "query"); 
関連する問題