Support » How-To and Troubleshooting » Forwarding page to URL with unique ID

Forwarding page to URL with unique ID

  • HI,

    I am trying to redirect my page to a URL with a unique ID. The unique ID is taken from the hidden field on mysql table.

    here is the code


    header(“Location: http://www.mysite.com/mycheck/?id=$id“);

    Now, i do get redirected to the correct page, but the ID field is blank. for some reason the variable $id does not get the unique ID from the form.

    URL looks like this: http://www.mysite.com/mycheck/?id=

    please help.

Viewing 15 replies - 1 through 15 (of 19 total)
  • Hi

    1) Try using this function to add the ID # to the redirect URL:
    WordPress strips off query vars its not made aware of in advance

    2) use this
    instead of “header(“Location”

    hey, thank you for the reply.

    now the code is like this:

    wp_redirect( ‘http://www.mysite.com/mycheck/?id=$id’, 301 ); exit; ?>

    we are getting closer, the URL is doing this now: http://www.mysite.com/mycheck/?id=id

    instead of the id number, it is throwing id

    it is actually

    wp_redirect( ‘http://www.mysite.com/mycheck/?id=$id’, 301 ); exit; ?>

    i am not using GET

    You are passing the ID on the URL in the redirect statement. Any query params passed on a URL are by definition a GET – that is what a GET is. WordPress strips off unknown GET params. You can make WP aware of unknown params like ID by using the function I linked you to.

    are you talking about this type of a function

    // This would output whatever the URL to post ID 9 is, with ‘hello=there’ appended with either ? or &, depending on what’s needed
    echo add_query_arg( ‘hello’, ‘there’, get_permalink(9) );

    $location = add_query_arg( 'id', $id, 'http://www.mysite.com/mycheck/' );
    wp_redirect( $location, 301 );

    hm, now for some reason the link does not pick up /?id

    it looks like this

    its the $id thats giving the issue. its not resolving it for some reason

    To debug do an echo statement in your code just before using the $id to confirm it in fact has a visible value. Depending on where in your code it is you might have to look at the browser View Source to see it.

    yup ive done that. there is no value

    <input name=”id” type=”hidden” value=””></td>

    I don’t know if what you just reported is what I suggested doing.

    Put the echo BEFORE the $location = line in the code below, to make sure the variable $id you are trying to pass as a query param has a value at the time you are adding it onto the URL. If it has no value that is your problem. That is a problem before the redirect occurs. You have to find out why.

    echo $id;
    $location = add_query_arg( 'id', $id, 'http://www.mysite.com/mycheck/' );
    wp_redirect( $location, 301 );

    yes this is where the problem is. $id does not have a value.

    this is the way this site suppose to work:

    1. submit an order from the form
    2. write to the db and reads the table with unique id (auto increment) (hidden value) and displays it.

    but i cannot figure out why i cant pull the unique ID for that particular order.

    Have you looked in the database to make sure that order HAS a unique ID?

    Are you sure the variable $id is in scope when you are trying to use it? Meaning, if it is declared in a different function than the one you are trying to use it in, you have to declare it as global in the function, or else set its value again from the $_POST variable.

    The real issue is, after you submit the form, check the value of $_POST and make sure the variable [‘id’] has been set.

    Also, in the hidden form field I’m pretty sure you have to echo the value

    <input type="hidden" value="<?php echo $id; ?>" />

    ok so simply put, this is what i have for my form

    <form name="myWebForm" action="testorder" method="post">
    First: <input title="Please Enter Your First Name" id="first" name="first" type="text" size="12" maxlength="12" /> Last: <input title="Please Enter Your Last Name" id="last" name="last" type="text" size="18" maxlength="24" /><br />
    <input type="hidden" name="orderNumber" id="orderNumber" value="<?php echo $orderNumber; ?>" /><br />
    <input type="submit" value="SUBMIT" />
    <input type="reset" value="RESET" />

    this is my php code:

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    // get data that sent from form
    $sql="INSERT INTO $tbl_name(orderNumber, first, last) VALUES('$orderNumber', '$first', '$last')";
    echo "Successful<BR>";
    echo $orderNumber;
    echo $first;
    else {
    echo "ERROR";

    now, $first is outputting everything correctly. but the orderNumber is giving me no results.

    this is my code for the table:

    CREATE TABLEtestform` (
    orderNumber int(6) NOT NULL auto_increment,
    first varchar(65) NOT NULL default ”,
    last varchar(65) NOT NULL default ”,
    KEY orderNumber (orderNumber)
    ) TYPE=MyISAM;`

    Any help would be greatly appreciated. I need to find out a way to spit out the orderNumber

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Forwarding page to URL with unique ID’ is closed to new replies.