简体   繁体   中英

update a form after all fields not being completed

the issue im having is that when a form is submitted but there are fields missing, i want it to say 'You did not complete all of the required fields' and then have a link back to the form. but the link goes back to the form but without the completed fields, which is due to the refernce not being populated in the address bar

eg address for form at first -

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

then after clicking update after fields not being completed -

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

here is the code on the page im having an issue with below: (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>";
 }

 ?> 

You are trying to grab data from mysql using an UPDATE statement. UPDATE will return 1 or 0 only.

You should be passing the Reference to the script via argument, session, or cookies. You can also grab it from the database, but you will need to use a SELECT statement.

echo "<a href='update.php?Reference={$Reference}.'>update</a>\n";

Sql update return true or false from query. It does not return modified rows. After update you must get modified rows:

$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>';
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM