2016-04-13 19 views
0

何が間違っているのかわかりません。接続は正常に動作しています。私は同じconnection.phpファイルを使ってデータを保存しました。しかし、別の形式で事前に設定することはできません。助けてください。 これは私が書いたコードです:データベースのデータをフォームに事前に入力できません。

<?php 
session_start(); 
if (!isset($_SESSION['email'])) 
    header('location: index.php'); 
?> 
<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <title>Welcome</title> 
    </head> 
    <body> 
<form action="app_script.php" method="POST"> 
<input class="form-control" placeholder="Name" name="name" required = "true" value="<?php require_once("connection.php"); $eventid = $_GET['ID'];$field = $_GET['Name'];$result = mysql_query("SELECT $field FROM `persons` WHERE `ID` = '$eventid' ");$row = mysql_fetch_array($result);echo $row[$field]; ?>"> 
<button type="submit" name="submit" class="btn btn-primary pull-right">Submit</button> 
       </form> 
</body> 
</html> 
+1

をすごいああ、前に* *それを見たことがありません。入力は 'value'の中にあります。受け取っているエラーは何ですか? 'あらかじめ設定することはできません'とはあまり関係ありません。 – Marcus

+0

フォームのフィールドが空です。私は名前がデータベースからあらかじめ設定されていることを望みます。 – Aaryan

+0

'value'属性のコード全体をページのどこかに移動し、値を取得できるかどうかを' echo'します。違いはないかもしれませんが、今は混乱しやすく、エラーが発生しやすいです。 –

答えて

0
<?php 
    session_start(); 
    if (!isset($_SESSION['email'])) 
     header('location: index.php'); 

    require_once("connection.php"); 
    $eventid = $_GET['ID']; 
    $field = $_GET['Name']; 
    $result = mysql_query("SELECT $field FROM `persons` WHERE `ID` = '$eventid' "); 
    if(mysql_num_rows($result)>0) 
    { 
    $row = mysql_fetch_array($result); 
    $output = $row[$field]; // to populate 
    } 
    else 
    { 
    $output ='';   
     } 
    ?> 

    <!DOCTYPE html> 
    <html lang="en"> 
     <head> 
      <title>Welcome</title> 
     </head> 
     <body> 
    <form action="app_script.php" method="POST"> 
    <input class="form-control" placeholder="Name" name="name" required = "true" 
    value="<?php echo $output; ?>"> 
    <button type="submit" name="submit" class="btn btn-primary pull-right">Submit</button> 
        </form> 
    </body> 
    </html> 
+0

コード$ result = mysql_query( "SELECT $ field FROM' persons' WHERE 'ID' = '$ eventid'")またはdie(mysql_error())を変更します。クエリでエラーが発生しているかどうか – seguro

+0

[mysql_ *関数の使用をやめてください](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [これらの拡張機能](http://php.net/manual/en/migration70.removed-exts-sapis.php)はPHP 7で削除されました。[prepared](http://en.wikipedia.org/ [PDO](http://php.net/manual/en/pdo.prepared-statements.php)および[MySQLi](http://php.net/manual/en/mysqli.quickstart)のwiki/Prepared_statement)ステートメント.prepared-statements.php)、PDOの使用を検討してください。[これは本当に簡単です](http://jayblanchard.net/demystifying_php_pdo.html)。 –

+0

なぜOPはこれを試すべきですか? ***良い答え***は、何が行われたのか、それがOPのためだけでなく、将来の訪問者のためにそうした方法で行われた理由について、常に説明します。 –

関連する問題