Hi
1) Try using this function to add the ID # to the redirect URL:
http://codex.wordpress.org/Function_Reference/add_query_arg
WordPress strips off query vars its not made aware of in advance
2) use this
http://codex.wordpress.org/Function_Reference/wp_redirect
instead of “header(“Location”
Thread Starter
nisals
(@nisals)
hey, thank you for the reply.
now the code is like this:
$id=$_GET[‘id’];
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
Thread Starter
nisals
(@nisals)
it is actually
$id=$_POST[‘id’];
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.
Thread Starter
nisals
(@nisals)
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) );
<?php
$location = add_query_arg( 'id', $id, 'http://www.mysite.com/mycheck/' );
wp_redirect( $location, 301 );
exit;
?>
Thread Starter
nisals
(@nisals)
hm, now for some reason the link does not pick up /?id
it looks like this
http://www.mysite.com/mycheck/
Thread Starter
nisals
(@nisals)
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.
Thread Starter
nisals
(@nisals)
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.
<?php
echo $id;
$location = add_query_arg( 'id', $id, 'http://www.mysite.com/mycheck/' );
wp_redirect( $location, 301 );
exit;
?>
Thread Starter
nisals
(@nisals)
yes this is where the problem is. $id does not have a value.
Thread Starter
nisals
(@nisals)
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; ?>" />
Thread Starter
nisals
(@nisals)
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" />
</form>
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
$orderNumber=$_POST['orderNumber'];
$first=$_POST['first'];
$last=$_POST['last'];
$sql="INSERT INTO $tbl_name(orderNumber, first, last) VALUES('$orderNumber', '$first', '$last')";
$result=mysql_query($sql);
if($result){
echo "Successful<BR>";
echo $orderNumber;
echo $first;
}
else {
echo "ERROR";
}
mysql_close();
?>
now, $first is outputting everything correctly. but the orderNumber is giving me no results.
this is my code for the table:
CREATE TABLE
testform` (
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