Page 1 of 1

Prog Advice -> Multiple submits in form

Posted: Wed Apr 13, 2005 2:05 am
by facets
Hi All,

I'd like some advice or some direction if you can help..
I'm new to PHP and posting to forums so please excuse :)

I'm using a form with Select menus to add a new product to the DB.
Whilst doing this I also need to be able to view a selected detail from one of the menus.
The image attached should give a better view.

Image

If you need any further info, please advise.

Cheers, Will.

Posted: Wed Apr 13, 2005 4:51 am
by Chris Corbyn
You is your problem knowing which button was clicked?

Code: Select all

<form action=&quote;file.php&quote; method=&quote;post&quote;>
<input type=&quote;submit&quote; name=&quote;submit_one&quote; value=&quote;1st Submit&quote;>
<br />
<input type=&quote;submit&quote; name=&quote;submit_two&quote; value=&quote;2nd Submit&quote;>
</form>
You can check this on the server

Code: Select all

if ($_POSTї'submit_one']) {
    //Do whatever for first submit
} elseif ($_POSTї'submit_two']) {
    //Do whatever for second submit
}
and so on....

Hope that helps :D

Posted: Wed Apr 13, 2005 7:39 am
by facets
Hi, Thanks for the quick reply.
We're gettign somewhere now :)
Next I need to discover how to figure how to open a popup with the 'viewDetails' page.
Which could be just an echo of 'print_r($_POST);' for now. I guess I need to pass 'stockId' to that page?

Any ideas? (TIA) Will.

Code: Select all

<?php

include &quote;includes/functions.inc&quote;;
include &quote;includes/common_db.inc&quote;;

$link_id = db_connect($db);

    
if ($_POST&#1111;'submit']) {  
    
//if (isset($_POST&#1111;'action']) && $_POST&#1111;'action'] == 'submitted') {
  
   echo '<pre>';
   print_r($_POST);
   echo &quote;<h1>Submitted to DB</h1><br>&quote;; 
   echo '<a href=&quote;'. $_SERVER&#1111;'PHP_SELF'] .'&quote;>Please try again</a>';
   echo &quote;</pre>&quote;;
} elseif ($_POST&#1111;'viewDetails']) {
 
//Do whatever for second submit
 echo &quote;StockID No# :&quote;;
 echo $stockId;
 echo $description;
 echo &quote;<a href=\&quote;javascript:open_window('$PHP_SELF?action=view_record&userid=$userid');\&quote;>View</a>&quote;;
 }
?>

<form action=&quote;<?php echo $_SERVER&#1111;'PHP_SELF']; ?>&quote; method=&quote;post&quote;>

<? $sql_query = mysql_query(&quote;SELECT description, stockId FROM austock&quote;);
	echo &quote;<select name=\&quote;stockId\&quote;>&quote;;
    	while(list($stockname, $stockId)=mysql_fetch_array($sql_query)) {
		$stockname = stripslashes($stockname);
		echo &quote;<option value=\&quote;$stockId\&quote;>$stockname</option>&quote;;
	}
	echo &quote;</select>&quote;;
	mysql_free_result($sql_query);
?>
    
<!--<input type=&quote;hidden&quote; name=&quote;action&quote; value=&quote;submitted&quote;>-->
<br><br><input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;submit me!&quote;>
<br><br><input type=&quote;submit&quote; name=&quote;viewDetails&quote; value=&quote;View Details&quote;>
</form>

Posted: Wed Apr 13, 2005 7:55 am
by Chris Corbyn
Use session variables to pass the data you need to the popup page.

I guess you could even do it using javascript....

Posted: Wed Apr 13, 2005 8:01 am
by facets
Any chance you could elaborate alittle?
In the meantime i'll google :)

thanks again for the help. Will

Posted: Wed Apr 13, 2005 8:05 am
by Chris Corbyn
facets wrote:Any chance you could elaborate alittle?
In the meantime i'll google :)

thanks again for the help. Will
Assuming you are asking what I think you are.

"How do I get the data into the popup window?"

You will need to use a session variable... these will be accessible across all pages.

You simply:

Code: Select all

session_start();
$_SESSION['variable_name'] = $variable;

echo '<a href="somepage.php?'.SID.'">Link to another page that can access my session varibale</a>';
Then on the other page:

Code: Select all

session_start();
echo $_SESSION['variable_name'];
Perhaps I've misunderstood you?

Posted: Wed Apr 13, 2005 8:21 am
by facets
Hi, Thanks for the reply..

Any idea on how to get the popup to happen..
My code doesn't error, but doesn't execute the popup either..

Code: Select all

<?php

include &quote;includes/functions.inc&quote;;
include &quote;includes/common_db.inc&quote;;

$link_id = db_connect($db);

session_start();
$_SESSION&#1111;'stockId'] = $stockId;
global $PHP_SELF;
    
if ($_POST&#1111;'submit']) {  
    
   echo '<pre>';
   print_r($_POST);
   echo &quote;<h1>Submitted to DB</h1><br>&quote;; 
   echo '<a href=&quote;'. $_SERVER&#1111;'PHP_SELF'] .'&quote;>Please try again</a>';
   echo &quote;</pre>&quote;;

} elseif ($_POST&#1111;'viewDetails']) {
 
//Do whatever for second submit
 
 echo $stockId;
 echo $description;
 view();
 
 }
?>

<form action=&quote;<?php echo $_SERVER&#1111;'PHP_SELF']; ?>&quote; method=&quote;post&quote;>

<? $sql_query = mysql_query(&quote;SELECT description, stockId FROM austock&quote;);
	echo &quote;<select name=\&quote;stockId\&quote;>&quote;;
    	while(list($stockname, $stockId)=mysql_fetch_array($sql_query)) {
		$stockname = stripslashes($stockname);
		echo &quote;<option value=\&quote;$stockId\&quote;>$stockname</option>&quote;;
	}
	echo &quote;</select>&quote;;
	mysql_free_result($sql_query);
?>
    
<br><br><input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;submit me!&quote;>
<br><br><input type=&quote;submit&quote; name=&quote;viewDetails&quote; value=&quote;View Details&quote;>
</form>

<?

function view() {
    echo&quote;javascript:open_window('$PHP_SELF?action=view_record&stockId=$stockId')&quote;;
    }

function view_record() {
 
    session_start();
    global $PHP_SELF;
    print &quote;hello world <br>&quote;;
    echo $stockId ;
    print &quote;<br>&quote;;
    echo $_SESSION&#1111;'variable_name'];
    
    }
?>
TIA, Will.

Posted: Wed Apr 13, 2005 9:20 am
by Chris Corbyn
This wont work...

Code: Select all

function view() {
    echo"javascript:open_window('$PHP_SELF?action=view_record&stockId=$stockId')";
    }
this will (You have to turn off a popup blocker though).

Code: Select all

function view() {
    echo "<script language=\"javascript\">
    var newWindow = window.open('".$_SERVER['PHP_SELF']."action=view_record&stockId=".$stockId."');
    </script>";
    }
d11wtq | Please use

Code: Select all

tags to post PHP code instead of

Code: Select all

tags.[/b][/color][/size]

Posted: Wed Apr 13, 2005 9:30 am
by facets
excellent. thank you so much.
got the pop up working.

the only trouble is it not passing the stockId through.

Siting : The requested URL /materials_register/testSubmit.phpaction=view_record&stockId=
was not found on this server.

So obviously my Session Variables are not set correctly. Any ideas? Keeping in mind they are being retrived from a mySql db.

tia, Will.