0

我遇到的问题是,当提交表单但缺少字段时,我希望它说“您没有完成所有必填字段”,然后有一个返回表单的链接。但链接返回到表单但没有完整的字段,这是由于地址栏中未填充引用

例如,首先是表格地址 -

http://'192.168.1.251'/update.php?Reference=654321

然后在未完成字段后单击更新后-

http://'192.168.1.251'/update.php?Reference=.

这是页面上的代码,我遇到以下问题:(update_ac.php)

<?php

require_once('auth.php');

$host=""; // Host name 
$username=""; // Mysql username
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name=""; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
 mysql_select_db("$db_name")or die("cannot select DB");

 $Reference=$_POST['Reference'];
 $directly = $_POST['directly'];
 $behalfclient = $_POST['behalfclient'];
 $investigations = $_POST['investigations'];
 $injuries = $_POST['injuries'];
 $duties = $_POST['duties'];
 $Wherepain = $_POST['Wherepain'];
 $pain = $_POST['pain'];
 $aggravates = $_POST['aggravates'];
 $eases = $_POST['eases'];
 $Movement = $_POST['Movement'];
 $neural = $_POST['neural'];
 $UnderstandNPRS = $_POST['UnderstandNPRS'];
 $NPRSassessment = $_POST['NPRSassessment'];
 $yourhobbies = $_POST['yourhobbies'];
 $hobbiesaffected = $_POST['hobbiesaffected'];
 $social = $_POST['social'];
 $activities = $_POST['activities'];
 $lifestyle = $_POST['lifestyle'];
 $avoiddriving = $_POST['avoiddriving'];
 $grip = $_POST['grip'];
 $flashbacks = $_POST['flashbacks'];
 $braking = $_POST['braking'];
 $past = $_POST['past'];
 $psychologically = $_POST['psychologically'];
 $stomach = $_POST['stomach'];
 $dental = $_POST['dental'];
 $organs = $_POST['organs'];
 $genitals = $_POST['genitals'];
 $memory = $_POST['memory'];
 $scaring = $_POST['scaring'];
 $deformity = $_POST['deformity'];
 $eyes = $_POST['eyes'];
 $burns = $_POST['burns'];
 $head = $_POST['head'];
 $symptoms = $_POST['symptoms'];
 $otherchanges = $_POST['otherchanges'];
 $receivingtreatment = $_POST['receivingtreatment'];
 $surgery = $_POST['surgery'];
 $Impression = $_POST['Impression'];
 $management = $_POST['management'];
 $ifyes = $_POST['ifyes'];
 $Rehabilitation = $_POST['Rehabilitation'];
 $Number = $_POST['Number'];
 $Psychological = $_POST['Psychological'];
 $diagnostic = $_POST['diagnostic'];
 $notrequiretreatment = $_POST['notrequiretreatment'];
 $house = $_POST['house'];
 $recommendations = $_POST['recommendations'];
 $Prognosis = $_POST['Prognosis'];
 $CV = $_POST['CV'];
 $cervical = $_POST['cervical'];
 $heat = $_POST['heat'];
 $ice = $_POST['ice'];
 $lumbar = $_POST['lumbar'];
 $medication = $_POST['medication'];
 $posture = $_POST['posture'];
 $sport = $_POST['sport'];
 $given = $_POST['given'];
 $sceneaccident = $_POST['sceneaccident'];

 $sql="UPDATE Triage SET sceneaccident='$sceneaccident', notrequiretreatment='$notrequiretreatment', house='$house', recommendations='$recommendations', Prognosis='$Prognosis', CV='$CV', cervical='$cervical', heat='$heat', ice='$ice', lumbar='$lumbar', medication='$medication', posture='$posture', sport='$sport', given='$given' ,organs='$organs', deformity='$deformity', otherchanges='$otherchanges', receivingtreatment='$receivingtreatment', surgery='$surgery', Impression='$Impression', management='$management', ifyes='$ifyes', Rehabilitation='$Rehabilitation', Number='$Number', Psychological='$Psychological', diagnostic='$diagnostic', eyes='$eyes', burns='$burns', head='$head', symptoms='$symptoms', memory='$memory', scaring='$scaring', genitals='$genitals', dental='$dental', stomach='$stomach', directly='$directly', behalfclient='$behalfclient', investigations='$investigations', injuries='$injuries', duties='$duties', Wherepain='$Wherepain', pain='$pain', aggravates='$aggravates', eases='$eases', Movement='$Movement', neural='$neural', UnderstandNPRS='$UnderstandNPRS', NPRSassessment='$NPRSassessment', yourhobbies='$yourhobbies', hobbiesaffected='$hobbiesaffected', social='$social', activities='$activities', lifestyle='$lifestyle', avoiddriving='$avoiddriving', grip='$grip', flashbacks='$flashbacks', braking='$braking', past='$past', psychologically='$psychologically' WHERE Reference='$Reference'";
 $result=mysql_query($sql);


 // 
 while($rows=mysql_fetch_array($result)){
 echo '<a href="update.php?Reference='.$rows['Reference'].' ">update test</a>';
 }
