SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 51

Hybrid View

  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What could be wrong with this a tags link?

    PHP Code:
    <a href="<?php "menu.php?id="$_GET['id']. "".'&register='$_GET['register'?>">
    When I click on this link then it won't take me to menu.php I don't know what could be going wrong with the way it is script it.

    help

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,139
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    You will need to print the string using echo.

    PHP Code:
    <a href="<?php echo '/menu.php?id='$_GET['id'].'&register='$_GET['register'?>">

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    printf
    ('<a href="/menu.php?id=%d&register=%s">Register</a>'$_GET['id'], $_GET['register']);
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you guys!
    I have encounter something similar

    PHP Code:
    <?php 
    $ids
    = (int) $_GET['ids'];
    $id= (int) $_GET['id'];
    ?>    
    <a href=<?php echo "cart.php?action=remove_item&ids=" . echo $ids; .'&qty=1''&register='$_GET['register']. '&id='.intval($id).""?>>Remove</a>
    The above is passing ids= empty! before going to cart.php as in above in the url ids has a value then when I click remove in cart.php is passes empty to cart.php again.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,786
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by co.ador View Post
    The above is passing ids= empty! before going to cart.php as in above in the url ids has a value then when I click remove in cart.php is passes empty to cart.php again.
    That's because you have a syntax error immediately before the field is referenced. Get rid of the word "echo" that immediately precedes is as the dot before that is supposed to be concatenating it to the string that is already being echoed.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php echo "cart.php?action=remove_item&ids=" $ids'&qty=1''&register='$_GET['register']. '&id='.intval($id).""?>>
    the above is not working either. I have taken out the echo and don't know what else could be wrong. I don't know if that was the echo you meant!

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You need to read the error messages php is giving you, it will point out these typos for you, as will most IDEs.
    PHP Code:
    <?php
    printf
    (
        
    '<a href="cart.php?action=remove_item&ids=%s&qty=1&register=%s&id=%s">Remove</a>',
        
    $_GET['ids'],
        
    $_GET['register'],
        
    $_GET['id']
    );
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  8. #8
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have used this printf but nothing has come out any error or anything like that. I have also have done a print_r($_GET) and it would show id variable coming empty.

  9. #9
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you guys problems solved.
    The printf() function made it. It printed the exact values it was picking up from the url where as as I had was passing it as empty when I knew there was values in the url.

  10. #10
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I have a similar issue with a pagination script it just that it has a parse error and I can not see it, but I think the logic is ok.

    PHP Code:
     echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=1&name="$_POST['name']. '&zipcode=' $_POST['zipcode'] .'&state=' $_POST['state'] . '&food_types= ' $_POST['frmSearch']['food_types'][0]. '&offerings=' $_POST['frmSearch']['offerings'][0]"'
      ><<</a> "


    The whole script above is one line and that's line 513 and the browsers display an parse error as:

    Parse error: parse error, expecting `','' or `';'' in C:\wamp\www\nyhungry\indexpagination.php on line 513
    it says it is missing a '," or ';" I don't know where should it go. I have tried after ['offereings'][0]";' but it won't work. That's the only place my limited eyes can suspect of.

    help

  11. #11
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Try with a shorter string and gradually build it up, you'll find the error. You need to spend a little time learning this, string concatenation is staple I'm afraid.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  12. #12
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have notice the concatenation irregularity in the code, but it seems not to be the issue here. since it keeps throwing the same undefined message. Right now every single variable is passing as undefined.

    i think i should try printf() as in before

  13. #13
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    What undefined message?
    When you get error messages, please post them, it makes it so much easier to understand the problem.
    And please post your corrected code as well.

  14. #14
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now i don't know if the logic is good now, because it's not working properly the pagination links Help.


    PHP Code:
    <?php     
    if ( trim($_POST['name']) == '' $_POST['zipcode'] =='' $_POST['state'] =='' $_POST['frmSearch']['food_types'][0]=='' $_POST['frmSearch']['offerings'][0]==''// line 97

    //$strZipCode == '' && $strState == '' $arrFoodTypes =='' && $arrOfferings == '') 
    {

     echo 
    '<div id="tresuno">';
     
    var_dump($_POST);
     echo
    '<p class="tremendi">No results for your match please try again!</p>

    <div id="tresdo">
    <a href="index3.php"><< Go Back</a>

    </div>'
    ;} else {

    var_dump($_POST);
        
    $strName = isset($_POST['name'])?mysql_real_escape_string($_POST['name']):'';
        
    $strZipCode = isset($_POST['zipcode'])?mysql_real_escape_string($_POST['zipcode']):'';
        
    $strState = isset($_POST['state'])?mysql_real_escape_string($_POST['state']):'';
        
    $arrFoodTypes = isset($_POST['frmSearch']['food_types'])?$_POST['frmSearch']['food_types']:array();
        
    $arrOfferings = isset($_POST['frmSearch']['offerings'])?$_POST['frmSearch']['offerings']:array();


    <
    div id=pagination>
    <?
    php //
    //$arr= $arr= array( 'name'=>$strName,'zipcode'=>$strZipCode, 'state'=> $strState,'food_types'=> $arrFoodTypes, 'offerings'=>$arrOfferings);
    //$query3 = http_build_query($arr);

    /******  build the pagination links ******/
    // range of num links to show
    $range 4;

    // if not on page 1, don't show back links
    if ($currentpage 1) {
       
    // show << link to go back to page 1  
       
    echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=1&name="$_POST['name']. '&zipcode=' $_POST['zipcode'] .'&state=' $_POST['state'] . '&food_types= ' $_POST['frmSearch']['food_types'][0]. '&offerings=' $_POST['frmSearch']['offerings'][0]."'
      ><<</a> "
    ;
       
       
    // get previous page num
       
    $prevpage $currentpage 1;
       
    // show < link to go back to 1 page http_build_query( $strName,$strZipCode, $strState, $arrFoodTypes, $arrOfferings)
       
    echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&name="$_POST['name']. '&zipcode=' $_POST['zipcode'] .'&state=' $_POST['state'] . '&food_types= ' $_POST['frmSearch']['food_types'][0]. '&offerings=' $_POST['frmSearch']['offerings'][0]."'><</a> ";
    // end if 

    // loop to show links to range of pages around current page
    for ($x = ($currentpage $range); $x < (($currentpage $range) + 1); $x++) {

       
    // if it's a valid page number...
       
    if (($x 0) && ($x <= $totalpages)) {
          
    // if we're on current page...
          
    if ($x == $currentpage) { 
             
    // 'highlight' it but don't make a link
             
    echo " [<b >$x</b>] ";
          
    // if not current page...
          
          
    }
         
          else {
             
    // make it a link http_build_query( $strName,$strZipCode, $strState, $arrFoodTypes, $arrOfferings)
             
    echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
          } 
    // end else
       
    // end if 


    // end for
                     
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       
    // get next page
       
    $nextpage $currentpage 1;
        
    // echo forward link for next page http_build_query( $strName,$strZipCode, $strState, $arrFoodTypes, $arrOfferings)
       
    echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&name="$_POST['name']. '&zipcode=' $_POST['zipcode'] .'&state=' $_POST['state'] . '&food_types= ' $_POST['frmSearch']['food_types'][0]. '&offerings=' $_POST['frmSearch']['offerings'][0]."'>></a> ";// line 548
       // echo forward link for lastpage http_build_query( $strName,$strZipCode, $strState, $arrFoodTypes, $arrOfferings)
       
    echo  " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&name="$_POST['name']. '&zipcode=' $_POST['zipcode'] .'&state=' $_POST['state'] . '&food_types= ' $_POST['frmSearch']['food_types'][0]. '&offerings=' $_POST['frmSearch']['offerings'][0]."'>>></a> ";
    // line 550 end if


    }
    ?>
     }
    </div>
    <div class="clearer"></div>
    </div>
    </div>
    when I come from index.php to the page above indexpagination.php then automatically it will display this undefined index.

    Notice: Undefined index: offerings in C:\wamp\www\nyhungry\indexpagination.php on line 548
    >
    Notice: Undefined index: offerings in C:\wamp\www\nyhungry\indexpagination.php on line 550
    >>
    then when I click the > at the pagination link it will display that all the indexes in the links are undefined.

    <br />

    <b>Notice</b>: Undefined index: name in <b>C:\wamp\www\nyhungry\indexpagination.php</b> on line <b>97</b><br />
    <br />
    <b>Notice</b>: Undefined index: zipcode in <b>C:\wamp\www\nyhungry\indexpagination.php</b> on line <b>97</b><br />
    <br />
    <b>Notice</b>: Undefined index: state in <b>C:\wamp\www\nyhungry\indexpagination.php</b> on line <b>97</b><br />

    <br />
    <b>Notice</b>: Undefined index: frmSearch in <b>C:\wamp\www\nyhungry\indexpagination.php</b> on line <b>97</b><br />
    <br />
    <b>Notice</b>: Undefined index: frmSearch in <b>C:\wamp\www\nyhungry\indexpagination.php</b> on line <b>97</b><br />

  15. #15
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Undefined index means this

    $_POST['frmSearch']['offerings'][0]

    isn't set.
    I see you're doing a var_dump($_POST). What does it contain?

  16. #16
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's comins as

    vardump
    var_dump

    array(0) {
    }
    print_r
    print_r

    Array
    (
    )

  17. #17
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when i set it then it won't show the undefined: offerings, But it shouldn't display this error because sometimes users input will not include the offerings.

    well..

    that undefined message will goes away once it set to the else statement because in the else statement there is a test to if isset then else null. but right now is trying to get the indexes defined from the form to the pagination links and then return those fields defined.

    Some where in between the form and the pagination links the value is getting lost or the set up of the logic in the pagination links is wrong.

  18. #18
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i should pass it on through the pagination links rights?

    it is true is passing as empty. well then the logic or set up in here is wrong

    PHP Code:
    &name=". $_POST['name']. '&zipcode=' . $_POST['zipcode'] .'&state=' . $_POST['state'] . '&food_types= ' . $_POST['frmSearch']['food_types'][0]. '&offerings=' . $_POST['frmSearch']['offerings'][0]."' 
    mmm

  19. #19
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    let me do the var dump with $_GET

  20. #20
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    So you found the problem. There are no $_POST variables passed on to the script, and you are using them nevertheless.

  21. #21
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Btw, if those values are being passed by the link, then you should use $_GET instead of $_POST

  22. #22
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Do a print_r of $_REQUEST and see what it contains.

  23. #23
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    below is an print_r and a var_dump of $_REQUEST after paginating when coming from the form then the only difference is the submit index that will show up.
    Array
    (
    [currentpage] => 2
    [name] =>
    [zipcode] => 10468
    [state] =>
    [food_types] => Array
    [offerings] =>

    )
    array(7) {
    ["currentpage"]=>
    string(1) "2"
    ["name"]=>
    string(0) ""
    ["zipcode"]=>
    string(5) "10468"
    ["state"]=>
    string(0) ""
    ["food_types"]=>
    string(6) " Array"
    ["offerings"]=>
    string(0) ""

    }

  24. #24
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    It looks like there's no such thing as a $_REQUEST['frmSearch'], so maybe you should try

    $_REQUEST['food_types'][0]

    and

    $_REQUEST['offerings'][0]

    instead.
    Although 'offerings' doesn't seem to be an array, it's empty.

  25. #25
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    look at it now it is an array. It just going crazy and heated right now.

    I have taken out the ["frmsearch"] but still it will display some undifined messages!

    that's the var_dump below.
    array(6) {
    ["name"]=>
    string(0) ""
    ["zipcode"]=>
    string(5) "10468"
    ["state"]=>
    string(0) ""
    ["frmSearch"]=>
    array(2) {
    ["food_types"]=>
    array(1) {
    [0]=>
    string(1) "5"
    }
    ["offerings"]=>
    array(1) {
    [0]=>
    string(1) "5"
    }
    }


Bookmarks

Posting Permissions

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