Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text box value into a variable

Status
Not open for further replies.

james0816

Programmer
Jan 9, 2003
295
US
I have the following input text box in my form:

<form>
<input type="text" name="dnum" value="" size="30">
</form>


how do I put this into a variable to pass to another page?

thx
 
When the form this element is in is submitted, it will automatically be passed to the page it's submitted to. Since you didn't specify the method, it will be handled as a "GET" and passed in the URL.

If you're asking how to put the value into a PHP variable without submitting the form, it can't be done. PHP functions server side, and doesn't have any connections to the web page once the server has sent the HTML to the client.

Lee
 
my form is a POST do i need to change it to GET??
 
No, just usethe $_POST superglobal instead:

Code:
$muvariable=$_POST['[red]dnum[/red]'];

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
You need to show your actual code, copied and pasted from what you wrote. If you show fake code, how do you expect to get real answers?

Lee
 
i obviously am missing the boat here. i tried coding as you said but it doesnt display on the next page. Here are the snippets of code:

from the first page (this is the action to go to the new page)

$insertGoTo = "AddConfirm.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));

my form:
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td colspan="2" align="right" nowrap><div align="center">You adding the following information: </div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Drawing # :</td>
<td><input type="text" name="dnum" value="" size="30"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>


and the statement on the second page to get the value:

</head>
<?php
$a=$_POST['dnum'];
?>
<body>

<?php echo $a; ?>
 


First you have this bit of code:

Code:
 $insertGoTo = "AddConfirm.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));


But then you have this in your form:

Code:
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">...

You have two things that send the browser to different places. One is most certainly going to nullify the other one.

What is in $editFormAction? If it is the same page that has the form and the redirect code, then the only thing that is going to happen is the borwser will get sent to AddConfirm.php and that's it, no values get passed, and nothing happens.






----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
ok...here is the editformaction:

$editFormAction = $_SERVER['PHP_SELF'];
 
better yet....this is the whole snippet:

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO main (dnum, dvnum, drev, dtype, ddesc, dloc, dvend, dsys, dssys, dkey) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['dnum'], "text"),
GetSQLValueString($_POST['dvnum'], "text"),
GetSQLValueString($_POST['drev'], "text"),
GetSQLValueString($_POST['dtype'], "text"),
GetSQLValueString($_POST['ddesc'], "text"),
GetSQLValueString($_POST['dloc'], "text"),
GetSQLValueString($_POST['dvend'], "text"),
GetSQLValueString($_POST['dsys'], "text"),
GetSQLValueString($_POST['dssys'], "text"),
GetSQLValueString($_POST['dkey'], "text"));

mysql_select_db($database_BirchTest, $BirchTest);
$Result1 = mysql_query($insertSQL, $BirchTest) or die(mysql_error());

$insertGoTo = "AddConfirm.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
 
I think you have a flaw in your logic.

You press the submit button, and it sends the values to itself. then it processess the values puts them in a database. and when its done, goes to another page (addconfirm.php and sends the values in the address bar) So far so good.

but then you want to display those values in addconfirm.php correct?

Wel thosevaluesare now being sent in the address bar, so are back to being in the $_GET superglobal.

You need to read up on superglobals and how they work. and hwere the information you expect is going to be.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I've tried both the $_GET and the $_POST but nothing gets displayed on the AddConfirm page. What am I missing?

thx
 
james
i'm not convinced you've posted the whole snippet just yet.
can we see the code for the form aswell
and the getsqlvaluestring function
and your code for addconfirm.php

and can you also explain why you are retaining the querystring for each location redirect? not sure it's relevant but just in case.

earlier in the post you refer to $_POST on a "second page". of course the form values are those that are stored in the POST superglobal and from your comments above it seems that the form is submitted to the same page that generates the form. that means that the POST variables will not be present in addconfirm.php, of course.

you may have been oversimplifying addconfirm.php for the purposes of this post. in which case, please post the unadulterated code here as requested above.

what you might consider doing is capturing the last_insert_id on the processing page (if you are using an auto_increment), pass it through to your confirmation page (probably in the query string or a session variable) and then use addconfirm.php to do a db lookup on the primary key. or just use phpmyadmin to check for a correct insert: the db insert code looks ok to me (assuming all your data types are correctly cast)
 
Do you get any errors/warnings when you try to diplay the values in addconfirm.php?

Does it just remain blank?

When your browser gets redirected to to addconfirm.php, are you seeing values in the address bar?

I would second jpadie suggestion, and request that you post addconfirm.php's code. So we can see what is wrong.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top