簡體   English   中英

如何從php頁面傳遞參數值

[英]how to pass the parameter value from the php page

DELIMITER $$

DROP PROCEDURE IF EXISTS `users` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `users`(in id int(25))
BEGIN

    declare empcode varchar(25);

    set empcode=(select emp_code from transaction_user_register where t_reg_id=id);

    delete from transaction_user_register where t_reg_id=id and emp_code=empcode;

    update user_register set active='2' where reg_id=id and emp_code=empcode;


END $$

DELIMITER ;

如何從PHP頁面傳遞ID。...

我從php頁面調用程序
我不知道如何傳遞參數值...

我寫的頁面像

<? require_once"db.php";
echo $id = $_REQUEST['t_reg_id'];

$connt = mysql_connect($server1, $user1, $pass1, $dbname1) or die ("__construct() Function Problem => ". mysqli_error());
$resr= mysql_query($connt,"CALL users('$id')"); 
mysql_close($connt);




echo "Cron Job Run Succesfully........";

?>

由於您使用的是mysqli使用准備好的語句,而不是插補查詢字符串,這使您的代碼可廣泛用於sql注入。

話雖這么說,您的代碼可能看起來像

<?php
require_once('db.php');
$id = $_REQUEST['t_reg_id'];

$db = new mysqli($server1, $user1, $pass1, $dbname1);
if (!$db) {
    die('Could not connect: ' . $db->connect_error);
}
$stmt = $db->prepare('CALL users(?)');
if (!$stmt) {
    die('Prepare failed: ' . $db->error); 
}
$stmt->bind_param('i', $id); // that's assuming id is an integer value
if(!$stmt->execute()) {
    die('Execute failed: ' . $db->error);
}
$stmt->close()
$db->close();

...

暫無
暫無

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

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