Jump to content

[SOLVED] question regarding passing variables...


jbrill

Recommended Posts

I have a question which is probably pretty easy for you php pros to answer.

 

here is what i need to happen:

 

file1.php

has a form which when submitted passed the  "id" and "table" to file 2.php

It uses a variable form another table to reference this one so when i go to pull the data it makes like easier by pulling all of them where id = whatever.

 

<?php

$host="localhost"; // Host name 
$username="**********"; // Mysql username 
$password="***********"; // Mysql password 
$db_name="************"; // Database name 
$tbl_name="guestbook"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE quote_id='".$idr."'ORDER by id";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"  >
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF" class="MainBody1">
<tr>
<td width="75" align="center" class="underline">Actual Time</td>
<td width="180" align="center" class="underline">Category</td>
<td width="180" align="center" class="underline">subcategory</td>
<td width="75" align="center" class="underline">machine time</td>
<td width="75" align="center" class="underline">Setup time</td>
<td width="400" align="center" class="underline">Proceedure</td>
<td width="75" align="center" class="underline">Completed</td>
<td width="75" align="center" class="underline">Action</td>
</tr>


<tr>
<td width="75" align="center" valign="top"><? echo $rows['actual_time']; ?></td>
<td width="180" align="center" valign="top">category</td>
<td width="180" align="center" valign="top">subcat</td>
<td width="75" align="center" valign="top" ><? echo $rows['machine_time']; ?></td>
<td width="75" align="center" valign="top" ><? echo $rows['setup']; ?></td>
<td width="400" align="left" valign="top" ><? echo $rows['notes']; ?></td>
<td width="75" align="center" valign="top"><? echo $rows['complete']; ?></td>
<td width="75" align="center" valign="top">


<?php

 

The above code is sent into the data base at file2.php where it inserts into database....

file.php then redirects to wherever i want it... the problem is that i cannot get ti to redirect back to file1.php because once the id is and table are processed in file2.php they are not in the url, so i cannot  $_get the id and table to revert back to.

 

how do i go about doing this?

 

In Short:

File1.php has a form which is processed and entered intot he database in File2.php. once processed i want file2.php to meta refresh to file1.php however it cannot because the id and table that it uses to refrence to for the refresh are lsot. how can i pass that information through even after it is processed?

Link to comment
Share on other sites

use sessions like this

 

<?php

session_start();

if(empty($_SESSION[id])) {
$_SESSION['id'] = "$my_data_id";   //sql id row here
}

if(!empty($_SESSION[id])) {
$my_id = "$_SESSION[id]};
}


?>

 

Then whenever you needed to pass the variable around just reference it as "$my_id"

 

You could also add other items there also, whatever you want to pass from page to page.

 

Then when you need to reset the id for another page just use unset($_SESSION[id]); and do that with all the variables and then you would be able to rebuild the $_SESSION array like you did in the beginning

Link to comment
Share on other sites

Yes already having a session is fine, just adding items to the _SESSIONS array is not too difficult.

 

It is just like passing any variable via POST/GET, except you have to define the value of the variable inside the _SESSION array.

 

<?php

 

session_start();

 

if(empty($_SESSION[id])) {

$_SESSION['id'] = "$my_data_id";  //sql id row here

}

//^ that piece of code checks to see if you have a session variable titled $_SESSION[id]

 

 

if(!empty($_SESSION[id])) {

$my_id = "$_SESSION[id]};

}

//^that piece checks to see if you have a session[id] and if so it creates an easier to use variable $my_id

//which you would pass from page 2 back to page 1 and so on.

//Since you do have a session created though, it will just add those _SESSION variables to the sessions array

 

 

?>

Link to comment
Share on other sites

If you are having a hard time passing things via session, just use $_GET like this:

 

<?php
$my_id = $_GET["my_id"];
//Put that line at the top of page1 and page2

//page one would simply pass the variable as part of the url to page 2 like this
//<form action='page2.php?my_id='.$my_id.' method='POST' />

//Then on page 2, you would set up your query like this

$host="localhost"; // Host name 
$username="**********"; // Mysql username 
$password="***********"; // Mysql password 
$db_name="************"; // Database name 
$tbl_name="guestbook"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");

//Here is the important part, you want to sanitize the query input before you submit it to SQL

$idr = mysql_real_escape_string($my_id);

//Then just back to your query like you had it here