// 

if (!$_REQUEST['sceneaccident'] || !$_REQUEST['notrequiretreatment'] || !$_REQUEST['house'] || !$_REQUEST['recommendations'] || !$_REQUEST['Prognosis'] || !$_REQUEST['CV'] || !$_REQUEST['cervical'] || !$_REQUEST['heat'] || !$_REQUEST['ice'] || !$_REQUEST['lumbar'] || !$_REQUEST['medication'] || !$_REQUEST['posture'] || !$_REQUEST['sport'] || !$_REQUEST['given'] || !$_REQUEST['organs'] || !$_REQUEST['deformity'] || !$_REQUEST['otherchanges'] || !$_REQUEST['receivingtreatment'] || !$_REQUEST['surgery'] || !$_REQUEST['Impression'] || !$_REQUEST['management'] || !$_REQUEST['ifyes'] || !$_REQUEST['Rehabilitation'] || !$_REQUEST['Number'] || !$_REQUEST['Psychological'] || !$_REQUEST['diagnostic'] || !$_REQUEST['eyes'] || !$_REQUEST['burns'] || !$_REQUEST['head'] || !$_REQUEST['symptoms'] || !$_REQUEST['memory'] || !$_REQUEST['scaring'] || !$_REQUEST['genitals'] || !$_REQUEST['dental'] || !$_REQUEST['stomach'] || !$_REQUEST['directly'] || !$_REQUEST['behalfclient'] || !$_REQUEST['investigations'] || !$_REQUEST['injuries'] || !$_REQUEST['duties'] || !$_REQUEST['Wherepain'] || !$_REQUEST['pain'] || !$_REQUEST['aggravates'] || !$_REQUEST['eases'] || !$_REQUEST['Movement'] || !$_REQUEST['neural'] || !$_REQUEST['UnderstandNPRS'] || !$_REQUEST['NPRSassessment'] || !$_REQUEST['yourhobbies'] || !$_REQUEST['hobbiesaffected'] || !$_REQUEST['social'] || !$_REQUEST['activities'] || !$_REQUEST['lifestyle'] || !$_REQUEST['avoiddriving'] || !$_REQUEST['grip'] || !$_REQUEST['flashbacks'] || !$_REQUEST['braking'] || !$_REQUEST['past'] || !$_REQUEST['psychologically'] )

{
 echo ('You did not complete all of the required fields');
 echo "<BR>";
 //while($rows==mysql_fetch_array($result)){
 echo "<a href='update.php?Reference={$rows['Reference']}.'>update</a>\n";
 }
// end of while loop 
else {
$sql = "UPDATE Triage SET completed='yes' WHERE Reference='$Reference'";
$result=mysql_query($sql); 
 echo "Successful";
 echo "<BR>";
 echo "<a href='list_records.php'>View result</a>";
 }

 ?> 
4

2 回答 2

0

Sql 更新从查询中返回 true 或 false。它不返回修改的行。更新后,您必须获得修改后的行:

$result=mysql_query("SELECT * FROM Triage WHERE Reference='$Reference'");
// and display result 
if($result){
    while($rows=mysql_fetch_array($result)){
        echo '<a href="update.php?Reference='.$rows['Reference'].' ">update test</a>';
    }
}
于 2013-11-07T11:46:15.990 回答
0

您正在尝试使用 UPDATE 语句从 mysql 中获取数据。UPDATE 将只返回 1 或 0。

您应该通过参数、会话或 cookie 将引用传递给脚本。您也可以从数据库中获取它,但您需要使用 SELECT 语句。

echo "<a href='update.php?Reference={$Reference}.'>update</a>\n";
于 2013-11-07T11:34:43.827 回答