• HEXUS
  • HEXUS.tv
  • channel
  • gaming
  • lifestyle
  • trust
  • community
  • ESReality
  • HEXUS.community discussion forumsVisit Corsair.com

    Welcome to the HEXUS.community discussion forums forums.

    You are currently viewing our boards as a guest which gives you limited access to view most discussions and other features. By joining our free community you will have access to post topics, respond to polls and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
    Go Back   HEXUS.community discussion forums > HEXUS.help - buying advice & technical queries > Operating systems & applications > Software and web development

    Software and web development Databases, graphics, programming, scripting and web development.

    Reply
     
    LinkBack Thread Tools
    Old 05-10-2009, 08:18 PM   #1 (permalink)
    my name is neil, hello
     
    nvening's Avatar
     
    Join Date: Jan 2005
    Location: London
    Posts: 4,543
    Thanks: 144
    Thanked 19 Times in 19 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.

    (\__/)
    (='.'=)
    (")_(")
    nvening is offline   Reply With Quote
    Old 05-10-2009, 08:21 PM   #2 (permalink)
    Member
     
    Join Date: Jan 2009
    Location: London
    Posts: 183
    Thanks: 4
    Thanked 22 Times in 22 Posts
    sadbuttrue's system
    Re: quick php problem

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

    include ($pd . '.php');
    sadbuttrue is offline   Reply With Quote
    Received thanks from:
    nvening (05-10-2009)
    Old 05-10-2009, 08:36 PM   #3 (permalink)
    my name is neil, hello
     
    nvening's Avatar
     
    Join Date: Jan 2005
    Location: London
    Posts: 4,543
    Thanks: 144
    Thanked 19 Times in 19 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!

    (\__/)
    (='.'=)
    (")_(")
    nvening is offline   Reply With Quote
    Old 05-10-2009, 09:36 PM   #4 (permalink)
    my name is neil, hello
     
    nvening's Avatar
     
    Join Date: Jan 2005
    Location: London
    Posts: 4,543
    Thanks: 144
    Thanked 19 Times in 19 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

    (\__/)
    (='.'=)
    (")_(")
    nvening is offline   Reply With Quote
    Old 06-10-2009, 03:28 PM   #5 (permalink)
    Gentoo Ricer
     
    Join Date: Jan 2005
    Location: /var/portage
    Posts: 6,200
    Thanks: 100
    Thanked 305 Times in 278 Posts
    aidanjt's system
    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... }.

    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...
    Server Box -> Asus P5B-E Plus | C2D E6320 | 2x2GB GieL PC2-6400 | 6x500GB (md-raid5) | nVidia 7300LE | Ubuntu Server 9.10 (for now)
    Test Box -> P4E 3.2Ghz Rev. E0 | Asus P4C800-E Deluxe | 2x1GB PC3200 | 2x160Gb | nVidia TNT 2 | Gentoo (X86)

    Currently breaking: eINIT
    aidanjt is offline   Reply With Quote
    Received thanks from:
    nvening (07-10-2009)
    Old 06-10-2009, 10:31 PM   #6 (permalink)
    Alpha
     
    Join Date: Jun 2008
    Location: London
    Posts: 255
    Thanks: 25
    Thanked 7 Times in 6 Posts
    Nelsaidi's system
    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.
    Nelsaidi is offline   Reply With Quote
    Received thanks from:
    nvening (07-10-2009)
    Old 07-10-2009, 12:07 AM   #7 (permalink)
    my name is neil, hello
     
    nvening's Avatar
     
    Join Date: Jan 2005
    Location: London
    Posts: 4,543
    Thanks: 144
    Thanked 19 Times in 19 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

    (\__/)
    (='.'=)
    (")_(")
    nvening is offline   Reply With Quote
    Old 07-10-2009, 01:37 AM   #8 (permalink)
    Gentoo Ricer
     
    Join Date: Jan 2005
    Location: /var/portage
    Posts: 6,200
    Thanks: 100
    Thanked 305 Times in 278 Posts
    aidanjt's system
    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

    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...
    Server Box -> Asus P5B-E Plus | C2D E6320 | 2x2GB GieL PC2-6400 | 6x500GB (md-raid5) | nVidia 7300LE | Ubuntu Server 9.10 (for now)
    Test Box -> P4E 3.2Ghz Rev. E0 | Asus P4C800-E Deluxe | 2x1GB PC3200 | 2x160Gb | nVidia TNT 2 | Gentoo (X86)

    Currently breaking: eINIT
    aidanjt is offline   Reply With Quote
    Old 07-10-2009, 11:08 AM   #9 (permalink)
    my name is neil, hello
     
    nvening's Avatar
     
    Join Date: Jan 2005
    Location: London
    Posts: 4,543
    Thanks: 144
    Thanked 19 Times in 19 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?

    (\__/)
    (='.'=)
    (")_(")
    nvening is offline   Reply With Quote
    Old 07-10-2009, 11:25 AM   #10 (permalink)
    Gentoo Ricer
     
    Join Date: Jan 2005
    Location: /var/portage
    Posts: 6,200
    Thanks: 100
    Thanked 305 Times in 278 Posts
    aidanjt's system
    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.

    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...
    Server Box -> Asus P5B-E Plus | C2D E6320 | 2x2GB GieL PC2-6400 | 6x500GB (md-raid5) | nVidia 7300LE | Ubuntu Server 9.10 (for now)
    Test Box -> P4E 3.2Ghz Rev. E0 | Asus P4C800-E Deluxe | 2x1GB PC3200 | 2x160Gb | nVidia TNT 2 | Gentoo (X86)

    Currently breaking: eINIT
    aidanjt is offline   Reply With Quote
    Old 07-10-2009, 07:00 PM   #11 (permalink)
    my name is neil, hello
     
    nvening's Avatar
     
    Join Date: Jan 2005
    Location: London
    Posts: 4,543
    Thanks: 144
    Thanked 19 Times in 19 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>

    (\__/)
    (='.'=)
    (")_(")
    nvening is offline   Reply With Quote
    Old 07-10-2009, 07:09 PM   #12 (permalink)
    Gentoo Ricer
     
    Join Date: Jan 2005
    Location: /var/portage
    Posts: 6,200
    Thanks: 100
    Thanked 305 Times in 278 Posts
    aidanjt's system
    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.

    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...
    Server Box -> Asus P5B-E Plus | C2D E6320 | 2x2GB GieL PC2-6400 | 6x500GB (md-raid5) | nVidia 7300LE | Ubuntu Server 9.10 (for now)
    Test Box -> P4E 3.2Ghz Rev. E0 | Asus P4C800-E Deluxe | 2x1GB PC3200 | 2x160Gb | nVidia TNT 2 | Gentoo (X86)

    Currently breaking: eINIT
    aidanjt is offline   Reply With Quote
    Reply

    Breadcrumb
    Go Back   HEXUS.community discussion forums > HEXUS.help - buying advice & technical queries > Operating systems & applications > Software and web development


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Trackbacks are On
    Pingbacks are On
    Refbacks are On


    Similar Threads
    Thread Thread Starter Forum Replies Last Post
    PHP and file uploads timing out too soon McClane Software and web development 12 02-12-2006 04:57 PM
    Right car peeps, I know a girl with a garage problem... MD HEXUS.automotive - Cars & Bikes 23 08-08-2005 11:05 AM
    Quick and easy PHP help needed chaps Kezzer Software and web development 20 23-02-2004 06:45 PM
    php problem... Joel Software and web development 2 12-10-2003 11:39 PM
    HARDCORE QUESTION: php/mssql/stored procedures problem dgr Software and web development 4 19-09-2003 08:25 AM



    All times are GMT. The time now is 09:56 AM.

    Any representations/statements made on the HEXUS.community discussion forums are the representations/statements of the author i.e. the person/organisation making them. If any such representations/statements are disputed they are a matter between the parties concerned.
    HEXUS Limited accepts no responsibility for any misrepresentations, inaccurate or false statements made by any person/organisation other than HEXUS Limited employees.
    For more information please read HEXUS Limited's terms, conditions and privacy policy.

    Hosted Exchange | Virtual Dedicated Server

    Powered by vBulletin® Version 3.8.4
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
    Content Relevant URLs by vBSEO 3.3.2
    Copyright © 2010 HEXUS® Limited. All rights reserved. Unauthorised reproduction strictly prohibited.