$sql="SELECT * FROM $tbl_name WHERE quote_id='".$idr."'ORDER by id";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){

//Query results here

}



//Then way down at the bottom of the page on page 2, you would just make a link back to 
//page 1 that passes the id back like this

echo "Now back to <a href='page1.php?my_id='.$my_id.'>'page 1</a>";
?>

 

That should make it easier for you

Link to comment
Share on other sites

ok, still need help!

 

i need u guys to put it together for me PLEASE!!!!!

 

<?
include 'admin_header.php';

// this page is for loading info on to the user information. Has 2 sections - top executes only if there are values put through
// the bottom shows the form if there are no values submitted yet


// this part validates whether the user is logged in as a administrator or not
if($_SESSION['type'] == "admin")
{






// execute the real stuff if the login is valid

$prodquery="SELECT * FROM jobs WHERE id='".$idr."'";
$prodinfo = mysql_query($prodquery);
$prod = mysql_fetch_array($prodinfo);
$curcat = $prod['cat'];
$cursubcat = $prod['subcat'];


include 'admin_jobmenu.php';
if($_POST)
	 {

	// codes to execute if something has been submitted already - this part loads it up and then takes you back to the whole list.






	// validations for valid entries

		if(isset($_POST['publish']))
		{$publish=1;}
		else{$publish=0;}




		$insert = "UPDATE jobs SET 
		customer='".$customer."',
		job_number='".$job_number."',
		po_number='".$po_number."',
		date_quoted='".$date_quoted."',
		order_date='".$order_date."',
		delivery_date='".$delivery_date."',
		quoted_price='".$quoted_price."',
		actual_price='".$actual_price."',
		status='".$status."',
		quote_notes='".$quote_notes."'
		WHERE id='".$prod['id']."'";




		if($_POST['delete']=="1")
		{
		// deleting user if the delete key is set
		$insert = "DELETE FROM jobs WHERE id='".$idr."'";
		}

		mysql_query($insert);
		loadimage("whmis","whmis",$idr);
		$success = mysql_affected_rows();




		if($success == 1)
		{echo "SAVED.";

		if($_POST['hopcat']!="")
		{$hopcat = "cat=".$_POST['hopcat'];}

		if($_POST['hopsubcat']!="")
		{$hopsubcat = "&subcat=".$_POST['hopsubcat'];}



		echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=admin_modjob.php?idr=".$prod['id']."&table=jobs\">";
		}
		else{'Did not Load : No changes made.'.mysql_error();
		echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=admin_modjob.php?idr=".$prod['id']."&table=jobs\">";}


		}





else{
// codes to run for the form itself

if(isset($idr))
{

?>

<form method="post" enctype="multipart/form-data" action="<?echo $PHP_SELF."?idr=".$idr;?>" name="jobs">
<table border="0" width="90%" cellspacing="0" cellpadding="0"  height="40">
<tr>
<td>

<?php
$idr = $_GET['idr'];
$table = $_GET['table'];

echo '<a target=\"_blank\" href="printquote.php?idr=' . $idr . '&table=' . $table . '"><img src="images/printquote.gif" border="0"></a>';

?>
</td>
<td valign="bottom">


<div id="glowingtabs">
<ul>


<?php

echo "<li>";
echo '<a href="admin_modprocess.php?idr=' . $idr . '&table=' . $table . '" onclick="return navConfirm(this.href);"><span>Job Process</span></a>';
echo "</li>";

echo "<li id=\"current\">";
echo '<a href="admin_modjob.php?idr=' . $idr . '&table=' . $table . '" onclick="return navConfirm(this.href);"><span>Quote/Job Info</span></a>';
echo "</li>";


?>


</ul>
</div>

<br style="clear: left;" />


</td></tr>
<tr>
<td colspan="2">

<form method="post" enctype="multipart/form-data" action="<?echo $PHP_SELF?>" name="jobs">
<input type="Hidden" name="submit" value="1">

<table align=center border=0 width="100%" cellpadding="10" class="MainBody1" bgcolor="white">

<tr>
<td align=center colspan=2>

<font class=section>
Modify Job
</font>

</td>
</tr>


<tr>
<td width="35%">Client: <select name="customer" >
<option selected value=''>Select Client</option>
<?

$catsql = "SELECT DISTINCT name FROM dealers";
$cats = mysql_query($catsql);
$category = mysql_fetch_array($cats);



do

{
if($category['name']==$prod['customer'])

{
echo "<option selected value='".$category['name']."'>".$category['name']."</option>";

}
else
{
echo "<option value='".$category['name']."'>".$category['name']."</option>";

}

} while ($category = mysql_fetch_array($cats));



?>
<img src="images/email.gif"></td>
<td width="65%" align="right" valign="top">
Quote #: <? echo $prod['id']?>  
Job #: <input type="text" name="job_number" class="inputbox" size="12" value="<? echo $prod['job_number']?>">  
PO #: <input type="text" name="po_number" class="inputbox" size="12" value="<? echo $prod['po_number']?>">  
  Status: 
	<select name="status">
<option selected value=''>Select Status</option>
<?

$statussql = "SELECT DISTINCT status FROM status";
$sts = mysql_query($statussql);
$status = mysql_fetch_array($sts);



do

{
if($status['status']==$prod['status'])

{
echo "<option selected value='".$status['status']."'>".$status['status']."</option>";

}
else
{
echo "<option value='".$status['status']."'>".$status['status']."</option>";

}

} while ($status = mysql_fetch_array($sts));



?>
</td>
</tr>
<tr>
<td valign="top">
Date Quoted:  <input type="text" name="date_quoted" value="<? echo $prod['date_quoted']?>" size=20>  <a href="javascript:showCal('date_quoted')"><img src="images/calender.gif" border="0"></a><br><br>

Date Ordered: <input type="text" name="order_date" value="<? echo $prod['order_date']?>" size=20>  <a href="javascript:showCal('order_date')"><img src="images/calender.gif" border="0"></a><br><br>

Delivery Date: <input type="text" name="delivery_date" value="<? echo $prod['delivery_date']?>" size=20>  <a href="javascript:showCal('delivery_date')"><img src="images/calender.gif" border="0"></a><br><br><br>

Quoted Price: <input type="text" name="quoted_price" value="<? echo $prod['quoted_price']?>" size=20><br><br>

Actual Price:  <input type="text" name="actual_price" value="<? echo $prod['actual_price']?>" size=20>
</td>
<td align="center" valign="middle">Quote Notes:<br><textarea name=quote_notes rows="20" cols="90"><? echo $prod['quote_notes']?></textarea></td>
</tr>

<tr><td colspan="2">

<div style="width:100%; overflow: auto;">

</div>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit value="Modify This Job"></form>

</td>
</tr>
</table>

<br><br>

<?
}

else {
echo "You do not have authority to modify this page, either because this is not your account, or you are not an administrator.";

}



}



}

