MM学php求助各位帅哥 本帖最后由 gg1082963 于 2010-07-26 13:06:44 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你get和post没分清混杂在一起 连你自己都不知道get执行啥 post访问时执行啥吧标题为啥要突出你是mm?你有贴照片的打算吗 <?php if($_POST["submit2"]=="查询") { $txt_book=$_POST["text_book"]; $sql = mysql_query("select * from tb_student2 where bookname '%".trim($txt_book)."%'",$connID); $info = mysql_fetch_object($sql); echo "<table align=\"center\" width=\"600\" border=\"1\"><tr>"; while($info= mysql_fetch_object($sql)) { echo "<td>".$info->id."</td><td>".$info->bookname."</td><td>".$info->time."</td><td>".$info->price."</td><td>".$info->author."</td><td>".$info->press."</td></table>"; } }//if end ?> Undefined index: submit2 in D:\wamp\www\xishuophp\k1.php on line 24??这这么错误?猪头920 因为你第一次运行的时候$_POST["submit2"]还没有被设置,要等到点submit2这个按钮时$_POST["submit2"]才有值。这只是一个Warning信息,可以通过设置error_reporting(E_ALL ^ E_NOTICE);来屏蔽这个信息,但是如果想代码严谨的话,可以使用下面的方法isset判断:<?php$host="127.0.0.1";$userName="root";$password="";$dbName="test01";$connID=mysql_connect($host,$userName,$password);mysql_select_db($dbName,$connID);mysql_query("set names gbk");?><form name="form1" action="$_SERVER['PHP_SELF']" method="post"><p> <label>请输入图书的名称</label> <input type="text" size="20" name="text_book"> <input type="submit" name="submit2" value="查询"></p></form><?phpif(isset($_POST["submit2"]) && $_POST["submit2"] == "查询"){ $txt_book=$_POST["text_book"]; $sql = mysql_query("select * from tb_student2 where bookname like '%".trim($txt_book)."%'",$connID); $info = mysql_fetch_object($sql);}echo "<table align=\"center\" width=\"600\" border=\"1\"><tr>";while($info= mysql_fetch_object($sql)){ echo "<td>".$info->id."</td><td>".$info->bookname."</td><td>".$info->time."</td><td>".$info->price."</td><td>".$info->author."</td><td>".$info->press."</td></table>";}?> if(isset($_POST["submit2"]) && $_POST["submit2"]=="查询") <?phpif(isset($_POST["submit2"]) && $_POST["submit2"] == "查询"){ $txt_book=$_POST["text_book"]; $sql = mysql_query("select * from tb_student2 where bookname like '%".trim($txt_book)."%'",$connID); $info = mysql_fetch_object($sql);//这里是多余的}echo "<table align=\"center\" width=\"600\" border=\"1\"><tr>";while($info= mysql_fetch_object($sql)){ echo "<td>".$info->id."</td><td>".$info->bookname."</td><td>".$info->time."</td><td>".$info->price."</td><td>".$info->author."</td><td>".$info->press."</td></table>";}?> if也不对噢 不把后面的包括进来 sql变量也会报错的 lz貌似修改了帖子 另外,说自己MM的,要带ID贴一张照片才能算数! smarty和ecmall的互相嵌套 PHP5.3+MYSQL 配置问题 php如何写一个可以发布文章博客的那种编辑器啊 高手进来帮忙看下,哪里出问题了 ajax刷新后,怎么给用户提示 谁帮我推荐一个企业公司用的网站模板?谢谢 奇怪的问题 谁用过php全程序tiki161 v1.6.1 散分!代码解读! php7不支持e修饰符,代码该如何修改呢 处理一个二维数组的问题 求教:以前用php编程 现在要换 好不好
混杂在一起 连你自己都不知道get执行啥 post访问时执行啥吧标题为啥要突出你是mm?你有贴照片的打算吗
<?php
if($_POST["submit2"]=="查询")
{
$txt_book=$_POST["text_book"];
$sql = mysql_query("select * from tb_student2 where bookname '%".trim($txt_book)."%'",$connID);
$info = mysql_fetch_object($sql); echo "<table align=\"center\" width=\"600\" border=\"1\"><tr>";
while($info= mysql_fetch_object($sql))
{
echo "<td>".$info->id."</td><td>".$info->bookname."</td><td>".$info->time."</td><td>".$info->price."</td><td>".$info->author."</td><td>".$info->press."</td></table>";
}
}//if end
?>
这这么错误?猪头920
这只是一个Warning信息,可以通过设置error_reporting(E_ALL ^ E_NOTICE);来屏蔽这个信息,但是如果想代码严谨的话,可以使用下面的方法isset判断:
<?php
$host="127.0.0.1";
$userName="root";
$password="";
$dbName="test01";
$connID=mysql_connect($host,$userName,$password);
mysql_select_db($dbName,$connID);
mysql_query("set names gbk");
?>
<form name="form1" action="$_SERVER['PHP_SELF']" method="post">
<p>
<label>请输入图书的名称</label>
<input type="text" size="20" name="text_book">
<input type="submit" name="submit2" value="查询">
</p>
</form>
<?php
if(isset($_POST["submit2"]) && $_POST["submit2"] == "查询"){
$txt_book=$_POST["text_book"];
$sql = mysql_query("select * from tb_student2 where bookname like '%".trim($txt_book)."%'",$connID);
$info = mysql_fetch_object($sql);}
echo "<table align=\"center\" width=\"600\" border=\"1\"><tr>";
while($info= mysql_fetch_object($sql)){
echo "<td>".$info->id."</td><td>".$info->bookname."</td><td>".$info->time."</td><td>".$info->price."</td><td>".$info->author."</td><td>".$info->press."</td></table>";
}
?>
<?php
if(isset($_POST["submit2"]) && $_POST["submit2"] == "查询"){
$txt_book=$_POST["text_book"];
$sql = mysql_query("select * from tb_student2 where bookname like '%".trim($txt_book)."%'",$connID);
$info = mysql_fetch_object($sql);//这里是多余的}
echo "<table align=\"center\" width=\"600\" border=\"1\"><tr>";
while($info= mysql_fetch_object($sql)){
echo "<td>".$info->id."</td><td>".$info->bookname."</td><td>".$info->time."</td><td>".$info->price."</td><td>".$info->author."</td><td>".$info->press."</td></table>";
}
?>
lz貌似修改了帖子