新手,轻拍. 各位大哥大姐们帮我看一下这段php代码问题出在哪

php中文网
发布: 2016-06-23 14:02:30
原创
1197人浏览过

Html Code:






 Rep Num: 



 Rep Num: 
Last Name:  First Name: 
Street:  City:  
State:  Zip: 
Commission:  Rate: 



 Rep Num: 



 Rep Num: 
Last Name:  First Name: 
Street:  City:  
State:  Zip: 
Commission:  Rate: 







[/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 tableif ($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>
                    <div class="aritcle_card">
                        <a class="aritcle_card_img" href="/ai/1365">
                            <img src="https://img.php.cn/upload/ai_manual/000/000/000/175679975740787.png" alt="腾讯云AI代码助手">
                        </a>
                        <div class="aritcle_card_info">
                            <a href="/ai/1365">腾讯云AI代码助手</a>
                            <p>基于混元代码大模型的AI辅助编码工具</p>
                            <div class="">
                                <img src="/static/images/card_xiazai.png" alt="腾讯云AI代码助手">
                                <span>98</span>
                            </div>
                        </div>
                        <a href="/ai/1365" class="aritcle_card_btn">
                            <span>查看详情</span>
                            <img src="/static/images/cardxiayige-3.png" alt="腾讯云AI代码助手">
                        </a>
                    </div>
                <p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>\n";	}}}function add_rep(){}function delete_rep(){}function update_rep(){}?></html>
登录后复制


可以连接到mySQL服务器上, 但是不能显示结果...


回复讨论(解决方案)

error_reporting(E_ALL & ~E_NOTICE);
改作
error_reporting(E_ALL);
可能就知道了

把 $row 的关联键改成小写看看

error_reporting(E_ALL & ~E_NOTICE);
改作
error_reporting(E_ALL);
可能就知道了

把 $row 的关联键改成小写看看

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

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

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

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

那应该怎么改呢?
html文件:

 Rep Num: 

难道不是将input type设置成为"submit"就可以了吗?

加一个隐藏的  input






改为





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






改为

Thanks a lot!!!

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号