PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Apr 13, 2005 2:05 am
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.
If you need any further info, please advise.
Cheers, Will.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Wed Apr 13, 2005 4:51 am
You is your problem knowing which button was clicked?
Code: Select all
<form action="e;file.php"e; method="e;post"e;>
<input type="e;submit"e; name="e;submit_one"e; value="e;1st Submit"e;>
<br />
<input type="e;submit"e; name="e;submit_two"e; value="e;2nd Submit"e;>
</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
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Apr 13, 2005 7:39 am
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 "e;includes/functions.inc"e;;
include "e;includes/common_db.inc"e;;
$link_id = db_connect($db);
if ($_POSTї'submit']) {
//if (isset($_POSTї'action']) && $_POSTї'action'] == 'submitted') {
echo '<pre>';
print_r($_POST);
echo "e;<h1>Submitted to DB</h1><br>"e;;
echo '<a href="e;'. $_SERVERї'PHP_SELF'] .'"e;>Please try again</a>';
echo "e;</pre>"e;;
} elseif ($_POSTї'viewDetails']) {
//Do whatever for second submit
echo "e;StockID No# :"e;;
echo $stockId;
echo $description;
echo "e;<a href=\"e;javascript:open_window('$PHP_SELF?action=view_record&userid=$userid');\"e;>View</a>"e;;
}
?>
<form action="e;<?php echo $_SERVERї'PHP_SELF']; ?>"e; method="e;post"e;>
<? $sql_query = mysql_query("e;SELECT description, stockId FROM austock"e;);
echo "e;<select name=\"e;stockId\"e;>"e;;
while(list($stockname, $stockId)=mysql_fetch_array($sql_query)) {
$stockname = stripslashes($stockname);
echo "e;<option value=\"e;$stockId\"e;>$stockname</option>"e;;
}
echo "e;</select>"e;;
mysql_free_result($sql_query);
?>
<!--<input type="e;hidden"e; name="e;action"e; value="e;submitted"e;>-->
<br><br><input type="e;submit"e; name="e;submit"e; value="e;submit me!"e;>
<br><br><input type="e;submit"e; name="e;viewDetails"e; value="e;View Details"e;>
</form>
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Wed Apr 13, 2005 7:55 am
Use
session variables to pass the data you need to the popup page.
I guess you could even do it using javascript....
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Apr 13, 2005 8:01 am
Any chance you could elaborate alittle?
In the meantime i'll google
thanks again for the help. Will
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Wed Apr 13, 2005 8:05 am
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?
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Apr 13, 2005 8:21 am
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 "e;includes/functions.inc"e;;
include "e;includes/common_db.inc"e;;
$link_id = db_connect($db);
session_start();
$_SESSIONї'stockId'] = $stockId;
global $PHP_SELF;
if ($_POSTї'submit']) {
echo '<pre>';
print_r($_POST);
echo "e;<h1>Submitted to DB</h1><br>"e;;
echo '<a href="e;'. $_SERVERї'PHP_SELF'] .'"e;>Please try again</a>';
echo "e;</pre>"e;;
} elseif ($_POSTї'viewDetails']) {
//Do whatever for second submit
echo $stockId;
echo $description;
view();
}
?>
<form action="e;<?php echo $_SERVERї'PHP_SELF']; ?>"e; method="e;post"e;>
<? $sql_query = mysql_query("e;SELECT description, stockId FROM austock"e;);
echo "e;<select name=\"e;stockId\"e;>"e;;
while(list($stockname, $stockId)=mysql_fetch_array($sql_query)) {
$stockname = stripslashes($stockname);
echo "e;<option value=\"e;$stockId\"e;>$stockname</option>"e;;
}
echo "e;</select>"e;;
mysql_free_result($sql_query);
?>
<br><br><input type="e;submit"e; name="e;submit"e; value="e;submit me!"e;>
<br><br><input type="e;submit"e; name="e;viewDetails"e; value="e;View Details"e;>
</form>
<?
function view() {
echo"e;javascript:open_window('$PHP_SELF?action=view_record&stockId=$stockId')"e;;
}
function view_record() {
session_start();
global $PHP_SELF;
print "e;hello world <br>"e;;
echo $stockId ;
print "e;<br>"e;;
echo $_SESSIONї'variable_name'];
}
?>
TIA, Will.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Wed Apr 13, 2005 9:20 am
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
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Wed Apr 13, 2005 9:30 am
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.