Html Code:<html><head>
<body><form action="sales_rep_m.php" method="post"> Rep Num: <input name="rep_num" type="int">
<input type="submit" value="Search">
</form><form action="sales_rep_m.php" method="post"> Rep Num: <input name="rep_num" type="int">
Last Name: <input name="last_name" type="varchar"> First Name: <input name="first_name" type="varchar">
Street: <input name="street" type="varchar"> City: <input name="city" type="varchar"> 
State: <input name="state" type="varchar"> Zip: <input name="zip" type="int">
Commission: <input name="commission" type="float"> Rate: <input name="rate" type="float">
<input type="submit" value="Add">
</form><form action="sales_rep_m.php" method="post"> Rep Num: <input name="rep_num" type="int">
<input type="submit" value="Delete">
</form><form action="sales_rep_m.php" method="post"> Rep Num: <input name="rep_num" type="int">
Last Name: <input name="last_name" type="varchar"> First Name: <input name="first_name" type="varchar">
Street: <input name="street" type="varchar"> City: <input name="city" type="varchar"> 
State: <input name="state" type="varchar"> Zip: <input name="zip" type="int">
Commission: <input name="commission" type="float"> Rate: <input name="rate" type="float">
<input type="submit" value="Update">
</form></body></html>[/code]
PHP code:<html>
<head>
<title>Sales Rep Maintenance</title>
</head>
<?php
// Address error handlingini_set('display_errors',1);
error_reporting(E_ALL & ~E_NOTICE);// Attempt to Connectif ($connection = @mysql_connect ('localhost', '***', '***')){
print '<p>Successfully connected to MySQL.</p>';
//mysql_close(); // close the connection
}
else {
die('<p>Could not connect to MySQL because: <b>' .mysql_error() .
'</b></p>');
}
if (@mysql_select_db("PREMIERE", $connection)){
print '<p>The PREMIERE database has been selected.</p>';
}
else {
die('<p>Cound not select the PREMIERE database because: <b>' .mysql_error().'</b></p>');
}if(!$_REQUEST['submit'])
{
generate_form();
}
else if($_REQUEST['submit'] == "Search")
{
search_rep();
}
else if($_REQUEST['submit'] == "Add")
{
add_rep();
}
else if($_REQUEST['submit'] == "Delete")
{
delete_rep();
}
else if($_REQUEST['submit'] == "Update")
{
update_rep();
}function generate_form()
{
}function search_rep()
{
// Define the rep Number php variable name
$rep = $_POST['rep_num'];
print "The rep num chosen was $rep<br/>";// Define the query
$query = "SELECT * FROM REP WHERE CUSTOMER_NUM = '$rep'";
// Output the resulting query table
if ($r = mysql_query($query))
{
while ($row = mysql_fetch_array($r))
{
print "<p>{$row['REP_NUM']}<br/>{$row['LAST_NAME']}<br/>{$row['FIRST_NAME']}<br/>
{$row['STREET']}<br/>{$row['CITY']}<br/>{$row['STATE']}<br/>{$row['ZIP']}<br/>
{$row['COMMISSION']}<br/>{$row['RATE']}<br/></p>\n";
}
}
}function add_rep()
{
}function delete_rep()
{
}function update_rep()
{
}?>
</html>
可以连接到mySQL服务器上, 但是不能显示结果...phpfunctionmysqlquery

解决方案 »

  1.   

    error_reporting(E_ALL & ~E_NOTICE);
    改作
    error_reporting(E_ALL);
    可能就知道了把 $row 的关联键改成小写看看
      

  2.   


    我试了, 错误提示为:
    Undefined index: submit ... on line 28
    Undefined index: submit ... on line 33
      

  3.   

    28行是 if(!$_REQUEST['submit']) 接受的是表单提交的数据
    但你的表单中并没有名为 submit 的控件
      

  4.   

    楼上正解,给type为submit的input加name=submit
      

  5.   


    那应该怎么改呢?
    html文件:
    <form action="sales_rep_m.php" method="post"> Rep Num: <input name="rep_num" type="int">
    <input type="submit" value="Search">
    难道不是将input type设置成为"submit"就可以了吗?
      

  6.   

    加一个隐藏的  input<input type="hidden" name="submit" value="search" />
      

  7.   


    <input type="submit" value="Search">
    <input type="submit" value="Add">
    <input type="submit" value="Delete">
    <input type="submit" value="Update">
    改为
    <input type="submit" name="submit" value="Search">
    <input type="submit" name="submit" value="Add">
    <input type="submit" name="submit" value="Delete">
    <input type="submit" name="submit" value="Update">一般的情况下,input type设置成为"submit"就可以了。但未命名的提交按钮的值是不会被提交的
    但是在你的应用中,是靠提交的值按钮来决定操作方式的,所以一定要命名