簡體   English   中英

我有兩個表單,都以id作為主鍵,我希望在第一個表單中輸入的id在下一個表單中更新

[英]I have two forms both with an id as the primary key, I want the id entered in the first form to update in the next form

我有兩種形式都以id作為主鍵,我希望在第一種形式中輸入的id供下一種形式使用。當前形式不更新id。第一種形式用於患者注冊和主鍵是ID,第二個表單用於輸入其他患者詳細信息,例如診斷和處方葯,第二個表單應使用第一個表單中的ID,並拒絕輸入除第一個表單中保存在數據庫中的ID之外的任何ID。在代碼片段中,有兩種形式:add Patient.php和addprescription.php

 <?php session_start() ?> <?php $id=$_POST['id']; $name=$_POST['name']; $age=$_POST['age']; $gender=$_POST['gender']; $occupation=$_POST['occupation']; $mobile=$_POST['mobile']; $address=$_POST['address']; $con=@mysql_connect("localhost","root","") or die(mysql_error()); $db=@mysql_select_db("hms",$con)or die(mysql_error()); $str="insert into patients values('$id','$name','$age','$gender','$occupation','$mobile','$address')"; $res=@mysql_query($str)or die(mysql_error()); if($res>=0) { echo'<br><br><b>Patient added !!<br>'; } ?> <html> <body style="background-image:url(background4.jpg)"> <br> <a href="home.html"><b>Click here to return to the home page</b></a> </body></html> //end of first form addpatient// //start of second form addprescription <?php session_start() ?> <?php $id=$_POST['id']; $medicine=$_POST['medicine']; $diagnosis=$_POST['diagnosis']; $instructions=$_POST['instructions']; $doc_name=$_POST['doc_name']; $con=@mysql_connect("localhost","root","") or die(mysql_error()); $db=@mysql_select_db("hms",$con)or die(mysql_error()); $str="insert into prescription values('$id','$medicine','$diagnosis','$instructions','$doc_name')"; $res=@mysql_query($str)or die(mysql_error()); if($res>=0) { echo'<br><br><b>Prescription added !!<br>'; } ?> <html> <body style="background-image:url(background4.jpg)"> <br> <a href="home.html"><b>Click here to return to the home page</b></a> </body></html> 

 //this is the html for the addpatient.html// <html> <head> <title>Patient Registration Form</title> <script type="text/javascript" src="validate.js"></script> <script> function validate() { if( document.PatientRegistration.id.value == "" ) { alert( "Please provide valid ID!" ); document.PatientRegistration.id.focus() ; return false; } if ( document.PatientRegistration.name.value == "" ) { alert( "Please provide your Name!" ); document.PatientRegistration.name.focus() ; return false; } if( document.PatientRegistration.address.value == "" ) { alert( "Please provide your Postal Address!" ); document.PatientRegistration.address.focus() ; return false; } if ( ( PatientRegistration.sex[0].checked == false ) && ( PatientRegistration.sex[1].checked == false ) ) { alert ( "Please choose your Gender: Male or Female" ); return false; } if( document.PatientRegistration.occupation.value == "" ) { alert( "Please provide your Occupation!" ); document.PatientRegistration.occupation.focus() ; return false; } if( document.PatientRegistration.age.value == "" ) { alert( "Please provide your age!" ); document.PatientRegistration.age.focus() ; return false; } } </script> </head> <body> <form action="addpatient.php" method="post" name="PatientRegistration" onsubmit="return(validate());"> <table cellpadding="2" width="20%" bgcolor="99FFFF" align="center" cellspacing="2"> <tr> <td colspan=2> <center><font size=4><b>Patient Registration Form</b></font></center> </td> </tr> <tr> <td>ID</td> <td><input type="text" name="id" id="id" size="30"></td> </tr> <tr> <td>Name</td> <td><input type="text" name="name" id="name" size="30" ></td> </tr> <tr> <td>Postal Address</td> <td><input type="text" name="address" id="address" size="30"></td> </tr> <tr> <td>Sex</td> <td> <input type="radio" name="gender" value="male" size="10">Male <input type="radio" name="gender" value="Female" size="10">Female </td> </tr> <tr> <td>Occupation</td> <td><input type="text" name="occupation" id="occupation" size="30"></td> </tr> <tr> <td>Age</td> <td><input type="text" name="age" id="age" size="30"></td> </tr> <tr> <td>Mobile</td> <td><input type="text" name="mobile" id="mobile" size="30"></td> </tr> <tr> <td> <input type="reset"> </td> <td colspan="2"> <input type="submit" value="Register" /> </td> </tr> </table> </form> </body> </html> //this is the html for the addprescription.html// <html> <head> <title>Patient Registration Form</title> <script type="text/javascript" src="validate.js"></script> </head> <body> <form action="addprescription.php" method="post" name="PatientPrescription" onsubmit="return(validate());"> <table cellpadding="2" width="20%" bgcolor="99FFFF" align="center" cellspacing="2"> <tr> <td colspan=2> <center><font size=4><b>Patient Prescription Form</b></font></center> </td> </tr> <tr> <td>ID</td> <td><input type="text" name="id" id="id" size="30"></td> </tr> <tr> <td>Medicine</td> <td><input type="text" name="medicine" id="medicine" size="30"></td> </tr> <tr> <td>Diagnosis</td> <td><input type="text" name="diagnosis" id="diagnosis" size="30"></td> </tr> <tr> <td>Instructions</td> <td><input type="text" name="instructions" id="instructions" size="30"></td> </tr> <tr> <td>Doc Name</td> <td><input type="text" name="doc_name" id="doc_name" size="30"></td> </tr> <tr> <td> <input type="reset"> </td> <td colspan="2"> <input type="submit" value="Enter" /> </td> </tr> </table> </form> </body> </html> 

