0

名前、テキスト、場所、連絡先を投稿する投稿フォームがあります。4つのラベル。

htmlの投稿フォームのコードは次のようになります。

<div  class="form">
            <form id="contactform" action="post.php" method="post"> 
                <p class="contact"><label for="who">Who</label></p> 
                <input id="who" name="who" placeholder="Who are you? (First & Second name)" required="" type="text"> 

                <p class="contact"><label for="email">Text</label></p> 
                <input id="what" name="what" placeholder="Text" required="" type="text"> 

                <p class="contact"><label for="username">Where</label></p> 
                <input id="where" name="where" placeholder="Country, City, Street..." required="" type="text"> 

                <p class="contact"><label for="password">Contact</label></p> 
                <input type="text" id="contact" name="contact" placeholder="Phone number or email"required=""> 
<input class="buttom" name="submit" id="submit" tabindex="5" value="Submit" type="submit">

そして、post.phpコードは次のようになります。

<?php header("Location: feed.php"); ?>
<?php 

define ( 'DB_NAME','database_name');
define ( 'DB_USER','user');
define ( 'DB_PASSWORD','foot');
define ( 'DB_HOST','localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!link) {
die('Could not connect: ' .mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}

$value1 = $_POST['who'];
$value2 = $_POST['text'];
$value3 = $_POST['where'];
$value4 = $_POST['contact'];

$sql = "INSERT INTO content (`who`, `text`, `where`, `contact`) VALUES ('$value1', '$value2', '$value3', '$value4')";


 if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
    echo "You've just posted your text!";
mysql_close();
?>

私が欲しいのは、たとえばwww.mywebsite.com/post.php?name=MyName&text=MyText&place=MyPlace&contact=Contactと書くことでテキストを投稿できるようにすることです。

したがって、URLを介してフォームに入力できるはずです。

何か案は?

4

1 に答える 1

1

すべての$_POSTを$_GETまたは$_REQUESTに変更するだけで、完了です。

$ _GET:http
://www.php.net/manual/en/reserved.variables.get.php $ _REQUEST:http ://www.php.net/manual/en/reserved.variables.request.php

于 2013-03-14T22:10:46.043 に答える