查看: 830|回复: 3
|
PHP简单的疑问!!!
[复制链接]
|
|
请问我要如何写才能够让输入Quanlity时, 例如输入1, 按submit显示001 ; 输入18, 按submit显示018 ? 谢谢!
<?php
session_start();
$_SESSION['Name'] = $_POST['Name'];
$_SESSION['sex'] = $_POST['sex'];
$_SESSION['quantity'] = $_POST['quantity'];
?>
<html>
<head>
<title>Testing</title>
<meta http-equiv="Content-Type" c>
<head>
<body>
<?php
function CheckBoxValue($chekboxvalue) {
if (isset($_POST["hobby1"])) {
$ArrayOfSelection = $_POST["hobby1"];
for ($x = 0; $x < count($ArrayOfSelection); $x++) {
if ($ArrayOfSelection[$x] == $chekboxvalue) {
echo ("CHECKED");
break;
}
}
}
}
?>
<?php
if ($_POST['change'] == 'change') {
if (isset($_POST['Hobby']) && !empty($_POST['Hobby'])) {
$hobby = stripslashes($_POST['Hobby']);
$hobby = unserialize($hobby);
for($i=0;$i<3;$i++) {
if ($hobby[$i]=='Gaming') {
$temp = $hobby[$i];
$hobby[$i] = $hobby[0];
$hobby[0] = $temp;
}
if ($hobby[$i]=='Cooking') {
$temp = $hobby[$i];
$hobby[$i] = $hobby[1];
$hobby[1] = $temp;
}
if ($hobby[$i]=='Swimming') {
$temp = $hobby[$i];
$hobby[$i] = $hobby[2];
$hobby[2] = $temp;
}
}
foreach($hobby as $key => $val) {
if (empty($val)) {
unset($hobby[$key]);
}
}
}
}
if (isset($_POST['quantity'])) {
$quantity= $_POST['quantity'];
settype($quantity,integer);
}
if ($_POST['submit'] == 'submit')
{
if (($_POST["Name"]!="")&&($_POST["hobby1"]!="")&&($_POST["sex"]!=""))
{
if(($_POST["quantity"]!="")&&(ereg ("(^[1-9])",$quantity)))
{
$Name=$_POST['Name'];
$sex=$_POST['sex'];
if($_POST["hobby1"])
{
foreach($_POST['hobby1'] as $value)
{
$hobby2=join (', ', $_POST['hobby1']);
}
$serializeHobbies = serialize($_POST["hobby1"]);
}
echo
(" Name: $Name<br>
Hobby: $hobby2<br>
Sex: $sex<br>
Quantity: $quantity");
echo
("<form name='frmtest' method = 'post' action='test.php'>
<input type = 'hidden' name = 'Name' value = '$Name'>
<input type = 'hidden' name = 'sex' value = '$sex'>
<input type = 'hidden' name = 'quantity' value = '$quantity'>
<input type = 'hidden' name = 'Hobby' value = '$serializeHobbies'>
<br>
<input type = 'submit' name = 'change' value = 'change'>
</form>");
exit;
}
else
{
$error1="Quantity Cannot Empty/Only Number!!!";
}
}
else
{$error="Cannot Empty!!!";}
}
?>
<?php echo $error;?><?php echo $error1;?>
<form name="frmtest" method="post" action="test.php">
<p>
<strong>Name:</strong>
<input type="text" name="Name" value="<?php echo $_SESSION['Name'] ?>">
<br>
<br>
<strong>Hobby:</strong><br>
<input name="hobby1[]" type="checkbox" value="Gaming" <?php CheckBoxValue("Gaming"); ?><?php if (isset($hobby[0])) echo "checked"; ?>>
Gaming
<input name="hobby1[]" type="checkbox" value="Cooking" id="hobby1" <?php CheckBoxValue("Cooking"); ?><?php if (isset($hobby[1])) echo "checked"; ?>>
Cooking
<input name="hobby1[]" type="checkbox" value="Swimming"<?php CheckBoxValue("Swimming"); ?> <?php if (isset($hobby[2])) echo "checked"; ?>>
Swimming
<p><strong>Sex:</strong><br>
<input type="radio" name="sex" value="M"<?php echo (($_SESSION['sex'] == "M")?"CHECKED":""); ?>>
Male
<input type="radio" name="sex" value="F"<?php echo (($_SESSION['sex'] == "F")?"CHECKED":""); ?>>
Female<br>
<br>
<strong>Quantity:</strong><br>
<input name="quantity" type="text" size="3" maxlength="3" value="<?php echo $_SESSION['quantity'] ?>">
<br>
<br>
<hr><br>
<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html> |
|
|
|
|
|
|
|
发表于 19-12-2007 08:44 AM
|
显示全部楼层
str_pad  |
|
|
|
|
|
|
|

楼主 |
发表于 19-12-2007 08:28 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 19-12-2007 09:58 PM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|