【发布时间】:2013-06-05 11:26:29
【问题描述】:
这里有一个简单的代码,我使用了 2 个带有显示和隐藏的表单,所以一切都很好,我只是错过了使用第二种表单在不同的桌子上设置 CL_ID
所以我在这里需要什么只是插入该行结果.$row['cl_id']. 我在第一个查询中得到的内容被插入到第二个表单中什么是正确的并保存了数据'
我试过把它调高或调低我的所有问题都是($row= mysql_fetch_assoc($data))的“未定义变量”和其他“未定义索引”原因@
我尝试了所有方法,但我发现定义了它应该是的变量 ($row= mysql_fetch_assoc($data)) { only here } 数组未达到的任何其他地方不可读
<?php
echo"<style type='text/css'>#here{ display:none; } </style> ";
require ('connections.php');
echo"<hr />";
if(isset($_POST['search'])) {
$search=(trim($_POST['search']));
if (empty($search)){echo" insert something to search it ";
} else{
$data=mysql_query("SELECT * from cl_info INNER JOIN cl_pro ON cl_pro.cl_id=cl_info.id WHERE cl_info.id LIKE '$search'")or die(mysql_error());
$num=mysql_num_rows($data);
if($num<1){echo' no results of your search'; }
else{?> <style type="text/css">#form1{ display:none; }</style>
<style type="text/css">#here{ display:block; }</style>
<?php
while ($row= mysql_fetch_assoc($data)) {
//$ak=($row['cl_id']) ;
// echo("<hr/>");
// echo("$ak");
echo("<table with='40%'border='1' align='center'>
<tr>
<th> Client ID</th>
<th> Name</th>
<th> Phone</th>
<th> Date of Birth</th>
<th> Blood Type</th>
<th> E-mail</th>
<th> smoker</th>
<th> drugs</th>
<th> extra</th>
<th> extra2</th>
</tr>
<tr>
<td>".$row['cl_id']."</td>
<td>".$row['name']."</td>
<td>".$row['phon']."</td>
<td>".$row['d_birth']."</td>
<td>".$row['blood_typ']."</td>
<td>".$row['email']."</td>
<td>".$row['smoker']."</td>
<td>".$row['drugs']."</td>
<td>".$row['extra']."</td>
<td>".$row['extra2']."</td>
</tr> ") ; echo"</table>";
} } } }
echo" where it was form 1
<form id='form1' action='' method='post'>
<input type='text' name='search' />
<input type='submit' name='sub' /> </form>
" ;
/////// start open new form2 "here "//////
echo"
<form id='here' action='' method='post' >
r: <input type='text' name='r' />
Doz :<input type='text' name='doz' />
Time:<input type='text' name='t/d' />
Date <input type='text' name='date' />
<input type='hidden' name='cl_id' />
<input type='submit' name='submit' value='Insert' />
</form> ";
if (isset($_REQUEST['submit'])){
//if (isset($_POST['submit'])){
echo('you have isset works right');
$r =$_POST['r'];
$doz =$_POST['doz'];
$t =$_POST['t/d'];
$date =$_POST['date'] ;
//$clid =$_POST['cl_id'] ;
mysql_query ("INSERT INTO scri (id, cl_id, r, doz, time, date) VALUES ('', '$ak', '$r', '$doz', '$t', '$date')")or die ( mysql_error());
}
?> <!---- end of PHP ---->
</body>
</html>
【问题讨论】:
-
你能附和这个吗? mysql_fetch_assoc($data)) $data里面是什么?
-
@Marijke 我可以得到结果,一切都很好,只是 CL_id 没有插入第二个表单
-
这是因为 $ak 是空的,在你的代码中看这个: while ($row= mysql_fetch_assoc($data)) { //$ak=($row['cl_id']) ; // echo("
"); // echo("$ak"); -
@Marijke 当我使用 echo 它的作品时,我可以看到结果,但它无法插入到第二个表单中
-
然后试试这个:mysql_query ("INSERT INTO scri (id, cl_id, r, doz, time, date) VALUES ('', ".$row['cl_id'].", ". $r.", ".$doz.", ".$t.", ".$date.")") 或死 (mysql_error());