我是PHP新手,所以请考虑周到。
我正试图通过url将doc_id(在下面的代码中)传递到另一个页面。不幸的是,当我点击此链接时,地址栏中显示的是doc_id=
echo'<td><a href="view_profile.php?doc_id='.$row[doc_id].'" onclick="return confirm(''Do you wish to view this record?'');">View Profile</a></td>';
这个链接实际上适用于其他页面。我不明白为什么它对我现在正在使用的那个不起作用。有什么想法吗?
如有任何建议,我们将不胜感激。
那行是从这里来的:
if($SearchBySpec) { $query="SELECT * FROM doctor where specialization='$SearchBySpec'"; $result=mysql_query($query) or die('Error executing select query'.mysql_error());
echo'<table border="1" cellspacing="1">'; echo'<tr align="center">'; echo'<td bgcolor=#81F7D8 width="80" class="auto-style2"><strong>Specialization</strong></td>'; echo'<td bgcolor=#81F7D8 width="80" class="auto-style2"><strong>Last Name</strong></td>'; echo'<td bgcolor=#81F7D8 class="auto-style2" style="width: 103px"><strong>First Name</strong></td>'; echo'<td bgcolor=#81F7D8 width="80" class="auto-style2"><strong>Middle Initial</strong></td>'; echo'<td bgcolor=#81F7D8 width="90" class="auto-style2"><strong>School</strong></td>'; echo'<td bgcolor=#81F7D8 width="80" class="auto-style2"><strong>Hospital Assigned</strong></td>';
while($row=mysql_fetch_array($result)) { echo "<tr align=center>"; echo "<td>$row[specialization]"; echo "<td>$row[last_name]"; echo "<td>$row[first_name]"; echo "<td>$row[middle_name]"; echo "<td>$row[school]"; echo "<td>$row[hospital_assigned]";
}
//echo"<td><a href='view_profile.php?doc_id=".$row[doc_id]."'>View Profile</a></td>"; echo'<td><a href="view_profile.php?doc_id='.$row[doc_id].'" onclick="return confirm(''Do you wish to view this record?'');">View Profile</a></td>'; //echo'<td><a href="view_profile.php?doc_id='.$row[doc_id].'" onclick="return confirm(''Do you wish to view this record?'');">View Profile</a></td>'; echo "<tr><td>There are ". mysql_num_rows($result). " record(s)found.</td></tr>"; echo "</table>" ;
}
doc_id需要用引号括起来。
$row['doc_id'];
另外,您在哪里定义$row?如果是这样的话:
$row=$_GET; // or
$row['doc_id']=$_GET['doc_id'];
那你就没事了。
很明显,$row
变量没有doc_id
(顺便说一下,您应该引用它:$row['doc_id']
)。听起来这句话之前可能出了什么问题。尝试执行print_r($row)
来查看实际拥有的数据。
此外,请确保打开了错误报告功能。PHP试图通过忽略错误来对新用户过于友好——一开始很好,但最终只是对你隐藏了真正的问题。