2013-09-10 2 views
0

$ _GET 변수를 테이블에 게시하는 데 문제가 있습니다. 내가 다른 스크립트의 모든하지만 listname 및 list_id로를 실행할 때마다

include 'connect.php'; 

if(isset($_POST['client_name'])) { 

$_GET['list']; //these are variables passed through from another page and I want these to post in the same table this page is suppose to post in. 
$_GET['list_id']; 


$Cname = $_POST['client_name']; 
$Cnumber = $_POST['client_number']; 
$listid = $_POST['list_id']; 
$listname = $_POST['list']; 


if(!empty($Cname) && !empty($Cnumber)){ 

    $query = "INSERT INTO clients (id, client_name, client_number, list_name, date_registered, list_id) VALUES ('$userid','$Cname', '$Cnumber', '$listname', now(), '$listid')"; 

    mysql_query($query); 

echo '<br /> 
<br /> 
     You successfully added a new clients to your list <a href="http://somewebsite.com/clients.php">View Update</a>'; 


    mysql_close(); 
    } 

    else { 

     echo '<script type="text/javascript">alert("Both fields are required");</script>'; 
     } 

데이터베이스 테이블에 게시 :

여기 내 스크립트입니다. get 변수를

과 같은 새 변수에 할당하려고 시도했습니다.

$ listNAME = $ _GET [ 'id'];

하지만 난 심지어 MySQL의 INSERT 쿼리 여전히 행운의 $ _GET 변수를 사용하려고

난 여전히 내 테이블의 빈 필드로 끝날 경우에도 그와

이 사람이 나를 도울 수 및 스크립트가 실행될 때 빈 필드를 해결하기 위해 내가 할 수있는 것에 관해 조언을 해주십시오.

<form action="addclient.php" method="POST"> 

Name of Client: <input type="text" name="client_name"> 

Client's Number: <input type="text" name="client_number" placeholder="1-876-xxx-xxx"> 

<input type="submit" > 


</form> 
+0

get 변수를 출력 할 때 표시되는 내용은 무엇입니까? –

+0

@ Murd URL에 전달 된 변수의 정보가 – mattchambers

+0

인데, 열이 적절한 데이터 유형으로 설정되어 있습니까? varchar 또는 텍스트 또는 >>? –

답변

1

나는 그것을주의해서 말합니다.

PDO 또는 mysqli를 사용하십시오


당신이 addclient.php에서 두 변수를 잡을 수 있어야합니다보다 당신이

http://localhost/addclient.php?list_id=100&list=mylistname 

처럼 addclient.php를 호출하는 경우

if (isset($_GET['list_id'])) { 

$listid = $_GET['list_id']; 
$listname = $_GET['list']; 

} 

및 양식

<form action="addclient.php" method="POST"> 
    <input type="hidden" name="list_id" value="$listid"> 
    <input type="hidden" name="list" value="$listname"> 
Name of Client: <input type="text" name="client_name"> 
Client's Number: <input type="text" name="client_number" placeholder="1-876-xxx-xxx"> 
<input type="submit" > 
</form> 

이후그것이 int(11)의 따옴표없이

if(isset($_POST['client_name'])) { 

$Cname = $_POST['client_name']; 
$Cnumber = $_POST['client_number']; 
$listid = $_POST['list_id']; 
$listname = $_POST['list']; 
.... 
} 

하고 삽입

VALUES ('$userid','$Cname', '$Cnumber', '$listname', now(), '$listid') 

$ listid에 제출합니다.

VALUES ('$userid','$Cname', '$Cnumber', '$listname', now(), $listid) 
+0

감사합니다. @ moskito-x이 도구를 사용하여 모든 작업을 수행 할 수있었습니다. – mattchambers

4

귀하는 $ _GET 변수가 있다고,하지만 당신은 $로 _POST 변수를 검색하려고 :

$listid = $_POST['list_id']; 
$listname = $_POST['list']; 

이 문제가되지 않습니다? 또한 두 배열에서오고 있는지보기 위해 시도해 볼 수도 있습니다 : 그것은 하나 $ _GET이나 $ _POST 변수를 수신 할 때

print_r($_GET); 
print_r($_POST); 

또는, 당신은 $ _REQUEST를 사용할 수 있습니다.

관련 문제