Je suis novice en PHP et je crée un CMS de base en utilisant PHP et MySQL. J'ai du mal à obtenir les informations de la case à cocher de ma page HTML dans la base de données.Ajout de valeurs de cases à cocher binaires à la base de données MySQL en utilisant PHP
Comment puis-je faire apparaître les valeurs comme valeurs binaires 0 ou 1?
Le document HTML est écrit comme suit:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Create your news page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<fieldset>
<legend>Checked components will show in the page</legend>
<form method="POST" action="http://*********.php">
<span class="label">Header</span>
<input type="checkbox" name="header" value="HEADER">
<br>
<span class="label">Footer</span>
<input type="checkbox" name="footer" value="FOOTER">
<hr>
<span class="label">Local news</span>
<input type="checkbox" name="local" value="LOCALNEWS">
<br>
<span class="label">National news</span>
<input type="checkbox" name="national" value="NATIONALNEWS">
<br>
<span class="label">International news</span>
<input type="checkbox" name="international" value="INTERNATIONALNEWS">
<p>
<input type="submit">
</form>
</fieldset>
</body>
</html>
Le document PHP est écrit comme suit:
<?php
$user="user_***";
$password="*********";
$database="dbxyz";
mysql_connect("localhost", $user, $password);
mysql_select_db($database, $db_handle);
mysql_select_db("dbxyz");
if(isset($_POST['layout']))
{
foreach($_POST['layout'] as $value {
$insert="INSERT INTO layout (header, footer, local, national, international) VALUES ('$value')";
mysql_query($insert);
}
}
?>
Et oui, comme les affiches ont déjà dit, vous devez convertir la case à cocher valeurs à 1 ou 0, puis enregistrer dans un champ tinyint. –