Jump to content

using variables with include statements


tom.hill

Recommended Posts

Hi guys,

 

im a bit stuck, im trying to include a variable within an include statement so that the page that is included depends on a variable if you get my drift!

 

this is what i have got so far but its not working, all im getting is a blank page :S

 

<?php

  // Check if session is not registered , redirect back to login page.

  include('includes/checklogin.php');

  // Connect to server and select database

  include('includes/db_login.php');

 

  // keyid sent in url

  $keyid = $_GET['keyid'];

 

  $query = "SELECT * FROM tkeys WHERE keyid = '$keyid' AND isdeleted = '0'";

  $result = mysql_query($query);

  if ($result) {

    $row = mysql_fetch_array($result, MYSQL_ASSOC);

    $softwareid = $row["softwareid"];

  } else {

    die ("Could not query the database: <br />". mysql_error());

  }

 

  // Mark key as deleted

  $query = "UPDATE tkeys SET isdeleted = '1' WHERE keyid = '$keyid' AND isdeleted = '0' LIMIT 1";

  $result = mysql_query($query);

 

  if($result) {

    $url = "viewlicences.php?softwareid=$softwareid";

    include("$url");

  } else {

    die ("Could not query the database: <br />". mysql_error());

  }

?>

 

can anyone spot any silly mistakes??

 

many thanks in advance.

 

Tom

Link to comment
Share on other sites

I don't think you can include a page and use the parameters like you have.

 

do you want to include the page or can you redirect to the page. If you want to include you can alway try setting the $_GET right on the page and then include the page.

 

<?php
  if($result) {
    $_GET['softwareid'] = $softwareid;
    $url = "viewlicences.php";
    include("$url");
  } else {
    die ("Could not query the database: ". mysql_error());
  }
?>

 

Ray

Link to comment
Share on other sites

thanks for your reply Ray, im a little confused tho, surely that would send the user to viewlicences.php every time? without the variable being passed in the URL? (that is picked up by viewlicences.php and shows specific content dependent on the variable)

 

i dont really mind how i work it include/redirect anything but i need php processing on that page first before the 'redirect' :S

 

is this possible?

Link to comment
Share on other sites

Well no. Actually this will INCLUDE the page viewlicences.php. I'm sure somewhere on that page you are looking for the GET variable softwareid. So what I did was set the get variable then included the page so it will find it. If you wanted to redirect then you could use

 

header('Location:http://yourwebpage/viewlicences.php?softwareid='.$softwareid.'');

 

Ray

Link to comment
Share on other sites

I wonder if anyone can help if I try to explain myself a little better.

 

I’m creating a system to store software licences and link them with hardware.

 

At the moment the user can view hardware (computers, model numbers serial numbers etc) and then drill down to view the software licences that are installed on a specific computer, I have achieved this by passing the hardwareid variable to the viewhardware page and a table is created showing the results, the user can then choose to "uninstall" a software title from that hardware, this works as far as the database is concerned but I’m unable to return the user to the page they were viewing, instead I have to send them back to the main hardware page (that does not have a variable in the url) what I would like to achieve is to send the user back to the specific computer page that they were at before selecting to uninstall the software, but this requires a variable sent in the url. Am I going about this the wrong way??

 

Really stuck, as always many thanks in advance.

 

Tom

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.