else {
echo "You do not have authority to modify this page, either because this is not your account, or you are not an administrator.";

}
?>
		<br>
	</td>
</tr>
</table>
<br>
<?
require 'admin_footer.php';
?>

 

 

That code above ( its actually one of the 'included' files that has the form that is to be processed i the next file listed below, on the page above, the url i see is:

http://www.myurl.com/admin/admin_modprocess.php?idr=1&table=jobs

 

the form is processed with this file (this is where i want to $_GET the id from above and forward to to the page is have shown with a note in the code below)

 

<? include 'admin_header.php'; 

?>


<?php


$host="localhost"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="***"; // Database name 
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");


$sql="INSERT INTO guestbook (quote_id,actual_time,cat,subcat,machine_time,setup,notes,complete)
VALUES ('".$quote_id."','".$actual_time."','".$cat."','".$subcat."','".$machine_time."','".$setup."','".$notes."','".$complete."')";
$result=mysql_query($sql);





//check if query successful 
if($result){
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=admin_modprocess.php?id='.$id.'&table=jobs\">"; //this is the link that shoudl use the id and redirect

}

else {
echo "ERROR";
}
mysql_close();

include 'admin_footer.php';
?>

 

 

Link to comment
Share on other sites

can some one please help me  >:(

 

im falling...in love with youuuu....good song =P

 

Sorry for the tease, I saw that and I just had to reply to it =)

 

 

Felt bad i didn't even give it a shot, try this out:

 

change this:
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=admin_modprocess.php?id='.$id.'&table=jobs\">"; //this is the link that shoudl use the id and redirect

to this:
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=admin_modprocess.php?id=" . $id . "&table=jobs\">"; //this is the link that shoudl use the id and redirect

 

See if that tickles your fancy.

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.