Page 1 of 1

PHP link post problem

Posted: Mon May 16, 2005 6:19 am
by mhouldridge
Hi,

I have a php link page called view.php which pulls down all of the asset numbers from a mysql database and displays them as hyperlinks. When a hyperlink is clicked it then goes through to viewall.php page which displays all of the data for that link.

I get an undefined variable of varl for the viewall.php page. I dont know what to do to fix this.

Here is the code for the hyperlink page;

Code: Select all

<?php
$db = mysql_connect("localhost","giacom-admin","snooker") or die("Problem connecting");
mysql_select_db("audit") or die("Problem selecting database");
$query = "SELECT * FROM dedicated order by type";
$result = mysql_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
echo "<TABLE BORDER=\"0\" table width=\"100%\">\n";
echo "<TR bgcolor=\"#cccccc\"><TD font colour=\"red\"><b>Asset</b></TD><TD><b>Title</b></TD><TD><b>Customer</b></TD><TD><b>Type</b></TD><TD><b>IP address</b></TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
    $row = mysql_fetch_array($result); //get a row from our result set
    if($i % 2) { //this means if there is a remainder
        echo "<TR bgcolor=\"#ffff99\">\n";
    } else { //if there isn't a remainder we will do the else
        echo "<TR bgcolor=\"#ffffcc\">\n";
    }
    echo "<TD><font color=\"red\"><b><a href='viewall.php'?varl=".$row['asset'].">".$row['asset']."</a></b></font></TD><TD><font size=\"2\">".$row['title']."</TD><TD><font size=\"2\">".$row['customer']."</TD><TD><font size=\"2\">".$row['type']."</TD><TD><font size=\"2\">".$row['IP']."</TD>\n"; 
    echo "</TR>\n";
}
//now let's close the table and be done with it 
echo "</TABLE>\n";
?>

and here is the viewall.php code;

Code: Select all

<?php
foreach($HTTP_GET_VARS as $varname => $value)
        $formVars[$varname]=$value;
$db = mysql_connect("localhost","giacom-admin","snooker"); 
mysql_select_db ('audit'); 
$query="SELECT * FROM dedicated WHERE asset = \"".$_GET['varl']."\"";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$formVars = array();
$formVars["title"]=$row["title"];
$formVars["customer"]=$row["customer"];
$formVars["type"]=$row["type"];
$formVars["serial"]=$row["serial"];
$formVars["os"]=$row["os"];
$formVars["oemfull"]=$row["oemfull"];
$formVars["oslicense"]=$row["oslicense"];
$formVars["IP"]=$row["IP"];
$formVars["location"]=$row["location"];
$formVars["processor"]=$row["processor"];
$formVars["memory"]=$row["memory"];
$formVars["motherboard"]=$row["motherboard"];
$formVars["software"]=$row["software"];
$formVars["software2"]=$row["software2"];
$formVars["software3"]=$row["software3"];
$formVars["software4"]=$row["software4"];
$formVars["software5"]=$row["software5"];
$formVars["software6"]=$row["software6"];
$formVars["software7"]=$row["software7"];
$formVars["software8"]=$row["software8"];
$formVars["software9"]=$row["software9"];
$formVars["software10"]=$row["software10"];
$formVars["software11"]=$row["software11"];
$formVars["software12"]=$row["software12"];
$formVars["software13"]=$row["software13"];
$formVars["software14"]=$row["software14"];
$formVars["software15"]=$row["software15"];
$formVars["disksize"]=$row["graphics"];
$formVars["networkcard"]=$row["networkcard"];
$formVars["graphics"]=$row["graphics"];
$formVars["license"]=$row["license"];
$formVars["license2"]=$row["license2"];
$formVars["license3"]=$row["license3"];
$formVars["license4"]=$row["license4"];
$formVars["license5"]=$row["license5"];
$formVars["license6"]=$row["license6"];
$formVars["license7"]=$row["license7"];
$formVars["license8"]=$row["license8"];
$formVars["license9"]=$row["license9"];
$formVars["license10"]=$row["license10"];
$formVars["license11"]=$row["license11"];
$formVars["license12"]=$row["license12"];
$formVars["license13"]=$row["license13"];
$formVars["license14"]=$row["license14"];
$formVars["license15"]=$row["license15"];
$formVars["asset"]=$row["asset"];
$formVars["value"]=$row["value"];
$formVars["value2"]=$row["value2"];
mysql_close($db);
?>

Posted: Mon May 16, 2005 6:57 am
by phpScott
this looks wrong

Code: Select all

<a href='viewall.php'?varl=".$row['asset'].">
try

Code: Select all

<a href='viewall.php?varl=".$row['asset']."'>
notice the placement of the second '

Posted: Mon May 16, 2005 7:26 am
by mhouldridge
you star!

That's done it. I cant believe something that simple has fixed the script.

Urghh!. Am I ever going to get used to php scripting. Please tell me that it took you ages to get this good?

thanks again,
Mark

Posted: Mon May 16, 2005 7:44 am
by phpScott
no just a wife in the background when I was freelancing saying 'your missing a quote' or 'don't forget the semi-colon';

You will only make the same mistake a couple of more times then you will remember it for later. :D

Glad to help.

phpScott

Posted: Mon May 16, 2005 8:03 am
by JayBird
starting a new thread instead of keeping it all your previous thread aint cool

viewtopic.php?t=33371

:roll:

Posted: Mon May 16, 2005 8:40 am
by mhouldridge
Sorry,

Im new to this. I wont do it again.