user3806674
user3806674

Reputation: 17

How to show PHP variable in hyperlink?

I'm trying to echo a variable so it shows in my hyperlink. Here's my current code:

<?php

if (!defined("WHMCS"))
        die("This file cannot be accessed directly");


$customerserviceid = mysql_query("SELECT id FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'");

function limitOrders($vars) {
        if(mysql_num_rows(mysql_query("SELECT packageid FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'")) > 0) {

                if($packageid = '1' || $packageid = '2' || $packageid = '3' || $packageid = '4' || $packageid = '5' || $packageid = '6' || $packageid = '7' || $packageid = '8' || $packageid = '9' || $packageid = '10') {
                global $errormessage;
                $errormessage = "<li>It looks like you already have an account!  Please <a href='http://mywebsite.com/upgrade.php?type=package&id=$customerserviceid'>click here</a> to upgrade or downgrade your account.</li>";
                }
        }
}
add_hook("ShoppingCartValidateCheckout", 1, "limitOrders");
?>

I tried adding $customerserviceid into the URL on line 14 but it just shows blank so I'm guessing that I didn't add something correctly. When I run the query in phpMyAdmin it does show what I'm wanting so the query itself should be correct...

Upvotes: 0

Views: 115

Answers (3)

Abhishek Batra
Abhishek Batra

Reputation: 1599

mysql_query returns a resourcse. You need to fetch data from the resourse. Yor can do it like this.

$result= mysql_query("SELECT id FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'");
$row = mysql_fetch_assoc($result);
$customerserviceid = $row['id'];

This should work.

Upvotes: 0

Barmar
Barmar

Reputation: 782683

You need to fetch the results from the query results, and then use global to access the global variable.

<?php
if (!defined("WHMCS"))
        die("This file cannot be accessed directly");

$result = mysql_query("SELECT id FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'");
$row = mysql_fetch_assoc($result);
$customerserviceid = $row['id'];

function limitOrders($vars) {
    global $customerserviceid;
    if(mysql_num_rows(mysql_query("SELECT packageid FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'")) > 0) {

        if($packageid = '1' || $packageid = '2' || $packageid = '3' || $packageid = '4' || $packageid = '5' || $packageid = '6' || $packageid = '7' || $packageid = '8' || $packageid = '9' || $packageid = '10') {
        global $errormessage;
        $errormessage = "<li>It looks like you already have an account!  Please <a href='http://mywebsite.com/upgrade.php?type=package&id=$customerserviceid'>click here</a> to upgrade or downgrade your account.</li>";
        }
    }
}
add_hook("ShoppingCartValidateCheckout", 1, "limitOrders");
?>

Upvotes: 1

user3801289
user3801289

Reputation: 33

I think you need to fetch the data you just did a query to select the data from the database but you didn't printed result you may can use this :

$query = mysql_query("SELECT id FROM `tblhosting` WHERE `userid` = '{$_SESSION['uid']}'");
$customerserviceid=mysql_fetch_array($query);

Upvotes: 0

Related Questions