Jump to content

how do i call this from another page?


esandra

Recommended Posts

$y is my variable that I increment by a for loop.

This variable determines the number of every row

 

..and then i'd concat'd $y with the name of

the textboxes of every column and row

 

      name="orno<?php echo $y;?>"

 

now, i'm not sure if i'm supposed to concat with the name

or should it be with the id?

 

HOW DO i CALL THE NAME FROM ANOTHER PAGE?

 

this is what I did and I don't know if this is right

 

    $orno= $_POST['orno'.$y];

 

and since I know I may not be

making much sense with my explaination above,

this is my add_content.php where it all starts

I've only included the part where the textboxes

are displayed by/within a loop and where the

names are concatenated with the variable $y.

I have dropdowns and textboxes for the date and

other elements above this.

<div id="slider">
	<ul>	
<?php
$num=$_GET['num'];//this here represents the number of rows
//of textboxes user wants to appear
//there are 5 textboxes in one row and 10 rows in one page
//this is a sliding page with jquery
$nump=$num / 10;
$y=1;//initializing y
for($j=1;$j<=$nump;$j++){//determines how many pages then loops accordingly
?>			
		<li>
            <p>
    <?php

    for($i=1;$i<=10;$i++){//loops 10 times to return 10 rows in a pages
	if(strlen($y)==1){
echo "0";
}
echo $y."      ";
?>
         <input name="orno<?php echo $y;?>" id="orno" type="text" size="3" maxlength="6" onKeyPress="return isNumberKey

(event)" value="<?php
if (isset($_POST['orno'])) {
	echo htmlspecialchars($_POST['orno'], ENT_QUOTES);
	}?>">
        
         <input name="billnmbr<?php echo $y;?>" id="billnmbr" type="text" size="16" maxlength="17" value="<?php
if (isset($_POST['billnmbr'])) {
	echo htmlspecialchars($_POST['billnmbr'], ENT_QUOTES);
	}?>">
        
        <input name="payor<?php echo $y;?>" id="payor" type="text" size="35" maxlength="50" value="<?php
if (isset($_POST['payor'])) {
	echo htmlspecialchars($_POST['payor'], ENT_QUOTES);
	}?>">
        
        <input name="arrastre<?php echo $y;?>" id="arrastre" type="text" size="7" maxlength="8" onKeyPress="return isMoneyKey

(event)" value="<?php
if (isset($_POST['arrastre'])) {
	echo htmlspecialchars($_POST['arrastre'], ENT_QUOTES);
	}?>">
        
        <input name="wharfage<?php echo $y;?>" id="wharfage" type="text" size="7" maxlength="8" onKeyPress="return isMoneyKey

(event)" value="<?php
if (isset($_POST['wharfage'])) {
	echo htmlspecialchars($_POST['wharfage'], ENT_QUOTES);
	}?>"><br />
        
        <?php $y++; }?>
        </p>
		</li>
<?php $y=$y; } ?>
	</ul>
</div>

then we go to add_save.php

this page is still very lacking because

I don't know how to evaluate then save

multiple rows yet since I've originally done

a page that saves one row at a time in which the

textboxes' names aren't from a loop and

were not concatenated.

<?php 

//please take a look at how I am calling the $_POSTs from the prev page
//what is the right way of calling concatenated names?
//or if there is a better way of calling these please let me know..

$year=$_POST['year'];
$month=$_POST['month'];
$day=$_POST['day'];
$date=$year."-".$month."-".$day;
    $billnmbr=$_POST['billnmbr'.$y]; 
    $orno= $_POST['orno'.$y]; 
    $payor=$_POST['payor'.$y];
    $arrastre=$_POST['arrastre'.$y];
    $wharfage=$_POST['wharfage'.$y];
    $total=$arrastre + $wharfage;
    $tcl=$_POST['tcl'];
$preparedby=$_POST['preparedby'];
$notedby=$_POST['notedby'];
$addedby=$_POST['addedby'];
$office=$_POST['office'];

    if($_POST['btnadd']){	
        if($billnmbr=="" or $orno=="" or $payor=="" or $arrastre=="" or $wharfage=="" or $year=="" or $month=="" or $day=="" 

or $tcl=="" or $preparedby=="" or $notedby=="" or $addedby=="" or $date=='2010-01-01'){
		?>
            <script>
            alert ('At least one field was left blank!');
		</script>
		<?php
            }
        else{
           $query = mysql_query("select * from `arrastre` WHERE `billnmbr`='$billnmbr'"); 
            $count = mysql_num_rows($query);
            if($count==1){//existing billnmbr
                echo "This billnumber is already in the database."; 			
            }
            else{
                $bll = strtoupper($billnmbr);
$explode_bill=explode("-",$bll);

$bill1 = 0;
$bill2 = 0;

$bill1 = $explode_bill[0];
$bill2 = $explode_bill[1];	

if(strlen($bill2)<6 && strlen($bll)!=17){
if(strlen($bill2)==1){
	$rep = "00000";
	$bll = $bill1."-".$rep."".$bill2;
	}
elseif(strlen($bill2)==2){
	$rep = "0000";
	$bll = $bill1."-".$rep."".$bill2;
	}
elseif(strlen($bill2)==3){
	$rep = "000";
	$bll = $bill1."-".$rep."".$bill2;
	}
elseif(strlen($bill2)==4){
	$rep = "00";
	$bll = $bill1."-".$rep."".$bill2;
	}
elseif(strlen($bill2)==5){
	$rep = "0";
	$bll = $bill1."-".$rep."".$bill2;
	}	
}
                $payr = strtoupper($payor); 
$query="insert into `arrastre` 
	values ('0', '$orno', '$bll','$payr', '$arrastre', '$wharfage', '$total', '$date', '$tcl', '$preparedby', 

'$notedby', '$addedby', '$office')";
                $result=mysql_query($query);
	?>
<?php	
}}}	
?> 

 

thank you very much

Link to comment
Share on other sites

now, i'm not sure if i'm supposed to concat with the name

or should it be with the id?

I don't know what you mean by "name" here, but if you're asking how you should name the fields, I'd probably use either the row number or  the ID number.

HOW DO i CALL THE NAME FROM ANOTHER PAGE?

If you're asking how to get the value of one of these fields from within the next page then the code you posted ($orno= $_POST['orno'.$y];) won't do it because $y won't have any value.  Are you going to run through the loop again in the second page?

Link to comment
Share on other sites

if the form is to update a single row in a database, you can have a hidden field of which you can set the value to the row's ID number using PHP.

i.e.

<form>
<input type='text' name='test' />
<input type='hidden' value='<?php echo $theIDnumber; ?>' name='id' />
</form>

 

or if you're updating several rows you can receive an array of $_POST values for several inputs rather than name='input1' name='input2' etc etc

i.e.

<?php
//php to receive input
if (isset($_POST['test']) && is_array($_POST['test']) {
foreach ($_POST['test'] AS $key => $value) 
{
echo "textbox $key - $value";
}
}


?>

<input type='text' name='test[]' />
<input type='text' name='test[]' />
<input type='text' name='test[]' />
<input type='text' name='test[]' />

 

 

found a quick tute at http://jetlogs.org/2007/07/19/passing-input-arrays-in-php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.