saving parameters

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

Post Reply
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

saving parameters

Post by marnieg »

I have one page that passes a parameter to another page. For example

http://mydomain.com/view_jobs_custwiths ... ?cust_id=1

Once I get to the new page I have two forms. One displays the data from my database based on the parameter I sent it. The other is a form that I want the user to reset within the existing selected data. Here is my code. The problem is once I display the screen and then enter search criteria it loses the cust_id value and my query fails and returns no data. I have tried using "$_GET" on the cust_id, saving it to a session variable, but I must be missing something.

Code: Select all

<form name="search" method="post" action="<?=$PHP_SELF?>">
 <b>Seach for:</b> <input type="text" name="find" value='<?php echo $find; ?>'/> <b>in</b>
<Select NAME="field">
 <Option VALUE="job_nm" <?php if($_POST['field'] == "job_nm"): ?>selected='selected'<?php endif;?>>Job Name</option>
 <Option VALUE="job_num" <?php if($_POST['field'] == "job_num"): ?>selected='selected'<?php endif;?>>Job Number</option>
 <Option VALUE="insp_nm" <?php if($_POST['field'] == "insp_nm"): ?>selected='selected'<?php endif;?>>Inspector</option>
 <Option VALUE="wo_num" <?php if($_POST['field'] == "wo_num"): ?>selected='selected'<?php endif;?>>Work Order</option>
 <Option VALUE="wo_status" <?php if($_POST['field'] == "wo_status"): ?>selected='selected'<?php endif;?>>WO Status</option>
 </Select>
 <input type="hidden" name="searching" value="yes" />
 <input type="submit" name="search" value="Search" />
 </form>
 <p>Work status is Active, Scheduled, Complete, or Cancelled</p>
 <p></p>	
 <?php
include ("dbconnect.inc.php");
$cquery = mysql_query("select * from customer where cust_id = $cust_id");
$crow = mysql_fetch_object($cquery);
$cnm = $crow->cust_nm;
echo "<h2>Jobs/Work Orders for Customer: <strong>$cust_id - $cnm</strong> </h2>";
					if ($searching =="yes" and !$find == "") {
//Now we search for our search term, in the field the user specified
$query = mysql_query("Select * from work_orders, jobs, inspector where wo_cust_id = [b]$cust_id[/b]   and wo_insp_id = insp_id and wo_job_id = job_id and upper($field) LIKE '%$find%' order by wo_num");
}
else
{
$query = mysql_query("Select * from work_orders, jobs, inspector where wo_cust_id = [b]$cust_id[/b]  and wo_insp_id = insp_id and wo_job_id = job_id order by wo_num");
}
?>
		<form name="jobsforcust" method = "post" action="post">
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: saving parameters

Post by Celauran »

Query fails as in returns false, or fails as in produces an error?

Also, what's up with having <span> in your queries?

Code: Select all

$query = mysql_query("Select * from work_orders, jobs, inspector where wo_cust_id = <span style="font-weight: bold">$cust_id</span>   and wo_insp_id = insp_id and wo_job_id = job_id and upper($field) LIKE '%$find%' order by wo_num");

Code: Select all

SELECT * FROM work_orders, jobs, inspector WHERE wo_cust_id = <span style=
is not a valid query.
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Re: saving parameters

Post by marnieg »

Sorry I was just tyring to bold the cust_id in my query to show where the variable in question. Here is the code without it.

Code: Select all

<form name="search" method="post" action="<?=$PHP_SELF?>">
 <b>Seach for:</b> <input type="text" name="find" value='<?php echo $find; ?>'/> <b>in</b>
<Select NAME="field">
 <Option VALUE="job_nm" <?php if($_POST['field'] == "job_nm"): ?>selected='selected'<?php endif;?>>Job Name</option>
 <Option VALUE="job_num" <?php if($_POST['field'] == "job_num"): ?>selected='selected'<?php endif;?>>Job Number</option>
 <Option VALUE="insp_nm" <?php if($_POST['field'] == "insp_nm"): ?>selected='selected'<?php endif;?>>Inspector</option>
 <Option VALUE="wo_num" <?php if($_POST['field'] == "wo_num"): ?>selected='selected'<?php endif;?>>Work Order</option>
 <Option VALUE="wo_status" <?php if($_POST['field'] == "wo_status"): ?>selected='selected'<?php endif;?>>WO Status</option>
 </Select>
 <input type="hidden" name="searching" value="yes" />
 <input type="submit" name="search" value="Search" />
 </form>
 <p>Work status is Active, Scheduled, Complete, or Cancelled</p>
 <p></p>	
 <?php
include ("dbconnect.inc.php");
$cquery = mysql_query("select * from customer where cust_id = $cust_id");
$crow = mysql_fetch_object($cquery);
$cnm = $crow->cust_nm;
echo "<h2>Jobs/Work Orders for Customer: <strong>$cust_id - $cnm</strong> </h2>";
					if ($searching =="yes" and !$find == "") {
//Now we search for our search term, in the field the user specified
$query = mysql_query("Select * from work_orders, jobs, inspector where wo_cust_id = $cust_id   and wo_insp_id = insp_id and wo_job_id = job_id and upper($field) LIKE '%$find%' order by wo_num");
}
else
{
$query = mysql_query("Select * from work_orders, jobs, inspector where wo_cust_id = $cust_id  and wo_insp_id = insp_id and wo_job_id = job_id order by wo_num");
}
?>
		<form name="jobsforcust" method = "post" action="post">
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: saving parameters

Post by Celauran »

Where is $cust_id being defined? Is it received a $_POST value when the page is first loaded and then being lost when the user submits the form you showed?
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Re: saving parameters

Post by marnieg »

It is being passed as a parameter from the previous page. Once I get to this page I want to keep it and continue passing it to my query.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: saving parameters

Post by Celauran »

You could include it as a hidden input in your form. Writing it to a cookie or session would probably be a better option, though. You mentioned you tried writing it as session data and it wasn't working. Can you post the code you had used? What was happening?
marnieg
Forum Commoner
Posts: 65
Joined: Wed Mar 12, 2003 4:35 pm

Re: saving parameters

Post by marnieg »

I was able to resolve this using session_register variable for cust_id and then using the session variable in my query statement. I also had to use the unset of the variable on the page I came from so that a new variable could get loaded if the cust_id changed.

Thank you for your suggestions. They pointed me in the right direction.

This forum is AWESOME! :D
Post Reply