black_box Posted November 19, 2007 Share Posted November 19, 2007 The file name is visit.php I have a search option and 1) user will give a value 2) the page will search and give the output. Now i want to pass the values to another <?PHP ?> code which is inside the the same file in visit.php ok here is the example code like this way: <?PHP echo $pro_id; ?> //some HTML codes <?PHP $por_name_id = $pro_id; //this is the same pro_id i got from above PHP code ?> Now how to do this?? any idea ..sorry i m new in this PHP Quote Link to comment Share on other sites More sharing options...
lewis987 Posted November 19, 2007 Share Posted November 19, 2007 welcome to the weird and wonderful world of php haha you wont need to do anything, that code will work aslong as you have set all the variables ($lala and $lalala u get the point). it will work... Quote Link to comment Share on other sites More sharing options...
black_box Posted November 19, 2007 Author Share Posted November 19, 2007 But the problem is i have two textfield One use for search another use for get input from user So first user will use first textfield to search and it will show the information The next textfield will let user insert a value and it will take those values from previous output and do calculation with new value and then store in database. <?PHP if (isset($_POST['search'])) //after give input and click submit { $pro_id = $_POST['ID']; } ?> //Some html code <?PHP if(isset($_POST ['AddN'])) //after give input and click submit2 { $New_id=$pro_id+3; //How to get the value of $pro_id from the above php code } ?> Any idea? Quote Link to comment Share on other sites More sharing options...
snk Posted November 19, 2007 Share Posted November 19, 2007 pro_id is set ONLY IF the text field area is filled. if you want to have it anytime then you have to take it before if (isset($_POST['search'])) //after give input and click submit. Quote Link to comment Share on other sites More sharing options...
snk Posted November 19, 2007 Share Posted November 19, 2007 Just to add.. that your code works ONLY if both of text fields are filled in, because only then meet the requirements of your IF statements. Quote Link to comment Share on other sites More sharing options...
black_box Posted November 19, 2007 Author Share Posted November 19, 2007 Yah i know this two things thts why i asked sorry The user will search then it shows the output and then the user give something on the another textfield and it will take wht it get from previous output and do calculation and show new output. So actually needs to send the values from previous output I think i need to use Hidden field wht u people say ?? Quote Link to comment Share on other sites More sharing options...
snk Posted November 19, 2007 Share Posted November 19, 2007 yes you need a hidden value. put it in your form and send it each time Quote Link to comment Share on other sites More sharing options...
black_box Posted November 19, 2007 Author Share Posted November 19, 2007 can you please show me hot to do it How to set the hidden field and how to retrieve ...i m really dumb in this cuz new..soory and thanx for ur reply Quote Link to comment Share on other sites More sharing options...
snk Posted November 19, 2007 Share Posted November 19, 2007 you retrieve it normally as _POST['name'] I have created from dreamweaver, so hold on (i see ur online) to check the code Quote Link to comment Share on other sites More sharing options...
snk Posted November 19, 2007 Share Posted November 19, 2007 you accept it as that $temp= $_POST['hidden1']; some code that you say that $temp = $temp+3 with in <form> tags you add this line <input name="hidden1" type="hidden" id="hidden1" value="<?php echo $number" /> Quote Link to comment Share on other sites More sharing options...
black_box Posted November 19, 2007 Author Share Posted November 19, 2007 Now i m totally lost Here is the code <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="bar" type="text" id="bar"> <td width="66" valign="bottom"> <input name="re" type="submit" id="re" value="Submit"> </form> </table> <table width="295" border="0"> <tr> <td align="right"><?php include "connect_db.php"; global $pro_id; $pro_id = $_POST['bar']; if(isset($_POST['bar'])) //search option for bar code { global $pro_id; $pro_id = $_POST['bar']; $SQL = "SELECT * FROM pro_info where pro_id = $pro_id"; $res= mysql_query($SQL) or die("could not register"); if(mysql_num_rows($res)==0) echo "<span class='style25'>*** No Data OR Wrong Bar Code Entered ***</span>"; $row = mysql_fetch_array($res); //need these variable below $pro_name=$row['pro_name']; $pro_hand = $row['pro_in_hand' ]; $pro_sprice=$row['pro_s_price']; echo" <table width='634' border='0'> <tr> <td width='114'> </td> <td width='285'><table width='274' border='1'> <tr> <td><span class='style4'>Product Name: </span></td> <td><span class='style4'><input name='pro_name' type='text' value='$pro_name' /></span></td> </tr> <tr> <td><span class='style4'>Quantity In Hand: </span></td> <td><span class='style4'>$pro_hand</span></td> </tr> <tr> <td><span class='style4'>Price Per Pc's (RM): </span></td> <td><span class='style5'>$pro_sprice</span></td> </tr> <input name='pro_H' type='hidden' id='pro_id' value='$pro_name' /> </table> </td> <td width='99'> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td width='118'> </td> </tr> </table> "; } echo"</td> </tr> </table> <table width='632' height='99' border='0'> <tr> <td width='165'> </td> <td width='83'><label><span class='style4'>Order Pc's : </span></label></td> <td width='144'><label> <form name='form1' method='post' action='sales.php'> <input input name='order' type='text' id='order'> </label></td> <td width='222'> </td> </tr> <tr> <td height='21'> </td> <td> </td> <td><label></label></td> <td> </td> </tr> <tr> <td> </td> <td><input type='submit' name='Submit' value='Submit'></td> <td><input type='reset' name='Submit2' value='Reset'></td> </form> <td> </td> </tr> </table>"; echo" "; $tot_price = $pro_order*$pro_price; $pro_id1 =$pro_id; echo $pro_name; $pro_order; $pro_sprice; echo $tot_price; if(isset($_POST['order']))//after the display of the info from the above bar code search the user will give a order number and submit then it will store into the database with all the field from first options to till now { //need all the variable from the first search options here... $SQL = "INSERT into pro_order VALUES ('$pro_id','$pro_name','$pro_order','$pro_sprice','$tot_price')"; mysql_query($SQL) or die("could not register"); echo" <table width='688' border='0'> <tr> <td width='35'> </td> <td width='643'><table width='643' border='1'> <tr> <td width='87' align='center'><span class='style4'>Product ID: </span></td> <td width='283' align='center'>Product Name </td> <td width='85' align='center'>Price /Pc's </td> <td width='66' align='center'>Order Pc's </td> <td width='88' align='center'>Total Price </td> </tr> <tr> [b][color=purple]<td>$pro_id</td> <td>$pro_name</td> <td>$pro_sprice</td> <td>$pro_order</td> <td>$tot_price</td>[/color][/b] </tr> </table></td> </tr> </table> "; } ?> Quote Link to comment Share on other sites More sharing options...
black_box Posted November 19, 2007 Author Share Posted November 19, 2007 WOW i did it with session ..its working fine ..i think i got the solution thanx all of u u guys are gr8 ...thanx again so happy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.