본문 바로가기
MySql

MySQL Select 문의 PHP 변수

by 베이스 공부 2020. 11. 14.
반응형

이 PHP 스크립트를 작성했습니다. 이제 행 이름을 변수로 변경하고 싶습니다 (행이 올바른지 확실하지 않음). select name에서 "이름"을 의미합니다. ... I've tried nearly everything, but nothing gave me the right result. ( " '. $ var.'")와 같은 문에서 변수를 사용할 수있는 일반적인 방법이 작동하지 않는다는 것을 알고 있습니다.

<?php
require_once 'config.php';

$id = $_GET["id"]; //ID OF THE CURRENT CONTACT
$user = $_GET["user"];  //ID OF THE CURRENT USERS

$query = mysql_query("SELECT name FROM contacts WHERE contact_id='". mysql_real_escape_string( $id ) ."' and user_id='1';");

$retval = mysql_fetch_object($query)->name;

$retval = trim($retval);
echo $retval;
?>

 

해결 방법

 

이게 훨씬 쉬워요?

$sql_insert = 
"INSERT INTO customers (        
`name`,
`address`,
`email`,
`phone`
) 
VALUES (        
'$name',
'$address',     
'$email',
'$phone'
)";

 

참조 페이지 https://stackoverflow.com/questions/3476108

 

 

반응형

댓글