[英]How to call php file inside a form (html)
我有2個PHP文件,名為:
然后,我想在其中再添加一個名為update_user.html的文件:
What I want to know is how can I fill this form calling the user_one.php given the $_POST['user']
。
* user_one.php必須返回“ echo json”,因為此文件在手機請求中稱為*
user_one.php(在其中json編碼並返回)
<?php
/*
* Following code will get single product details
* A product is identified by product id (uid)
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '../../db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_POST["user"])) {
$uid = $_POST['user'];
// get a product from products table
$result = mysql_query("SELECT *FROM Usuarios WHERE Usuario = '$uid'");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$users = array();
$users["name"] = $result["Nombre"];
$users["lastname"] = $result["Apellidos"];
$users["user"] = $result["Usuario"];
$users["password"] = $result["Contrasena"];
$users["birthday"] = $result["Fnacimiento"];
$users["direction"] = $result["Direccion"];
$users["email"] = $result["Email"];
$users["phone"] = $result["TelfFijo"];
$users["mobile_phone"] = $result["TelfMov"];
$users["user_type"] = $result["TipoUsuario"];
// success
$response["success"] = 1;
// user node
$response["user"] = array();
// push single users into final response array
array_push($response["user"], $users);
// echoing JSON response
echo json_encode($response);
} else {
// no user found
$response["success"] = 0;
$response["message"] = "No user found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no user found
$response["success"] = 0;
$response["message"] = "No user found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
user_uptade.html(必須使用在user_one.php中獲得的JSON填寫表單)
<html>
<body>
<br>Agregue un nuevo Usuario:
<form method="post" action="user_update.php" >
Nombre:
<br>
<input type="Text" name="name" >
<br>
<br>
Apellidos:
<br>
<input type="Text" name="lastname" >
<br>
<br>
Usuario:
<br>
<input type="Text" name="user" >
<br>
<br>
Fecha nacimiento:
<br>
<input type="Text" name="bday" >
<br>
<br>
Direccion:
<br>
<input type="Text" name="direccion" >
<br>
<br>
TelFijo:
<br>
<input type="Text" name="tfijo" >
<br>
<br>
TelMov:
<br>
<input type="Text" name="tmov" >
<br>
<br>
Email:
<br>
<input type="Text" name="email" >
<br>
<br>
Password:<br>
<input type="password" name="password" ><br>
<input type="Submit" name="enviar" value="Agregar">
</form>
</body>
</html>
您不能從HTML“調用” PHP文件。 僅在使用include或要求加載要使用的其他PHP文件之后,才可以對PHP文件執行此操作。 PHP真正可以做的唯一一件事就是將表單發布到服務器,可以這樣完成:
<form type="post" action="http://yoururl.com/your_desired_php_file.php">
...
</form>
更新:通過將擴展名從.html更改為.php,您可以輕松地將HTML文件更新為PHP。之后,您可以使用require(“ your_filename.php”); 加載要使用的文件。 然后,您可以調用該文件中的任何函數或訪問任何全局變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.