我有一个问题。我从表单构建一个表,并将值存储在mysql数据库中。表单正在运行,我看到表中的值,但是当我检查其他浏览器时,我看不到它们。我觉得有些东西不见了,但我不知道是什么。请问你能帮帮我吗 ?这是我的代码:
表单文件:
<form method="post" action="file.php">
<p class="titre">Informations</p>
<fieldset id="infos">
<p id="gender"><label>gender : </label>
<input type="radio" name="gender" value="M." />M.
<input type="radio" name="gender" value="Ms" />Ms
<input type="radio" name="gender" value="Mrs" />Mrs
</p>
<label>name : </label>
<input type="text" name="name" size="30" /><br />
<label>Address : </label>
<input type="text" name="address" size="30" /><br />
<label>zip code : </label>
<input type="text" name="zipcode" size="30" /><br />
<label>city : </label>
<input type="text" name="city" size="30" /><br />
<label>country : </label>
<select name="country">
<option value="france">France</option>
<option value="belgium">Belgium</option>
<option value="uk">uk</option>
</select>
<p id="interests"><label>interests : </label>
<input type="checkbox" name="interests[]" value="sport" />Sport
<input type="checkbox" name="interests[]" value="cinema" />Cinéma<br />
<input type="checkbox" name="interests[]" value="internet" />Internet
<input type="checkbox" name="interests[]" value="travel" />Voyages
</p>
</fieldset>
<p class="titre">Message</p>
<fieldset id="message">
<textarea name="comments" rows="5" cols="40"></textarea>
</fieldset>
<p id="buttons">
<input type="submit" value="send" />
<input type="reset" value="reset" />
</p>
</form>
和php文件:
<?php
define('DB_SERVER', 'localhost'); // serveur mysql
define('DB_SERVER_USERNAME', 'root'); // nom d'utilisateur
define('DB_SERVER_PASSWORD', 'xxxx'); // mot de passe
define('DB_DATABASE', 'formulaire'); // nom de la base
$connect = mysql_connect(DB_SERVER, DB_SERVER_USERNAME,
DB_SERVER_PASSWORD)
or die('Impossible to connect : ' . mysql_error());
mysql_select_db(DB_DATABASE, $connect);
$msg_erreur = "Error. Request fields:
<br/><br/>";
$msg_ok = "your request is sent.";
$message = $msg_erreur;
// vérification des champs
if (empty($_POST['gender']))
$message .= "your gender<br/>";
if (empty($_POST['name']))
$message .= "your name<br/>";
if (empty($_POST['address']))
$message .= "your address<br/>";
if (empty($_POST['zipcodde']))
$message .= "your zipcode<br/>";
if (empty($_POST['city']))
$message .= "your city<br/>";
if (empty($_POST['comments']))
$message .= "your message<br/>";
if (strlen($message) > strlen($msg_erreur)) {
echo $message;
} else {
foreach($_POST as $index => $valeur) {
$$index = mysql_real_escape_string(trim($valeur));
}
$interets = $_POST['interets'];
$sqlinterets = '';
for ($i=0; $i<count($interets); $i++)
{
$sqlinterets .= $interets[$i];
$sqlinterets .= ', ';
}
$sql = "INSERT INTO formulaire VALUES ('', '".$gender."', '".$name."',
'".$address."', '".$zipcode."', '".$city."', '".$country."',
'".$sqlinterests."', '".$comments."', now())";
$res = mysql_query($sql);
}
?>
<?php
$name = $_POST['gender'];
//this takes the data from input
$from = $_POST['name'];
$car = $_POST['address'];
echo "<table><tr><td>Name</td><td>From</td><td>Car</td></tr>
<tr><td>".$gender."</td><td>".$name."</td><td>".$address."</td></tr></table>";
?>