php issues & error.log

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jan 20, 2021 9:34 am

Wed Jan 20, 2021 9:54 am

thanks for reading.

i'm trying to update an old website to conform to php 7 ( currently 5.6.2 iirc )

among other issues, i am fight variable undefined.. passing via URL

link on page one:

echo "<tr><td><span CLASS = \"regtext\"><B><A HREF=\"mywebsite.php?pn=$pn\" > Add to Cart </A></B></span></td></tr>\n";

I placed this on the linked page right after the <head> tag:
$pn = $_GET['pn'];
else {
echo "pn capture failed.";

further down the page i call the variable

$sql = "SELECT * from tbl_items where part_no = '$pn'";

the error log states: "Undefined variable: pn"

The webpage is fully functional. i am using HTML grid layout so there are multiple grids & open/closing php tags - which shouldn't matter ?

thanks for any insight.

by the way: i have the exact same code on another page which doesn't give an error ?
User avatar
php-forum GURU
php-forum GURU
Posts: 398
Joined: Sat Mar 23, 2013 8:24 am
Location: Livonia, MI

Thu Jan 21, 2021 6:21 pm

Code: Select all

$pn = $_GET["pn"] ?? null;
Life is a fig newton of your imagination!
Post Reply