php
  • mysql
  • 2015-08-19 28 views -2 likes 
    -2

    包含一個用於在表格中插入值的php文件。腳本插入值,但全部爲空。

    if(isset($_GET['id'])) 
    { 
    $id=$_GET['id']; 
    include_once ('1.php?id='.$id); 
    
    $sql = "insert into table (...) values (variables from 1.php?id='.$id)"; 
    

    插入查詢很好,但提交空值..什麼是錯的?

    +0

    請予以明確。你想做什麼。 –

    +0

    你可以告訴我們'1.php' –

    +0

    什麼是提交空值? –

    回答

    3

    您不能將variable s傳遞給文件,同時包含像query string s。如果設置了variable,那麼在這些文件之後它們已經可用。難道 -

    if(isset($_GET['id'])) 
    { 
    $id=$_GET['id']; 
    include_once ('1.php'); 
    
    $sql = "insert into table (name) values ('$name')"; 
    

    1.PHP 喜歡的東西 -

    if(!empty($id)) { // Check if the variable is present 
        // Genarate the variables 
        $name = 'xyz'; 
    } 
    
    +3

    如果'$ name'是一個用戶(或dinamically)生成的值,我建議使用[PDO](http://php.net)更安全[方法](http://www.phptherightway.com/#pdo_extension) /manual/en/book.pdo.php)擴展名 – ramabarca

    +0

    是的。這應該被照顧。但不是相關的問題。 –

    0

    請考慮下面的代碼片段:

    if(!empty($_GET['id'])) { 
        $id = mysql_real_escape_string($_GET['id']); 
        include_once("1.php?id={$id}"); 
        $sql = "INSRET INTO your_table (your_columns) VALUES (variables from 1.php?id={$id})"; 
        mysql_query($sql); 
    } 
    
    相關問題