我不知道为什么我会得到这个。我没有在这个网页中处理这些变量,所以我不确定为什么会向我提出这些变量。
添加好的脚本。我认为问题是我的函数文件已经运行了建立连接所需的行,因此每个包含都会导致它再次发生。有什么办法可以简化?谢谢
Notice: Constant DB_HOST already defined in C:\xampp\htdocs\cw1\db_config.php on line 2
Notice: Constant DB_NAME already defined in C:\xampp\htdocs\cw1\db_config.php on line 3
Notice: Constant DB_USER already defined in C:\xampp\htdocs\cw1\db_config.php on line 4
Notice: Constant DB_PASSWORD already defined in C:\xampp\htdocs\cw1\db_config.php on line 5
Notice: Constant DB_HOST already defined in C:\xampp\htdocs\cw1\db_config.php on line 2
Notice: Constant DB_NAME already defined in C:\xampp\htdocs\cw1\db_config.php on line 3
Notice: Constant DB_USER already defined in C:\xampp\htdocs\cw1\db_config.php on line 4
Notice: Constant DB_PASSWORD already defined in C:\xampp\htdocs\cw1\db_config.php on line 5
?php include 'mefunc.php'; include 'memberfunc.php'; include 'eventfunc.php'; //include the lot they are all needed!
?php include 'mefunc.php'; include 'memberfunc.php'; include 'eventfunc.php'; //include the lot they are all needed!
$db1 = new dbme();
$db1->openDB();
$sql="select mid from member";
$result=$db1->getResult($sql);// get the ids from the tables for the select
$sql1="select ename from event";
$result1=$db1->getResult($sql1);// get the ids from the tables for the select
if (!$_POST) //page loads for the first time
{
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return validateForm( );">
Select Member ID: <select name="mid">
<?php
while($row = mysql_fetch_assoc($result))
echo "<option value='{$row['mid']}'>{$row['mid']} </option>";
?>
</select>
<br />
Select Event name : <select name="ename">
<?php
while($row = mysql_fetch_assoc($result1))
echo "<option value='{$row['ename']}'>{$row['ename']} </option>";
?>
</select>
<br />
<script language="javascript">
function validateField( fld ) { //validation of all forms. The field will change colour if wrong.
var field = document.getElementById( fld );
if( !field ) return true;
var error = field.value != '';
if( error ) {
field.style.backgroundColor = 'White';
} else {
field.style.backgroundColor = 'Orange';
}
return error;
}
function validateForm( ) {
var cont = true;
if( !validateField( 'total' ) ) cont = false;
if( !validateField( 'comments' ) ) cont = false;
return cont;
}
</script>
Enter lifter total:<input type="text" name="total" id="total" /><br />
Enter comment:<input type="text" name="comments" id="comments"/><br />
<input type="submit" value="Save" />
</form>
<?php
}
else//post it into database
{
//$mid = $_POST['mid'];//??
$mid = $_POST['mid'];
$total = $_POST['total'];
$comments = $_POST['comments'];
$ename = $_POST['ename'];
$db1 = new dbme();
$db1->openDB();
$numofrows = $db1->insert_me($mid, $total, $comments, $ename);
echo "Success. Number of rows affected:
<strong>{$numofrows}<strong>";
$db1->closeDB();
}
$db1 = new dbmember();//show members to see
$db1->openDB();
$sql="SELECT * from member";
$result=$db1->getResult($sql);
echo "<table border='1'>";
echo "<tr><th>Member ID</th><th>Name</th>";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>{$row['mid']}</td><td>{$row['name']}</td>";
echo "</tr>";
}
echo "</table>";
$db1->closeDB();
$db1 = new dbevent();//now show events to see too
$db1->openDB();
$sql="SELECT * from event";
$result=$db1->getResult($sql);
echo "<table border='1'>";
echo "<tr><th>Event ID</th><th>Event Name</th><th>Date</th>";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>{$row['eid']}</td><td>{$row['ename']}</td>";
echo "<td>{$row['date']}</td>";
echo "</tr>";
}
echo "</table>";
$db1->closeDB();
?>