Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help cannot find files or make url work

Status
Not open for further replies.

boab

Programmer
May 30, 2001
75
GB
Can some one have a look at the code below and tell me what if any thing is wrong with it. The problems that I have are two fold the code is supposed to generate a table with all the relevant products and images but the images are not showing and these images and related text lables should be links to display the products in more detail but the code is failing to generate the proper links. The file structure is in the root /catcarscpt which contains all the scripts and then pics_etc/products. Any ideas are welcome thanx
Boab

<?

function do_html_header($title = '')
{
// print an HTML header

// declare the session variables we want access to inside the function
global $total_price;
global $items;
if(!$items) $items = &quot;0&quot;;
if(!$total_price) $total_price = &quot;0.00&quot;;
?>
<html>
<head>
<title><?=$title?></title>
<style>
h2 { font-family: Arial, Helvetica, sans-serif; font-size: 22px; color = red; margin = 6px }
body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }
hr { color: #FF0000; width=70%; text-align=center}
a { color: #000000 }
</style>
</head>
<body>
<table width=100% border=0 cellspacing = 0 bgcolor=#cccccc>
<tr>

<td rowspan = 2>
<a href = &quot;index.php&quot;><img src=&quot;../pics_etc/HEADER.gif&quot; alt=&quot;Stewart Highland&quot; border=0
align=left valign=bottom height = 97 width = 647></a>
</td>
<td align = right valign = bottom>
<? if(session_is_registered(&quot;admin_user&quot;))
echo &quot; &quot;;
else
echo &quot;Total Items = $items&quot;;
?>
</td>
<td align = right rowspan = 2 width = 135>
<? if(session_is_registered(&quot;admin_user&quot;))
display_button(&quot;logout.php&quot;, &quot;log-out&quot;, &quot;Log Out&quot;);
else
display_button(&quot;show_cart.php&quot;, &quot;view-cart&quot;, &quot;View Your Shopping Cart&quot;);
?>
</tr>
<tr>
<td align = right valign = top>
<? if(session_is_registered(&quot;admin_user&quot;))
echo &quot; &quot;;
else
echo &quot;Total Price = $&quot;.number_format($total_price,2);
?>
</td>
</tr>
</table>
<?
if($title)
do_html_heading($title);
}

function do_html_footer()
{
// print an HTML footer
?>
</body>
</html>
<?
}

function do_html_heading($heading)
{
// print heading
?>
<h2><?=$heading?></h2>
<?
}

function do_html_URL($url, $name)
{
// output URL as link and br
?>
<a href=&quot;<?=$url?>&quot;><?=$name?></a><br>
<?
}

function display_categories($cat_array)
{
if (!is_array($cat_array))
{
echo &quot;No categories currently available<br>&quot;;
return;
}
echo &quot;<ul>&quot;;
foreach ($cat_array as $row)
{
$url = &quot;show_cat.php?catid=&quot;.($row[&quot;catid&quot;]);
$title = $row[&quot;name&quot;];
echo &quot;<li>&quot;;
do_html_url($url, $title);
}
echo &quot;</ul>&quot;;
echo &quot;<hr>&quot;;
}

function display_products($product)
{
//display all products in the array passed in
if (!is_array($product))
{
echo &quot;<br>No products currently available in this category<br>&quot;;
}
else
{
//create table
echo &quot;<table width = \&quot;100%\&quot; border = 0>&quot;;

//create a table row for each product
foreach ($product as $row )
{
$url = &quot;show_product.php?productid=&quot;.($row[&quot;productid&quot;]);
echo &quot;<tr><td>&quot;;
if (@file_exists(&quot;.\pics_etc\products&quot;.$row[&quot;productid&quot;].&quot;.jpg&quot;))
{
$title = &quot;<img src=\&quot;.\pics_etc\products&quot;.($row[&quot;productid&quot;]).&quot;.jpg\&quot; border=0>&quot;;
do_html_url($url, $title);
}
else
{
echo &quot; &quot;;
}
echo &quot;</td><td>&quot;;
$title = $row[&quot;name&quot;];
do_html_url($url, $title);
echo &quot;</td></tr>&quot;;
}
echo &quot;</table>&quot;;
}
echo &quot;<hr>&quot;;
}

function display_product_details($product)
{
// display all details about this product
if (is_array($product))
{
echo &quot;<table><tr>&quot;;
//display the picture if there is one
if (@file_exists(&quot;./pics_etc/products/&quot;.($product[&quot;productId&quot;]).&quot;.jpg&quot;))
{
$size = GetImageSize(&quot;../pics_etc/products/&quot;.$product[&quot;productId&quot;].&quot;.jpg&quot;);
if($size[0]>0 && $size[1]>0)
echo &quot;<td><img src=\&quot;../pics_etc/products/&quot;.$product[&quot;productId&quot;].&quot;.jpg\&quot; border=0 &quot;.$size[3].&quot;></td>&quot;;
}
echo &quot;<td><ul>&quot;;

echo &quot;<li><b>productId:</b> &quot;;
echo $product[&quot;productId&quot;];
echo &quot;<li><b>Our Price:</b> &quot;;
echo number_format($product[&quot;price&quot;], 2);
echo &quot;<li><b>Description:</b> &quot;;
echo $product[&quot;lng_desc&quot;];
echo &quot;</ul></td></tr></table>&quot;;
}
else
echo &quot;The details of this product cannot be displayed at this time.&quot;;
echo &quot;<hr>&quot;;
}

function display_checkout_form()
{
//display the form that asks for name and address
?>
<br>
<table border = 0 width = 100% cellspacing = 0>
<form action = purchase.php method = post>
<tr><th colspan = 2 bgcolor=&quot;#cccccc&quot;>Your Details</th></tr>
<tr>
<td>Name</td>
<td><input type = text name = name value = &quot;&quot; maxlength = 40 size = 40></td>
</tr>
<tr>
<td>Address</td>
<td><input type = text name = address value = &quot;&quot; maxlength = 40 size = 40></td>
</tr>
<tr>
<td>City/Suburb</td>
<td><input type = text name = city value = &quot;&quot; maxlength = 20 size = 40></td>
</tr>
<tr>
<td>State/Province</td>
<td><input type = text name = state value = &quot;&quot; maxlength = 20 size = 40></td>
</tr>
<tr>
<td>Postal Code or Zip Code</td>
<td><input type = text name = zip value = &quot;&quot; maxlength = 10 size = 40></td>
</tr>
<tr>
<td>Country</td>
<td><input type = text name = country value = &quot;&quot; maxlength = 20 size = 40></td>
</tr>
<tr><th colspan = 2 bgcolor=&quot;#cccccc&quot;>Shipping Address (leave blank if as above)</th></tr>
<tr>
<td>Name</td>
<td><input type = text name = ship_name value = &quot;&quot; maxlength = 40 size = 40></td>
</tr>
<tr>
<td>Address</td>
<td><input type = text name = ship_address value = &quot;&quot; maxlength = 40 size = 40></td>
</tr>
<tr>
<td>City/Suburb</td>
<td><input type = text name = ship_city value = &quot;&quot; maxlength = 20 size = 40></td>
</tr>
<tr>
<td>State/Province</td>
<td><input type = text name = ship_state value = &quot;&quot; maxlength = 20 size = 40></td>
</tr>
<tr>
<td>Postal Code or Zip Code</td>
<td><input type = text name = ship_zip value = &quot;&quot; maxlength = 10 size = 40></td>
</tr>
<tr>
<td>Country</td>
<td><input type = text name = ship_country value = &quot;&quot; maxlength = 20 size = 40></td>
</tr>
<tr>
<td colspan = 2 align = center>
<b>Please press Purchase to confirm your purchase,
or Continue Shopping to add or remove items</b>
<? display_form_button(&quot;purchase&quot;, &quot;Purchase These Items&quot;); ?>
</td>
</tr>
</form>
</table><hr>
<?
}

function display_shipping($shipping)
{
// display table row with shipping cost and total price including shipping
global $total_price;
?>
<table border = 0 width = 100% cellspacing = 0>
<tr><td align = left>Shipping</td>
<td align = right> <?=number_format($shipping, 2); ?></td></tr>
<tr><th bgcolor=&quot;#cccccc&quot; align = left>TOTAL INCLUDING SHIPPING</th>
<th bgcolor=&quot;#cccccc&quot; align = right>$<?=number_format($shipping+$total_price, 2); ?></th>
</tr>
</table><br>
<?
}

function display_card_form($name)
{
//display form asking for credit card details
?>
<table border = 0 width = 100% cellspacing = 0>
<form action = process.php method = post>
<tr><th colspan = 2 bgcolor=&quot;#cccccc&quot;>Credit Card Details</th></tr>
<tr>
<td>Type</td>
<td><select name = card_type><option>VISA<option>MasterCard<option>American Express</select></td>
</tr>
<tr>
<td>Number</td>
<td><input type = text name = card_number value = &quot;&quot; maxlength = 16 size = 40></td>
</tr>
<tr>
<td>AMEX code (if required)</td>
<td><input type = text name = amex_code value = &quot;&quot; maxlength = 4 size = 4></td>
</tr>
<tr>
<td>Expiry Date</td>
<td>Month <select name = card_month><option>01<option>02<option>03<option>04<option>05<option>06<option>07<option>08<option>09<option>10<option>11<option>12</select>
Year <select name = card_year><option>00<option>01<option>02<option>03<option>04<option>05<option>06<option>07<option>08<option>09<option>10</select></td>
</tr>
<tr>
<td>Name on Card</td>
<td><input type = text name = card_name value = &quot;<?=$name; ?>&quot; maxlength = 40 size = 40></td>
</tr>
<tr>
<td colspan = 2 align = center>
<b>Please press Purchase to confirm your purchase,
or Continue Shopping to add or remove items</b>
<? display_form_button(&quot;purchase&quot;, &quot;Purchase These Items&quot;); ?>
</td>
</tr>
</table>
<?
}



function display_cart($cart, $change = true, $images = 1)
{
// display items in shopping cart
// optionally allow changes (true or false)
// optionally include images (1 - yes, 0 - no)

global $items;
global $total_price;

echo &quot;<table border = 0 width = 100% cellspacing = 0>
<form action = show_cart.php method = post>
<tr><th colspan = &quot;. (1+$images) .&quot; bgcolor=\&quot;#cccccc\&quot;>Item</th>
<th bgcolor=\&quot;#cccccc\&quot;>Price</th><th bgcolor=\&quot;#cccccc\&quot;>Quantity</th>
<th bgcolor=\&quot;#cccccc\&quot;>Total</th></tr>&quot;;

//display each item as a table row
foreach ($cart as $productID => $qty)
{
$product = get_product_details($productID);
echo &quot;<tr>&quot;;
if($images ==true)
{
echo &quot;<td align = left>&quot;;
if (file_exists(&quot;\..\pics_etc\products\$productID.jpg&quot;))
{
$size = GetImageSize(&quot;\..\pics_etc\products&quot;.$productID.&quot;.jpg&quot;);
if($size[0]>0 && $size[1]>0)
{
echo &quot;<img src=\&quot;\..\pics_etc\products&quot;.$productID.&quot;.jpg\&quot; border=0 &quot;;
echo &quot;width = &quot;. $size[0]/3 .&quot; height = &quot; .$size[1]/3 . &quot;>&quot;;
}
}
else
echo &quot; &quot;;
echo &quot;</td>&quot;;
}
echo &quot;<td align = left>&quot;;
echo &quot;<a href = \&quot;show_product.php?productId=&quot;.$productID.&quot;\&quot;>&quot;.$product[&quot;title&quot;].&quot;</a> by &quot;.$product[&quot;author&quot;];
echo &quot;</td><td align = center>$&quot;.number_format($product[&quot;price&quot;], 2);
echo &quot;</td><td align = center>&quot;;
// if we allow changes, quantities are in text boxes
if ($change == true)
echo &quot;<input type = text name = \&quot;$productID\&quot; value = $qty size = 3>&quot;;
else
echo $qty;
echo &quot;</td><td align = center>$&quot;.number_format($product[&quot;price&quot;]*$qty,2).&quot;</td></tr>\n&quot;;
}
// display total row
echo &quot;<tr>
<th colspan = &quot;. (2+$images) .&quot; bgcolor=\&quot;#cccccc\&quot;> </td>
<th align = center bgcolor=\&quot;#cccccc\&quot;>
$items
</th>
<th align = center bgcolor=\&quot;#cccccc\&quot;>
\$&quot;.number_format($total_price, 2).
&quot;</th>
</tr>&quot;;
// display save change button
if($change == true)
{
echo &quot;<tr>
<td colspan = &quot;. (2+$images) .&quot;> </td>
<td align = center>
<input type = hidden name = save value = true>
<input type = image src = \&quot;images/save-changes.gif\&quot;
border = 0 alt = \&quot;Save Changes\&quot;>
</td>
<td> </td>
</tr>&quot;;
}
echo &quot;</form></table>&quot;;
}

function display_login_form()
{
// dispaly form asking for name and password
?>
<form method=post action=&quot;admin.php&quot;>
<table bgcolor=#cccccc>
<tr>
<td>Username:</td>
<td><input type=text name=username></td></tr>
<tr>
<td>Password:</td>
<td><input type=password name=passwd></td></tr>
<tr>
<td colspan=2 align=center>
<input type=submit value=&quot;Log in&quot;></td></tr>
<tr>
</table></form>
<?
}

function display_admin_menu()
{
?>
<br>
<a href=&quot;index.php&quot;>Go to main site</a><br>
<a href=&quot;insert_category_form.php&quot;>Add a new category</a><br>
<a href=&quot;insert_product_form.php&quot;>Add a new product</a><br>
<a href=&quot;change_password_form.php&quot;>Change admin password</a><br>
<?

}

function display_button($target, $image, $alt)
{
echo &quot;<center><a href=\&quot;$target\&quot;><img src=\&quot;images/$image&quot;.&quot;.gif\&quot;
alt=\&quot;$alt\&quot; border=0 height = 50 width = 135></a></center>&quot;;
}

function display_form_button($image, $alt)
{
echo &quot;<center><input type = image src=\&quot;images/$image&quot;.&quot;.gif\&quot;
alt=\&quot;$alt\&quot; border=0 height = 50 width = 135></center>&quot;;
}

?>
 
If that's the code you're using, I see you're missing some \ characters to escape the &quot;'s in your <img links. The string you have is ending prematurely because of these un-escaped double quotes. Artificial Intelligence is no match for Natural Stupidity
 
That's true but the code isn't getting to the <img links as there is something wrong with the file_exists Statements and also the line that generate the product links are generating &quot;show_product.php?productid&quot; so there must be something awry with the ($row[&quot;productid&quot;]) code
 
Are you getting an error message here? --Acoyauh
&quot;Artificial Intelligence is no match for Natural Stupidity&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top