douhongxie5436 2014-08-14 13:04 采纳率: 100%
浏览 32
已采纳

从URL使用PHP到$ _GET [ID]

i am using simple code to get some data from DB based on some unique ID called VIN. i wrote a script which work fine if somebody insert it in form, but now i need to edit to work more automaticly, and use $_GET['vin'] from URL and just display results based on that.

My try of code looks like: public $vin = null;

 public function __construct( $data = array() ) {
     if( isset( $data['vin'] ) ) $this->vin = stripslashes( strip_tags( $data['vin'] ) );
 }

 public function storeFormValues( $params ) {
    $this->__construct( $params ); 
 }

 public function fetchByVinEvidence($vin) {
     $success = false;
     try{
        $con = new PDO( DB_HOST, DB_USER, DB_PASS ); 
        $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        $sql = "SELECT * FROM evidence_vin WHERE vin = :vin LIMIT 1";
        $stmt = $con->prepare( $sql );
        $stmt->bindValue( "vin", $this->vin, PDO::PARAM_STR );
        $stmt->execute();
            echo "<table>";
            echo "<th>First Registration</th>";
            echo "<th>Validity Until</th>";
            echo "<th>Rpm</th>";
            echo "<th>Max-Speed</th>";
            echo "<th>Action</th>";
            while ($row = $stmt->fetch()){
                echo "<tr>";
                echo "<td>24</td>";
                echo "<td>".$row['claim_number']."</td>";
                echo "<td>".$row['license']."</td>";
                echo "<td>".$row['country']."</td>";
                echo "<td>".$row['vin']."</td>";
                echo "</tr>";
            }
            echo "</table>" ;
            }catch(PDOExeption $e){
            echo $e->getMessage();
            echo $con->errorInfo();
            }

         return $success;
     }

and call the function:

$vin = $_GET['vin'];
echo $vin;
$data = new Data;
$data->fetchByVinEvidence($vin);

Can somebody help me with that?

  • 写回答

2条回答 默认 最新

  • doudun5009 2014-08-14 13:06
    关注

    You pass a variable $vin to the function fetchByVinEvidence but then use the class level variable $this->vin instead of the passed one.

    $stmt->bindValue( "vin", $this->vin, PDO::PARAM_STR );
    

    should be

    $stmt->bindValue( "vin", $vin, PDO::PARAM_STR );
    

    OR set the class level variable to the passed one at the start of the function if you need to use it elsehwere:

    public function fetchByVinEvidence($vin) {
         $this->vin = $vin;
         ....
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的