你好 Stackflow 社区!我已经完成了 3 页,但仍然没有弄清楚。所以我有一个显示用户名的第一页(创建或检查是否存在),直到一切正常。
<form name="form1" action= "test3.php" method="post">
Please enter your Username: <input type = "Text" value ="" name = "username"><br />
<input name="cmd_submit" type="submit" id="submit" value="Submit" />
</form>
在此之后,正如“操作”所说,我有下一个 php,它检查记录是否存在并拉出一个表单。
<?php
if(isset($_POST['mode'])) {
$mode = implode(",", $_POST['mode']);
} else {
$mode = "";
}
?>
<?php
$dbhost = 'localhost';
$dbname = 'dbname';
$dbuser = 'dbuser';
$dbpass = 'dbpass';
$con = mysql_connect($dbhost, $dbuser, $dbpass);
if($con == FALSE)
{
echo 'Cannot connect to database' . mysql_error();
}
else
{
echo 'SUCCESS !';
}
mysql_select_db($dbname, $con);
// Get values from form
$username = mysql_escape_string($_POST['username']);
if(mysql_num_rows(mysql_query("SELECT * FROM email WHERE username = '".mysql_real_escape_string($_POST['username'])."'")))
{
echo '<form name="form1" action= "test41.php" method="post">
<table width="100%" >
Please select the category that you want to receive on your moval.edu e-mail account.<br /><br />
<b>Athletics:</b><br><br />
<b>MENS</b><br />
<input type="checkbox" name="mode[]" id="mode" value="Football">Football<br>
<input type="checkbox" name="mode[]" id="mode" value="Baseball">Baseball<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Basketball">Basketball<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Cheer">Cheer<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Cross Country">Cross Country<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Golf">Golf<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Lacrosse">Lacrosse<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Rodeo">Rodeo<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Soccer">Soccer<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Tennis">Tennis<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Track">Track<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Volleyball">Volleyball<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Wrestling">Wrestling<br><br />
<b>WOMENS</b><br />
<input type="checkbox" name="mode[]" id="mode" value="Womens Basketball">Basketball<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Cheer">Cheer<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Cross Country">Cross Country<br>
<input type="checkbox" name="mode[]" id="mode" value="Dance">Dance<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Golf">Golf<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Lacrosse">Lacrosse<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Rodeo">Rodeo<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Soccer">Soccer<br>
<input type="checkbox" name="mode[]" id="mode" value="Softball">Softball<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Tennis">Tennis<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Track">Track<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Volleyball">Volleyball<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Wrestling">Wrestling<br><br />
<b>STUDENT AFFAIRS ACIVITIES</b><br><br />
<input type="checkbox" name="mode[]" id="mode" value="Student Affairs"> Sign me up for Student Affairs Activities<br /><br />
<b>INTERNAIONAL CLUB ACTIVITIES</b><br /><br />
<input type="checkbox" name="mode[]" id="mode" value="International Club"> Sign me up for International Club Activities<br /><br />
<b>HISTORICAL ACTIVITIES</b><br><br />
<input type="checkbox" name="mode[]" id="mode" value="Historical Activities"> Sign me up for Hisorical Activities<br /><br />
<b>CONTESTS</b><br><br />
<input type="checkbox" name="mode[]" id="mode" value="Contests"> Sign me up for Contests<br /><br />
<b>LIBRARY EVENTS</b><br><br />
<input type="checkbox" name="mode[]" id="mode" value="Library Events"> Sign me up for Library Evens<br /><br />
<b>VIKING EXCHANGE</b><br /><br />
<input type="checkbox" name="mode[]" id="mode" value="Viking Exchange"> Sign me up for Viking Exchange News<br /><br />
</table>
<input name="cmd_submit" type="submit" id="submit" value="Submit" />
</form>';
}
else
{
$sql="INSERT INTO email(username, mode) VALUES('$username', '$mode')";
$result=mysql_query($sql);
echo '<form name="form1" action= "test41.php" method="post">
<table width="100%" >
Please select the category that you want to receive on your moval.edu e-mail account.<br /><br />
<b>Athletics:</b><br><br />
<b>MENS</b><br />
<input type="checkbox" name="mode[]" id="mode" value="Football">Football<br>
<input type="checkbox" name="mode[]" id="mode" value="Baseball">Baseball<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Basketball">Basketball<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Cheer">Cheer<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Cross Country">Cross Country<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Golf">Golf<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Lacrosse">Lacrosse<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Rodeo">Rodeo<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Soccer">Soccer<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Tennis">Tennis<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Track">Track<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Volleyball">Volleyball<br>
<input type="checkbox" name="mode[]" id="mode" value="Mens Wrestling">Wrestling<br><br />
<b>WOMENS</b><br />
<input type="checkbox" name="mode[]" id="mode" value="Womens Basketball">Basketball<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Cheer">Cheer<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Cross Country">Cross Country<br>
<input type="checkbox" name="mode[]" id="mode" value="Dance">Dance<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Golf">Golf<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Lacrosse">Lacrosse<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Rodeo">Rodeo<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Soccer">Soccer<br>
<input type="checkbox" name="mode[]" id="mode" value="Softball">Softball<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Tennis">Tennis<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Track">Track<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Volleyball">Volleyball<br>
<input type="checkbox" name="mode[]" id="mode" value="Womens Wrestling">Wrestling<br><br />
<b>STUDENT AFFAIRS ACIVITIES</b><br><br />
<input type="checkbox" name="mode[]" id="mode" value="Student Affairs"> Sign me up for Student Affairs Activities<br /><br />
<b>INTERNAIONAL CLUB ACTIVITIES</b><br /><br />
<input type="checkbox" name="mode[]" id="mode" value="International Club"> Sign me up for International Club Activities<br /><br />
<b>HISTORICAL ACTIVITIES</b><br><br />
<input type="checkbox" name="mode[]" id="mode" value="Historical Activities"> Sign me up for Hisorical Activities<br /><br />
<b>CONTESTS</b><br><br />
<input type="checkbox" name="mode[]" id="mode" value="Contests"> Sign me up for Contests<br /><br />
<b>LIBRARY EVENTS</b><br><br />
<input type="checkbox" name="mode[]" id="mode" value="Library Events"> Sign me up for Library Evens<br /><br />
<b>VIKING EXCHANGE</b><br /><br />
<input type="checkbox" name="mode[]" id="mode" value="Viking Exchange"> Sign me up for Viking Exchange News<br /><br />
</table>
<input name="cmd_submit" type="submit" id="submit" value="Submit" />
</form>';
}
//if (!mysql_query($sql, $con))
//{
// die('Error: ' . mysql_error());
//}
echo "You username has been added.";
mysql_close($con)
?>
直到这里一切正常,现在我的问题是:在拉出此表单后,我希望他将其保存在连接的用户中,因此如果存在,则将其保存在该用户名上,如果不存在(应该创建)创建它并以下次显示他们“检查”检查的复选框的方式保存信息,并根据需要修改该信息,并且每次都提取“检查”的信息。等等。
所以我在这里有另一个代码用于第二种形式(复选框)的操作。
<?php
if(isset($_POST['mode'])) {
$mode = implode(",", $_POST['mode']);
} else {
$mode = "";
}
?>
<?php
$dbhost = 'localhost';
$dbname = 'website';
$dbuser = 'Test';
$dbpass = 'password1';
$con = mysql_connect($dbhost, $dbuser, $dbpass);
if($con == FALSE)
{
echo 'Cannot connect to database' . mysql_error();
}
else
{
echo 'SUCCESS !';
}
mysql_select_db($dbname, $con);
// Get values from form
$sql="INSERT INTO email(mode) VALUES('$mode')";
$result=mysql_query($sql);
if (!mysql_query($sql, $con))
{
die('Error: ' . mysql_error());
}
echo "You info has been submitted.";
mysql_close($con)
?>
谢谢,如果我在某些时候没有解释自己,请很好,让我知道,我愿意在评论中编辑或解释它。