Can someone explain why this throws up a parse error??
PHP Code:<?php
$pd = $_GET['pd'];
?>
...
<?php include ($pd'.php'); ?>
Thanks, Neil.
Can someone explain why this throws up a parse error??
PHP Code:<?php
$pd = $_GET['pd'];
?>
...
<?php include ($pd'.php'); ?>
Thanks, Neil.
(\__/)
(='.'=)
(")_(")
You need to concat the $pd and '.php' with a '.'.
include ($pd . '.php');
nvening (05-10-2009)
thats strange, i swear i tried that before and it didnt work :s - haha strange, thats for your help anyway, it works now!
(\__/)
(='.'=)
(")_(")
Ok, next problem
is not adding one to the $pd varible, it simply stays the samePHP Code:<a href="products.php?pd=<?php echo($pd++);?>">Next</a>
edit:
Also how do would i make that link not display if the $pd++ variable was not set in my array?
Thanks![]()
(\__/)
(='.'=)
(")_(")
nvening (07-10-2009)
Validate your data! - Including whatever $_GET['pd'] has is a big security issue! There are tutorials, but best method tbh is limit what can be in the URL, so simply adding something like:
[code=php]if(!is_numeric($_GET['pd'])){ die(); }[/code] Will stop the page from loading because pd isnt numeric, you can use regular expressions to allow alpha numeric.
nvening (07-10-2009)
Ah, cheers for thatr aidanjt
And i came up with an if statment (i was a bit coded out when i couldnt work out how to do it last night!) but im having a strange issue.
The code is as follows:
The strange thing is that this works fine for the Next, with the link being removed when no more values exist, but the Previous results in $pd being echoed not --$pd.PHP Code:<?php
$next = ++$pd;
$previous = --$pd;
$product = array("ring","bracelet","anklet","earing");
if (array_key_exists($previous, $product))
{
echo "<a href=\"products.php?pd=".$previous."\">Previous</a>";
}
if (array_key_exists($next, $product))
{
echo "<a href=\"products.php?pd=".$next."\">Next</a>";
}
?>
Any ideas what could be causing this?
And thanks for the security tip, im working on something along those lines for when the code is more mature![]()
(\__/)
(='.'=)
(")_(")
That worked great thanks!
Could you explain why writing it out in long form, ie $pd + 1 is different from ++$pd??? I thought all ++ was was shorthand?
(\__/)
(='.'=)
(")_(")
++$pd is shorthand for $pd = $pd + 1;, so what you were doing there was $next = $pd = $pd + 1;. Then, when you did $previous = --$pd what you did was $previous = $pd = $pd - 1; after $pd was already incremented, the value of $pd was changed back to it's original value and assigned to $previous and $pd.
urgh, this is getting irritating. Why is this if statment executing the if statment and not the elseif statment?
Code of products filePHP Code:
$product = array("ring","bracelet","anklet","earing");
$page = "pd_det";
<?php
if ($page = "products")
{
include ("products/products.php");
}
elseif ($page = "pd_det")
{
include ("products/product_details/" . $product[$pd] . ".php");
}
?>
PHP Code:<div id="pdcont">
<div id="pdimgcont">
<a id="pdimg" href="index.php?page=pd_det&pd=<?php echo("{$product[$pd]}");?>" title="<?php echo("{$product[$pd]}");?>"><span><?php echo("{$product[$pd]}");?></span></a>
</div>
<div id="sketchcont">
<img src="products/products_img/sketch/<?php echo("{$product[$pd]}");?>.jpg"/>
<?php if (array_key_exists($previous, $product))
{
echo "<a href=\"index.php?page=\products&pd=".$previous."\">Previous</a>";
}
if (array_key_exists($next, $product))
{
echo "<a href=\"index.php?page=\products&pd=".$next."\">Next</a>";
}
?>
</div>
</div>![]()
(\__/)
(='.'=)
(")_(")
There are currently 1 users browsing this thread. (0 members and 1 guests)