Page 1 of 2

referencing a text field

Posted: Sun Feb 19, 2006 11:52 am
by aceconcepts
Hi,

how do i reference a text field when trying to send its value to another file?

i.e. i have a text field called 'newQty', i want to be able to reference this field from within the same file.

Using php variables you would write $newQty but as i am using an html text field i dont know how to call it.

Probably rather simple.

Thanks.

Nick

Posted: Sun Feb 19, 2006 12:15 pm
by MinDFreeZ
since its a .html file you need to make the external php file...

so on form action="name_of_external_file.php" ... and that file will handle the form...

could u show the page or give the code, or an example of what you're trying to do?

Posted: Sun Feb 19, 2006 12:57 pm
by aceconcepts
What i have is a php file in which i have an html text field. I would like to be able to reference this field using php within the same file. (the html field is not part of a form).

Nick

Posted: Sun Feb 19, 2006 1:13 pm
by feyd
the field will not exist to php unless it is submitted to the script.

Posted: Sun Feb 19, 2006 1:15 pm
by aceconcepts
how can i submit the value of that field via a url/link and not using a form $_POST?

Posted: Sun Feb 19, 2006 1:49 pm
by MinDFreeZ
wait.. nvm.. just saw ur other post....

um... what are you trying to do? reference what's in the text field before anyone puts anything there?

I don't get it.. show an example...

it has to be submitted, like feyd said..
you can submit it to itself using php_self or just action=""

Posted: Sun Feb 19, 2006 2:09 pm
by aceconcepts
sorry about this, im rather new to php.

Basically what im trying to do is send the user's input of the text field to an additional php file.

If it is possible, i would like to be able to send via a url.

Here is an example of what i cuurently send via url:

<td align="center"><a href="update_product.php?type=product&id=$pID">[view]</a></td>

$pID is the id code for a product in a table. This send perfectly.

How can i attach the input value to the url show above?

Thanks.

Posted: Sun Feb 19, 2006 2:18 pm
by MinDFreeZ
use the same form action to where ur form is going, use $_GET ... then the name of the textarea


here... go here
http://enhancedworks.com/temp.php

type in some text in the first box and hit submit...

is that what you're trying to do? except go to a dif page? (not just a dif. text area)

Posted: Sun Feb 19, 2006 3:04 pm
by aceconcepts
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


here is the code i am using to get the table data:

Code: Select all

$product_details .=<<<EOD

<tr bgcolor="#CACFE3">
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pID</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pCode</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pName</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">£$pDesc</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">£$pQtyPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pQtyEAPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pCostPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pPricePP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pCostEAPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pPriceEAPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pStockQty</font></td>
	<td align="center"><input name="newQty" type="text" id="newQty" maxlength="20"></td>
	<td align="center"><a href="update_product.php?type=product&id=$pID">[view]</a></td>
</tr>

EOD;
the form is defined earlier in the file.

When i submit the input data i cannot echo it on the additional php page!


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Feb 19, 2006 3:18 pm
by MinDFreeZ
hold on...

<input name="newQty" type="text" id="newQty" maxlength="20"> is supposed to be ..... added to the ... link ?

Posted: Sun Feb 19, 2006 3:27 pm
by aceconcepts
yeh, i would like to send the value of newQty text field via the link.

Is this possible?

Posted: Sun Feb 19, 2006 4:30 pm
by MinDFreeZ
yea, it's possible.. whether you use php or javascript I'm sure it can be done..
can u give us the code to the first form used? .. or is that through many pages? .. or what...

basically we need to see the forms used, and the names of each variable, and the full link outputted.... and it shouldn't be too hard

Posted: Sun Feb 19, 2006 4:34 pm
by aceconcepts
the only outputted value is from the a href link i posted earlier anf the body of the form is basically the script i posted earlier.

Posted: Sun Feb 19, 2006 4:47 pm
by MinDFreeZ
ok basically... the input newQty .... obviously input's go in <form> ... so that form can use get or post, i really dont know/care ... because update_product.php is the one handling what is done with it.... know what I mean? ... if you use GET it shows up in the URL, if you use POST it doesn't...

if that doesnt make sense, I don't know what else to say.. we need the actual <form action= whatever method=whatever... and all that noise... I know you're showing the actual code from the script, but not enough of it, or explaining whats being done.. maybe that's just me tho :P

maybe give us a link with an example of what ur trying to do?

Posted: Sun Feb 19, 2006 5:18 pm
by aceconcepts
I have removed the form definition because it didn't actually do anything.

Can you please illustrate how i can setup the form within the code so that i can pass the newQty value.

Code: Select all

<?php
include "auth.inc.php";
include "b2b_header.php";
//CONNECT TO SERVER AND DATABASE
$link = mysql_connect("localhost", "root", "mysqlpass")
	or die(mysql_error());
mysql_select_db("ace_concepts_b2b")
	or die(mysql_error());
	
$query = "SELECT * FROM product";

$result = mysql_query($query, $link)
	or die(mysql_error());
$num_orders = mysql_num_rows($result);

$product_header =<<<EOD
<table width="760" height="25">
<tr bgcolor="#CACFE3">
	<th><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><center>Product List</center></strong></font></th>
</tr>
</table>
<table width="760" border="0" cellpadding="1"
	cellspacing="1" align="left">
	<tr bgcolor="#000066">
	<th width="60"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>ID</strong></font></th>
	<th width="70" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Code</strong></font></th>
	<th width="70" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Name</strong></font></th>
	<th width="70" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Desc</strong></font></th>
	<th width="80" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Qty p/p</strong></font></th>
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Qty e/a/p/p</strong></font></th>
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Cost p/p</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Price p/p</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Cost e/a/p/p</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Price e/a/p/p</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Stock Qty</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Update Qty</strong></font></th>	
	</tr>
EOD;

$product_details = '';
while ($row = mysql_fetch_array($result)) {
$pID = $row['product_id'];
$pCode = $row['prod_code'];
$pName = $row['prod_name'];
$pDesc = $row['prod_description'];
$pQtyPP = $row['prod_qty_pp'];
$pQtyEAPP = $row['prod_qty_ea_pp'];
$pCostPP = $row['prod_cost_pp'];
$pPricePP = $row['prod_price_pp'];
$pCostEAPP = $row['prod_cost_ea_pp'];
$pPriceEAPP = $row['prod_price_ea_pp'];
$pStockQty = $row['prod_stock_qty'];

$product_details .=<<<EOD

<tr bgcolor="#CACFE3">
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pID</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pCode</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pName</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">£$pDesc</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">£$pQtyPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pQtyEAPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pCostPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pPricePP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pCostEAPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pPriceEAPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pStockQty</font></td>
	<td align="center"><input name="newQty" type="text" id="newQty" maxlength="20"></td>
	<td align="center"><a href="update_product.php?type=product&id=$pID?qty=$txtQty">[view]</a></td>
</tr>

EOD;
}

$product_details .<<<EOD
	<tr>
	<td>&nbsp;</td>
	</tr>
	<tr>
	<td>Total :$num_products Products</td>
	</tr>
EOD;

$product_footer="</table>";

$product=<<<PRODUCTS
	$product_header
	$product_details
	$product_footer
	
PRODUCTS;
?>
<html><body><br>
<font color="#000000"></font><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">The list consists of <?php echo $num_products; ?> products.</font>

<?php
//echo "Your account history consists of $num_orders orders.";
echo $product;
?>
Thanks