search
HomeBackend DevelopmentPHP Tutorialphp查询数据库表问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>学生课题查询</title><style type="text/css"><!--.STYLE1 {font-size: 14px}--></style></head><body><?php//######################学生查询所选课题########################## include "config.php"; include "header.php";?> <?if($search){  if ($xuehao=="")  {	echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>请填写您的学号!</big></b></font></p>";	echo "<meta http-equiv=\"refresh\" content=\"1;url=query.php\">";	exit;	 }    $query="select * from $student_table where xuehao='$xuehao'"; mysql_query("set names 'gb2312'"); $result=mysql_query($query); $row=mysql_fetch_array($result); if($row==0) {	echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>你还没有注册,或者你的输入有误,请重新输入!</big></b></font></p>";	echo "<meta http-equiv=\"refresh\" content=\"2;url=query.php\">";    exit; }  $query="select id as sm from $student_table where xuehao='$xuehao'"; mysql_query("set names 'gb2312'"); $result=mysql_query($query); $row=mysql_fetch_array($result); if($row[sm]==0) {	echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>你还没有选择课题,请去选题!</big></b></font></p>";	echo "<meta http-equiv=\"refresh\" content=\"2;url=keti_list.php\">";    exit; } ?><table width="700" border="0" cellspacing="1" cellpadding="0" bgcolor="#333333" align="center">  <tr>   <td width="78" height="30" bgcolor="#FFFFFF">       <div align="center" class="text">         <p class="STYLE1">学生学号</p>      </div>    </td>    <td width=97 height="30" bgcolor="#FFFFFF">       <div align="center" class="STYLE1">学生姓名</div>    </td>    <td width="329" height="30" bgcolor="#FFFFFF">     <div align="center" class="STYLE1"> 课题名称 </div>    </td>    <td width=106 height="30" bgcolor="#FFFFFF">       <div align="center" class="STYLE1">指导教师</div>    </td>    <td width=84 height="30" bgcolor="#FFFFFF">     <div align="center" class="STYLE1">职称</div>    </td>  </tr>   <?   $n=0;    $query=mysql_query("select * from $jiaoshi_table,$student_table where $jiaoshi_table.id=$student_table.id and $student_table.xuehao='$xuehao'");   mysql_query("set names 'gb2312'");   while($row=mysql_fetch_array($query)){        if(($n%2)!='0'){ 	  echo "<tr bgcolor=#FFFFff>";}	  else{	  echo "<tr bgcolor=#E4E4E4>";	  }     echo"	 <td   height='22' class='STYLE1'> <div align='center'>".$row['xuehao']."</div></td>	 <td   height='22'> 		<div align='center' class='STYLE1'>".$row['name']."</div></td>    <td   height='22' class='STYLE1'> <div align='center'>".$row['subject']."</div></td>    <td   height='22' class='STYLE1'> <div align='center'>".$row['teacher']."</div></td>	<td   height='22' class='STYLE1'> <div align='center'>".$row['zhicheng']."</div></td>  </tr> ";   $n++;   } ?></table> <p> </p><?php include "foot.php";?>

当我输入学号查询的时候,运行结果却是一堆乱七八糟的东西。。。
注:我的表名叫做teacher,student


回复讨论(解决方案)

你截的图看看       

你截的图看看       

你截的图看看       
哇塞,版主亲自回复。偶表示好激动地说。

你没开启段标签
  改成

你没开启段标签
  改成

你没开启段标签
  改成

