Results 1 to 12 of 12

Thread: quick php problem

  1. #1
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts

    quick php problem

    Can someone explain why this throws up a parse error??
    PHP Code:
    <?php
    $pd 
    $_GET['pd']; 
    ?>

    ...

    <?php include ($pd'.php'); ?>


    Thanks, Neil.
    (\__/)
    (='.'=)
    (")_(")

  2. #2
    Senior Member
    Join Date
    Jan 2009
    Location
    London
    Posts
    350
    Thanks
    6
    Thanked
    48 times in 42 posts
    • sadbuttrue's system
      • Motherboard:
      • Gigabyte P55 UD5
      • CPU:
      • i5 750 @ 3.8ghz + Megahalems + GT1450 @ 5v
      • Memory:
      • G.Skill ECO 4GB 1.4v
      • Storage:
      • Intel 320 120gb + Samsung F4 2tb in Scythe Quiet Drive
      • Graphics card(s):
      • 6950 @ 940/1350/1.175v + Shaman @ 20%
      • PSU:
      • Corsair AX750
      • Case:
      • Raven RV02 with 3xPhobya G-Silent Fans @ 210rpm + Scythe S-Flex 1200 @ 5v
      • Operating System:
      • Windows 7
      • Monitor(s):
      • Samsung 2233rz, Dell 2209wa, Panasonic AX200 Projector
      • Internet:
      • BeThere 24mb

    Re: quick php problem

    You need to concat the $pd and '.php' with a '.'.

    include ($pd . '.php');

  3. Received thanks from:

    nvening (05-10-2009)

  4. #3
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts

    Re: quick php problem

    thats strange, i swear i tried that before and it didnt work :s - haha strange, thats for your help anyway, it works now!
    (\__/)
    (='.'=)
    (")_(")

  5. #4
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts

    Re: quick php problem

    Ok, next problem

    PHP Code:
    <a href="products.php?pd=<?php echo($pd++);?>">Next</a>
    is not adding one to the $pd varible, it simply stays the same

    edit:

    Also how do would i make that link not display if the $pd++ variable was not set in my array?

    Thanks
    (\__/)
    (='.'=)
    (")_(")

  6. #5
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: quick php problem

    Do echo(++$pd) instead. $pd++ will return the value of $pd *then* increment by one. ++$pd does it the other way around (which is what you want).

    As for your other problem, use an if statement, something like if($pd) { printlinkcode... }.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  7. Received thanks from:

    nvening (07-10-2009)

  8. #6
    Alpha
    Join Date
    Jun 2008
    Location
    London
    Posts
    355
    Thanks
    26
    Thanked
    7 times in 6 posts
    • Nelsaidi's system
      • Motherboard:
      • Asus P5Qe IP45
      • CPU:
      • Intel E8400
      • Memory:
      • 2x2Gb Corsair PC2-6400
      • Storage:
      • Western Digital Caviar SE16 640Gb 7200rpm, Seagate 250gb 7200rpm
      • Graphics card(s):
      • Sapphire HD4850 512mb
      • PSU:
      • Corsair HX 520w
      • Case:
      • Antec 300
      • Operating System:
      • Windows 7
      • Monitor(s):
      • DEll Ultrasharp 17"
      • Internet:
      • AOL :(

    Re: quick php problem

    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.

  9. Received thanks from:

    nvening (07-10-2009)

  10. #7
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts

    Re: quick php problem

    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:

    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>";
    }
    ?>
    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.

    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
    (\__/)
    (='.'=)
    (")_(")

  11. #8
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: quick php problem

    $pd is being incremented, so when you decrement with --, then you're returning a number for the current page. Do something like this instead.

    PHP Code:
    $next $pd 1;
    $previous $pd 1
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  12. #9
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts

    Re: quick php problem

    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?
    (\__/)
    (='.'=)
    (")_(")

  13. #10
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: quick php problem

    ++$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.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  14. #11
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts

    Re: quick php problem

    urgh, this is getting irritating. Why is this if statment executing the if statment and not the elseif statment?

    PHP 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");
    }
    ?>
    Code of products file

    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>
    (\__/)
    (='.'=)
    (")_(")

  15. #12
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable

    Re: quick php problem

    one equal means assignment, two equals means comparison.

    $page is always true because you're assigning a string to $page before evaluating it, which will always be true because it's not zero or unset.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PHP and file uploads timing out too soon
    By McClane in forum Software
    Replies: 12
    Last Post: 02-12-2006, 05:57 PM
  2. Replies: 23
    Last Post: 08-08-2005, 11:05 AM
  3. Quick and easy PHP help needed chaps
    By Kezzer in forum Software
    Replies: 20
    Last Post: 23-02-2004, 07:45 PM
  4. php problem...
    By Joel in forum Software
    Replies: 2
    Last Post: 12-10-2003, 11:39 PM
  5. Replies: 4
    Last Post: 19-09-2003, 08:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •