2017-04-17 5 views
1

私は2つの.phpページを持っています。それぞれのエントリのidとhtmlテキスト入力を含むテーブルの内容を返すものと、詳細を取得してレコードを更新するもの。ハイパーリンクを使ってphp get set変数を設定する

idを入力して送信するのではなく、hrefを使用してリスト項目をクリックしてエントリのIDを保存します。

session_start(); 

$reference = $_GET['regName']; 

echo "Your selection id is: ".$reference."."; 
$query="SELECT * FROM firsttable WHERE reference='$reference'"; 
$result=mysql_query($query) or die("Query to get data from firsttable failed with this error: ".mysql_error()); 
$row=mysql_fetch_array($result); 

$name=$row[name]; 

echo "<form method=\"POST\" action=\"updated.php\">"; 
    echo "<p>"; 
     echo "<label for=\"name\">Name: </label><input type=\"text\" id=\"name\" name=\"name\" size=\"30\" value=\"$name\"/>"; 

    echo "<p><input type=\"submit\"></p>"; 
echo "</form>"; 

私は、これは非常に明白なようであれば謝罪

choose.php

echo "<ul>";      
while ($row=mysql_fetch_array($result)) { 
    $reference=$row[reference]; 
    $name=$row[name]; 
    echo "<li>$reference, $name</li>"; 
} 
echo "</ul>";  


session_start(); 

$_SESSION['regName'] = $reference; 
mysql_close($link); 
?> 

<form method="get" action="update.php"> 
    <input type="text" name="regName" value=""> 
    <input type="submit"> 
</form> 

update.phpを、私は今日だけのようにPHPを学び始めたのだが、何よりもはるかに複雑です私は今まで終わった。あなたの質問に答える

おかげ ジェームズ

+1

*** [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/wiki)について学んでください。/Prepared_statement)ステートメント(PDO)(http://php.net/manual/en/pdo.prepared-statements.php)と[MySQLi](http://php.net/manual/en/mysqli.quickstart。 prepared-statements.php)、PDOの使用を検討してください。[これは本当に簡単です](http://jayblanchard.net/demystifying_php_pdo.html)。 –

+1

[Little Bobby](http://bobby-tables.com/)によると*** [あなたのスクリプトはSQLインジェクション攻撃の危険にさらされています。](http://stackoverflow.com/questions/60174/how-can- i-prevent-sql-in-php)***。 [文字列をエスケープする](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)でも安全ではありません! –

+0

十分なはずです。何を試しましたか? –

答えて

0

は、あなただけのタグのHREFパラメータを使用する必要があります。 POST \ GETを介してデータを渡すことについての詳細はこちらをお読み

echo '<ul>';      
while ($row = mysql_fetch_array($result)) { 
    $reference = $row[reference]; 
    $name = $row[name]; 
    echo '<li><a href=/update.php?regName='.$reference.'>'.$name.'</a></li>'; 
} 
echo '</ul>';  
?> 

:これはあなたが必要と参照が含まれますアクティブリンク、になりますhttps://www.w3schools.com/tags/ref_httpmethods.asp

をそして、あなたは上記の言われたように、再配線をご検討くださいコードは完全に安全ではなく、何らかの非常に基本的な概念の証明の他に何も使用されてはいけません。イントラネットやローカルマシン内だけ。
幸運を祈る!

関連する問題