PHP Variable in Select Statement

前端 未结 7 527
滥情空心
滥情空心 2021-01-13 17:50

I\'ve written this PHP-Script which is working, and now I want to change the row name into a variable to (not sure if row is correct), I mean the \"name\" from the selec

相关标签:
7条回答
  • 2021-01-13 18:27

    You can usi it something like this. Currently i assume you get only one row back and want to use only one field.

    <?php
    require_once 'config.php';
    
    $id = $_GET["id"]; //ID DES DERZEITIGEN KONTAKTES
    $user = $_GET["user"];  //ID DES DERZEITIGEN USERS
    
    //Use variable inside closures `` and just in case escape it, depends how you get variable
    $query = mysql_query("SELECT `".mysql_real_escape_string($variable)."` FROM contacts WHERE contact_id='". mysql_real_escape_string( $id ) ."' and user_id='1';");
    
    
    if (!$query) {
        echo 'Could not run query: ' . mysql_error();
        exit;
    }
    $row = mysql_fetch_row($query); //Retriev first row, with multiple rows use mysql_fetch_assoc
    $retval = $row['0']; //Retriev first field
    
    $retval = trim($retval); 
    echo $retval;
    ?>
    
    0 讨论(0)
提交回复
热议问题