0

I am having problem in getting variable from one PHP page to another PHP page. The problem is I can't get the variable. I use this code to move to another page :

$updateGoTo = "closeticketscs.php";
if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
}

and I've tried code below to get the variable :

$updateGoTo = "closeticketscs.php?id=echo $row_searchreslt['ID'];";
if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
}

However, this doesn't work. Any help will be appreciated. Here is the right code :

$updateGoTo = "closeticketscs.php?id=".$_POST['ID_Pelanggan'];
  if (isset($_SERVER['QUERY_STRING'])) 
  {
    $updateGoTo .= ((strpos($updateGoTo, '?') > -1) ? "&" : "?" ).
    $_SERVER['QUERY_STRING'];
  }

header(sprintf("Location: %s", $updateGoTo));

1

4 Answers 4

3

Did you try $_GET?

if (isset($_GET['id']) {
    $id = $_GET['id']
}
Sign up to request clarification or add additional context in comments.

Comments

0

in your second code, i think you have a mistake. you dont need to echo a php variable file when you declare a variable to another variable.

change

  $updateGoTo = "closeticketscs.php?id=echo $row_searchreslt['ID'];";

to

  $updateGoTo = "closeticketscs.php?id=".$row_searchreslt['ID'];

and if you want to get a variable from page to another page, just use $_GET. example,

in index.php

 <?php
 $updateGoTo = "closeticketscs.php?id=".$row_searchreslt['ID'];
 echo '<a href="'.$updateGoTo.'">Go Here</a>';
 ?>

and in closeticketscs.php

 <?php
 $new_variable = $_GET['id'];
 //now you get the variable 'id' from the url closeticketscs.php?id=value
 ?>

if use form :

 <form method="get" action="closeticketscs.php">
 <input type="text" name="id" value="123" >
 <input type="submit" value="Click Here" name="click">
 </form>

7 Comments

Ive tried your suggestion, but still won't work. When I echo the $new_variable it doesn't appear :(
is the $row_searchreslt['ID'] variable has been declared? check your url before you click the link, is closeticketscs.php?id=somevalue or just closeticketscs.php?id=
yes haha. klo cuma closeticketscs.php?id= , berarti variabel $row_searchreslt['ID'] nya kosong. variabel $_GET['id'] keisi kalo di link nya closeticketscs.php?id=adavaluenya
Nah, iya ngga keisi. sebenernya itu ID bisa ngga ya kalo ambil dari name, soalnya id nya itu kecetak gini : <input type="hidden" name="ID">
coba kirim scriptnya ke email gw, soalnya gw masih belum ngerti apa yang harus dikirim. bisa sih pake input juga, tapi pakenya form
|
0
if (isset($_SERVER['QUERY_STRING'])) {
   $updateGoTo .= ( (strpos($updateGoTo, '?') > -1) ? "&" : "?" ) . $_SERVER['QUERY_STRING'];
}

If you want to check for question mark with strpos you must use > -1 :) And you can .= in 1 line no need to make it on 2

1 Comment

So, I have to use >-1 to make it work (link to another page)?
0

//If your link is closeticketscs.php?id=12345

if (isset($_REQUEST['id']){
   $id= $_REQUEST['id'];
   echo $id;
}

Among $_REQUEST, $_GET and $_POST which one is the fastest? this is more about request get and post.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.