你代码到91行之前都在执行,你就不能开全了吗
      $n=0;    $query=mysql_query("select * from $jiaoshi
这里还有一个,你没改成

你代码到91行之前都在执行,你就不能开全了吗
      $n=0;    $query=mysql_query("select * from $jiaoshi
这里还有一个,你没改成<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>学生课题查询</title><style type="text/css"><!--.STYLE1 {font-size: 14px}--></style></head><body><?php//######################学生查询所选课题########################## include "config.php"; include "header.php";?><?phpif($search){ if ($xuehao=="") { echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>请填写您的学号!</big></b></font></p>"; echo "<meta http-equiv=\"refresh\" content=\"1;url=query.php\">"; exit; } $query="select * from $student_table where xuehao='$xuehao'"; mysql_query("set names GB2312"); $result=mysql_query($query); $row=mysql_fetch_array($result); if($row==0) { echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>你还没有注册,或者你的输入有误,请重新输入!</big></b></font></p>"; echo "<meta http-equiv=\"refresh\" content=\"2;url=query.php\">"; exit; } $query="select id as sm from $student_table where xuehao='$xuehao'"; mysql_query("set names 'GB2312'"); $result=mysql_query($query); $row=mysql_fetch_array($result); if($row[sm]==0) { echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>你还没有选择课题,请去选题!</big></b></font></p>"; echo "<meta http-equiv=\"refresh\" content=\"2;url=keti_list.php\">"; exit; } ?><table width="700" border="0" cellspacing="1" cellpadding="0" bgcolor="#333333" align="center"> <tr> <td width="78" height="30" bgcolor="#FFFFFF"> <div align="center" class="text"> <p class="STYLE1">学生学号</p> </div> </td> <td width=97 height="30" bgcolor="#FFFFFF"> <div align="center" class="STYLE1">学生姓名</div> </td> <td width="329" height="30" bgcolor="#FFFFFF"> <div align="center" class="STYLE1"> 课题名称 </div> </td> <td width=106 height="30" bgcolor="#FFFFFF"> <div align="center" class="STYLE1">指导教师</div> </td> <td width=84 height="30" bgcolor="#FFFFFF"> <div align="center" class="STYLE1">职称</div> </td> </tr> <?php $n=0; $query=mysql_query("select * from $jiaoshi_table,$student_table where $jiaoshi_table.id=$student_table.id and $student_table.xuehao='$xuehao'"); mysql_query("set names GB2312"); while($row=mysql_fetch_array($query)){ if(($n%2)!='0'){ echo "<tr bgcolor=#FFFFff>";} else{ echo "<tr bgcolor=#E4E4E4>"; } echo" <td height='22' class='STYLE1'> <div align='center'>".$row['xuehao']."</div></td> <td height='22'> <div align='center' class='STYLE1'>".$row['name']."</div></td> <td height='22' class='STYLE1'> <div align='center'>".$row['subject']."</div></td> <td height='22' class='STYLE1'> <div align='center'>".$row['teacher']."</div></td> <td height='22' class='STYLE1'> <div align='center'>".$row['zhicheng']."</div></td> </tr> "; $n++; } ?></table> <p> </p><?php include "foot.php";?>

if($search)
{

这个if没有关闭,即少了 } 号

if($search)
{

这个if没有关闭,即少了 } 号 好,我看看

if($search)
{

这个if没有关闭,即少了 } 号 是加在48行后吗?我加了以后就变成这样了

是加在48行后吗?
 我不知道你的逻辑,你自己应该很清楚啊。

$search 和 $xuehao 你在哪定义的?

是加在48行后吗?
 我不知道你的逻辑,你自己应该很清楚啊。

$search 和 $xuehao 你在哪定义的? 不太清楚啊,因为这个代码老师给的让做修改……

最后缺了个分号


include "foot.php";?>

最后缺了个分号


include "foot.php";?> 有分号啊

……  楼主这错误看着太头晕,建议你用eclipse什么的去检查一下,丢的东西有点多啊

……  楼主这错误看着太头晕,建议你用eclipse什么的去检查一下,丢的东西有点多啊 说我的最后一行是语法错误,unexpected 'EOF'这是什么意思?


最后缺了个分号


include "foot.php";?> 有分号啊

你上面贴的代码里没有


……  楼主这错误看着太头晕,建议你用eclipse什么的去检查一下,丢的东西有点多啊 说我的最后一行是语法错误,unexpected 'EOF'这是什么意思?

你那少了一个括号的括回,仔细检查一下代码吧。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

HTTP Method Verification in LaravelHTTP Method Verification in LaravelMar 05, 2025 pm 04:14 PM

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building

Discover File Downloads in Laravel with Storage::downloadDiscover File Downloads in Laravel with Storage::downloadMar 06, 2025 am 02:22 AM

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function