Page 1 of 1
[SOLVED] How to use isset in the same file
Posted: Wed Sep 21, 2005 8:47 am
by dude81
Hello forum,
I have a form which on submission it should go to isset condition and exectue the sql query and thenexecute a jabvascript . If javascript returns false then I need to display the same page else it should go to the other page.
How to do this?
can anyone post a sample code
Posted: Wed Sep 21, 2005 8:52 am
by Jenk
By the sounds of it, the JavaScript function may be unecessary as you can redirect using PHP
Code: Select all
header('Location: page.php');
exit();
To use the isset() function, the below example is a valid use:
Code: Select all
if (isset($variable)) {
/* do something if it is set */
}
else {
/* do something else if it is not set */
}
Posted: Wed Sep 21, 2005 8:55 am
by hawleyjr
You have three different types of transactions here.
HTML -> to PHP page to execute PHP/SQL
PHP -> HTML/Javascript
Javascript -> New Page
Note: If you can do this without using javascript then use Jenk's desc. above.
Posted: Wed Sep 21, 2005 8:59 am
by feyd
a quick note on header() based redirection.. it's best to use a full URL.
Posted: Wed Sep 21, 2005 10:17 pm
by dude81
Hi,
That means I can use same form variables for two different files?? or can resend to 2 different validations using isset?
Posted: Wed Sep 21, 2005 10:26 pm
by hawleyjr
dude81 wrote:Hi,
That means I can use same form variables for two different files?? or can resend to 2 different validations using isset?
What?
Posted: Wed Sep 21, 2005 10:47 pm
by s.dot
if your variables are being passed to the page which executes the isset(), then they can be passed along to whatever page you decide to send the client to.
Posted: Wed Sep 21, 2005 10:48 pm
by dude81
See
I have a form which user fills up the data .
Once he clicks on the submit, I need three variable from the form to check the stock..For checking the stock I need to execute the two SQL queries in isset conditon . Once queries are succesful then only I need to send him to the next page
else I need to popup saying stock doesnt exist..
Posted: Wed Sep 21, 2005 11:23 pm
by dude81
But I get undefined index notices , that means variables are not being set in the same page?
Code: Select all
<form name="kitsaleorder1" method="post" action="salekit.php">
<input type="hidden" name="sess_id" value="<? echo $sess_id; ?>">
<input type="hidden" name="ecash" value="<? echo $ecash; ?>">
<input type="hidden" name="ecredit" value="<? echo $ecredit; ?>">
<input type="hidden" name="delivery" value="<? echo $delivery; ?>">
<input type="hidden" name="shipping_company" value="<? echo $shipping_company; ?>">
<input type="hidden" name="shipping_state" value="<? echo $shipping_state; ?>">
<input type="hidden" name="shipping_pin" value="<? echo $shipping_pin; ?>">
<input type="hidden" name="currency" value="<? echo $currency; ?>">
<input type="hidden" name="Type_of_sale" value="<? echo $Type_of_sale; ?>">
<input type="hidden" name="Price_Method" value="<? echo $Price_Method; ?>">
<input type="hidden" name="Store_Id" value="<? echo $Store_Id; ?>">
<table width="100%" border="0" cellspacing="1" cellpadding="4">
<tr align="center" valign="middle" bgcolor="#99CCFF" nowrap>
<td width="6%" bgcolor="#99CCFF"><strong>Sl.No</strong></td>
<td width="13%"><strong>Item Code </strong></td>
<td width="41%" bgcolor="#99CCFF"><strong>Product Name</strong></td>
<td width="6%"><strong>Order</strong></td>
<td width="8%"><strong>Quantity</strong></td>
<td width="14%"><strong>Unit Price (<?=$currency?>) </strong></td>
<td width="12%"><strong>Unit IV </strong></td>
<td width="12%"><strong> Details </strong></td>
</tr>
The code above gets is the form, and salekit.php is the name of the same file. I want to pass the action if form data to the othe page that is at header location:check_quantity.php
this first nad second queries gets the data and displays on the browser
Code: Select all
<?
$odbc = dbconn();
$Query = ""SQL QUERY"
$sth = OCIParse($odbc, $Query);
OCIExecute($sth, OCI_DEFAULT);
$nrows = ocifetchstatement($sth, $results_details);
for($i=0; $i<$nrows; $i++)
{
$item_code = $results_details['ITEM_CODE'][$i];
$stock_type = $results_details['STOCK_TYPE'][$i];
$item_name = $results_details['ITEM_NAME'][$i];
$iv_points = $results_details['IV_POINTS'][$i];
$mrp = $results_details['ITEM_PRICE'][$i];
$weight = $results_details['GROSS_WEIGHT'][$i];
$q = "SQL2"
//echo $q;
$sth1 = OCIParse($odbc, $q);
OCIExecute($sth1, OCI_DEFAULT);
$nr = ocifetchstatement($sth1, $rs);
$stock_qty = 0;
for($k=0; $k<$nr; $k++)
{
$stock_qty = $rs['STOCK_QTY'][$k];
}
?>
Code: Select all
<tr align="center" valign="middle" bgcolor="#E6F2FF" id="product_row<?=$i?>"
<td><? echo $i+1; ?></td>
<td><? echo $item_code; ?></td>
<td align="left">
<input name="stock_qty<?=$i?>" type="hidden" id="stock_qty<?=$i?>" value="<? echo $stock_qty;?>">
<input name="item_code<?=$i?>" type="hidden" id="item_code<?=$i?>" value="<? echo $item_code;?>">
<input name="stock_type<?=$i?>" type="hidden" id="stock_type<?=$i?>" value="<? echo $stock_type;?>">
value="<? echo $stock_type;?>">
<input name="weight<?=$i?>" type="hidden" id="weight<?=$i?>" value="<? echo $weight;?>">
<input name="item_name<?=$i?>" type="hidden" id="item_name<?=$i?>" value="<? echo $item_name;?>">
<? echo $item_name;?></td>
<td><input name="order" type="radio" id="order<?=$i?>" value="1" onClick="checkRow(<? echo $i; ?>)">
</td>
<td><input name="quantity<?=$i?>" type="text" id="quantity<?=$i?>" value="" size="2" onKeyPress="return chkNumber(event)"></td>
once quantity isset here I need to check whether stock exists otr not? if exists I need to pass the control to the other file that is check _quantity .php. but whn I do this I get notoces sayin gthat undefined index and displays the same file?
Code: Select all
<?
if (isset($_POST['quantity'.$i]))
{
echo $quantity;
$kit_code= $_POST['item_code'].$i;
$quantity=$_POST['quantity'].$i;
$sql="SELECT ITEM_CODE ITEM_CODE, STOCK_TYPE STOCK_TYPE, ITEMS_PKG.GET_ITEM_NAME ( COMPANY, ITEM_CODE) ITEM_NAME, ITEM_QTY ITEM_QTY, SAMPLE_ITEM SAMPLE_ITEM FROM KIT_ITEMS WHERE COMPANY = '$company' AND KIT_CODE = '$kit_code' AND TRUNC(SYSDATE) BETWEEN EFFECTIVE_FROM AND NVL(EFFECTIVE_TILL,SYSDATE) ORDER BY 1, 2";
$kit_name=get_item_name($company,$kit_code);
$sth=OCIParse($odbc, $sql);
OCIExecute($sth, OCI_DEFAULT);
$num = ocifetchstatement($sth, $rs);
for($i=0; $i<$num; $i++)
{
$each_item_code=$rs['ITEM_CODE'][$i];
$each_item_in_stock=$rs['ITEM_QTY'][$i];
$each_item_name=$rs['ITEM_NAME'][$i];
$each_stock_type=$rs['STOCK_TYPE'][$i];
$sl=$i+1;
if (($each_item_in_stock*$quantity<$each_stock_available))
{
?>
Code: Select all
<script language="javascript" type="text/javascript">
alert("stock not available");
</script>
Code: Select all
<?
}
}
}
else if (isset($_POST['Submit']))
{
header("Location:check_quantity.php");
}
?>
Code: Select all
<td align="right"><? printf("%01.2f", $mrp);?>
<input type="hidden" name="price<?=$i?>" value="<? echo $mrp;?>"></td>
<td align="right">
<input type="hidden" name="unitiv<?=$i?>" value="<? echo $iv_points; ?>"><? echo $iv_points; ?> </td>
Code: Select all
<?$_SESSION['kit_code']=$item_code;?>
Code: Select all
<td align="right">
<?
print("<a href='javascript:popUp(\"kit_details.php?shipping_company=$shipping_company&kit_code=$item_code\")' class='defaultlink'><img src='images/info_more.gif' border=0></a>"); ?>
</td>
</tr>
<?
}
?>
<input type="hidden" name="max_val" value="<? echo $nrows; ?>"><tr align="center" valign="middle" bgcolor="#99CCFF" id="product_row">
<tr align="center" valign="middle" id="product_row">
<td colspan="7">
<input type="hidden" name="index" value="<? echo $nrows;?>" >
<input type="reset" name="Reset" value="Clear Form">
<input type="submit" name="Submit" value="Continue >>" onClick="return checkAdd('0')"></td>
</tr>
</table>
</form>
[SOLVED]How to use isset in the same file
Posted: Thu Sep 22, 2005 5:16 am
by dude81
I some how struggled and solved, thanks for ur help