-6

I am trying to pass a value of a variable from one php file to another but for some reason it doesn't pass anything. I would just like some hints on how i can fix this.

At the moment I am trying to pass using include. I have tried require and require_once. I have tried global variables and I have tried creating a function to inherit from but it still displays nothing.

I am only able to post the code of the first page:

<?php

/*
 * Following code will get single product details
 * A product is identified by product id (pid)
 */
 // array for JSON response
$response = array();

// include db connect class
 require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new db_connect();
// check for post data

global $userNameInput;
$passInput;

if ( isset($_POST['userNameInput']) && isset($_POST['passInput'])) {

    $userNameInput = $_POST['userNameInput'];
    $passInput = $_POST['passInput'];
    // get a product from products table
    $result = mysql_query("SELECT Business_Login_Password FROM Businesses WHERE    Business_Login_UserName = '".$userNameInput."' AND Business_Login_Password =   '".$passInput."'");

       if (isset($result))
       {


        echo "<head><meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=loginHome.php\"></head> ";




        } else {
        // failed to insert row
      $response["success"] = 0;
   // $response["message"] = "Oops! An error occurred.";
        // echoing JSON response

      }
   }
 ?>
  • Do not post the exact code, whereas post a concept of code which is abstract from anything related to the project itself. – jshthornton Jul 11 '14 at 07:49
  • 2
    How are you TRYING to pass them? `$_POST` `$_GET` sessions etc...? Show the basics of what you're trying to do – Paul Dessert Jul 11 '14 at 07:49
  • http://stackoverflow.com/questions/5678567/how-to-pass-variables-between-php-scripts – Eric Lagergren Jul 11 '14 at 07:50
  • simple, you could try echo some value for example in json format in one script then call this script from another. – dgierejkiewicz Jul 11 '14 at 07:57
  • It's still not clear what variable you're trying to pass from where to where. And please **look up how to hash passwords** -- saving passwords as plain text to the database is a huge security risk. – JJJ Jul 11 '14 at 08:18

1 Answers1

-3

Well there is always the concept of passing a variable to the $_SESSION array, but it really depends on the case you need. For example if you need to keep information about the currently logged in user, you could save it as an object and assign it `$_SESSION['user'] = $user'. Otherwise, if you want to just pass the variables to the other script and be done with them you could try a form and send them via the $_POST, $_GET or $_REQUEST arrays. Note that if sent by form the values are only sent once and not remembered.

I hope I was of some help :)

valio_sg
  • 95
  • 9
  • can you give me an example of what a '$_SESSION['user'] = $user' script will look like? Sorry i have never really done php coding in my life. – Devon Lamminga Jul 11 '14 at 08:12
  • Lets say you have some login functionality and you save the username in a variable $user. You are currently in (for example) index.php and you want to pass it to validate.php. First you have to initialize your session by writing `session_start();`. Now imagine your $_SESSION array as already created and you want to initialize a key inside it which keeps your information. You do so by writing $_SESSION['user'] = $user; Now your information is kept in the session and you can access it everywhere by typing session_start() in the beginning of the script and than $user = $_SESSION['user']. – valio_sg Jul 11 '14 at 08:24
  • much appreciated. Its helped me quite a lot. – Devon Lamminga Jul 11 '14 at 08:29