不知道用戶如何從表單一移到表單二(自動重定向或手動導航),也無法看到表單元素(它們似乎未包含在代碼中)。 我建議使用會話。

<?php
session_start()
?>

<?php
$id=$_POST['id'];
$name=$_POST['name'];
$age=$_POST['age'];
$gender=$_POST['gender'];
$occupation=$_POST['occupation'];
$mobile=$_POST['mobile'];
$address=$_POST['address'];
$con=@mysql_connect("localhost","root","") or die(mysql_error());
$db=@mysql_select_db("hms",$con)or die(mysql_error());
$str="insert into patients values('$id','$name','$age','$gender','$occupation','$mobile','$address')";
$res=@mysql_query($str)or die(mysql_error());

if($res>=0)
{
    echo'<br><br><b>Patient added !!<br>';
    $_SESSION['patientid'] = $id;
}

?>
<html>

<body style="background-image:url(background4.jpg)">
<br>
<a href="home.html"><b>Click here to return to the home page</b></a>
</body></html>




//end of first form addpatient//

//start of second form addprescription




<?php
session_start()
?>

<?php
$id=$_POST['id'];
$medicine=$_POST['medicine'];
$diagnosis=$_POST['diagnosis'];
$instructions=$_POST['instructions'];
$doc_name=$_POST['doc_name'];
$con=@mysql_connect("localhost","root","") or die(mysql_error());
$db=@mysql_select_db("hms",$con)or die(mysql_error());
$str="insert into prescription values('$id','$medicine','$diagnosis','$instructions','$doc_name')";
$res=@mysql_query($str)or die(mysql_error());
if($res>=0)
{
echo'<br><br><b>Prescription added !!<br>';
}

?>
<html>
<body style="background-image:url(background4.jpg)">
<br>
<a href="home.html"><b>Click here to return to the home page</b></a>
<form>
    <input type = "text" name = "id" value = "<?php echo $_SESSION['patientid']; ?>" />
</form>
</body></html>

另外,使用“ root”帳戶進行mysql登錄會帶來很大的安全風險。 結合使用提交的值直接插入數據庫這一事實,您對SQL注入攻擊( https://www.owasp.org/index.php/SQL_Injection開放態度

我強烈建議您使用權限受限的新用戶帳戶,並在將其值插入查詢字符串之前對其進行限定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM