Jump to content

[SOLVED] PHP passing single value rather than entire section


nd3_2000

Recommended Posts

Hi Guys,

I am working on a job page that uses an sql query to get details of all today's jobs, this then places them all onto a page, then when I click the button under each individual job it passes that value from a (will be but not currently for bugging purposes) hidden text box and passes that value onto a new page to get all details for that particular job.

 

The problem I am having is that when I click on a button, it automatically passes the last job through, no matter which job I click on (and I know the job no is in the text boxes as I can see them laid out correctly, this is driving me nuts,  :facewall:

 

I have tried BOTH The post and get methods and a mixture of the two but it always does the same thing, continually passes through the last job number

 

I will post the code below for the sending page and the receiving page.

 

First page

 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title></title>

</head>

 

<body>

<form action="GetSingleJob.php" name="GetJobDets" method="POST">

 

 

<?php

$database_name="";

$database_password="";

$database_host="";

$Username="";

 

 

$conn = @mysql_connect($database_host, $Username, $database_password, $database_name) or die(mysql_error());

 

echo "<html><head><title>All Jobs</title></head><body>";

echo "<h1>All Jobs</h1>";

 

$sql = "SELECT * FROM Jobs where Print_Complete=0 and JobNo like '%EB%'";

 

$results=mysql_db_query($database_name,$sql,$conn);

while ($output=mysql_fetch_array($results)) {

 

$JobNo =$output[JobNo];

 

echo "<p><b>Job ID:</b> ". $output[JobNo];

echo "<br /><b>Desc:</b> ". $output[Job_Desc];

echo "<br /><b>Print Date:</b> ". $output[Print_Date];

echo "<br /><b>Delivery Date:</b> ". $output[Delivery_Date];

echo "<br />";

echo("<INPUT TYPE=\"text\"  NAME=\"JobNumber\" VALUE= \"$JobNo\" id='JobNumber'>");

echo("<INPUT TYPE=\"submit\"  NAME=\"ViewJob\" VALUE=\"View Job\">");

$JobNo="";

echo "<hr /></p>";}

 

mysql_close($conn);

?>

 

</form>

<INPUT TYPE=BUTTON  NAME='ViewTodaysJobs' VALUE='View Todays Jobs' onClick="window.location='selectatodaysjobs.php'">

<INPUT TYPE=BUTTON  NAME='ViewALLJobs' VALUE='Refresh Jobs' onClick="window.location='selectalljobs.php'">

 

 

 

</body>

</html>

 

 

Receiving page

 

 

<?php

 

 

 

$database_name="";

$database_password="";

$database_host="";

$Username="";

 

 

$conn = @mysql_connect($database_host, $Username, $database_password, $database_name) or die(mysql_error());

 

$JobNo = $_POST['JobNumber'];

//This receives the JobNo data from the hidden field on the previous page

 

$sql = "SELECT * FROM Jobs where JobNo='$JobNo'";

 

 

$results=mysql_db_query($database_name,$sql,$conn);

 

 

echo "<html><head><title>Job No: $JobNo</title></head><body>";

echo "<h1>Job No: $JobNo </h1>";

 

 

while ($output=mysql_fetch_array($results)) {

 

$JobNo =$output[JobNo];

 

echo "<p><b>Job ID:</b> ". $output[JobNo];

echo "<br /><b>Date Added:</b> ". $output[Date_Added];

echo "<br /><b>Company Name:</b> ". $output[Company_Name];

echo "<br /><b>Desc:</b> ". $output[Job_Desc];

echo "<br /><b>Press:</b> ". $output[Press];

echo "<br /><b>Print Date:</b> ". $output[Print_Date];

echo "<br /><b>Delivery Date:</b> ". $output[Delivery_Date];

echo "<br />";

echo("<INPUT TYPE=text  NAME='Job' VALUE= $JobNo>");

echo "<hr /></p>";

 

 

}

 

mysql_close($conn);

?>

 

<INPUT TYPE=BUTTON  NAME='ViewALLJobs' VALUE='View ALL Jobs' onClick="window.location='selectalljobs.php'">

 

<INPUT TYPE=BUTTON  NAME='ViewTodaysJobs' VALUE='Todays jobs' onClick="window.location='selectatodaysjobs.php'">

 

<INPUT TYPE=BUTTON  NAME='Complete' VALUE='Job Complete' onClick="window.location='selectalljobs.php'">

 

</form>

 

 

Many thanks guys a big gold star for anyone who can fix this for me

Link to comment
Share on other sites

I would output the following part like this:

while ($output=mysql_fetch_array($results)) {

echo "<p><b>Job ID:</b> ". $output['JobNo'];
echo "<br /><b>Desc:</b> ". $output['Job_Desc'];
echo "<br /><b>Print Date:</b> ". $output['Print_Date'];
echo "<br /><b>Delivery Date:</b> ". $output['Delivery_Date'];
echo "<br />";
echo("<INPUT TYPE=\"hidden\"   NAME=\"JobNumber\" VALUE= \"$output['JobNo']\" id='JobNumber'>"); 
echo("<INPUT TYPE=\"submit\"  NAME=\"ViewJob\" VALUE=\"View Job\">"); 
echo "<hr /></p>";}

Link to comment
Share on other sites

the id is not escaped out on the hidden field and I didn't notice it.

 

change

echo("<INPUT TYPE=\"hidden\"   NAME=\"JobNumber\" VALUE= \"$output['JobNo']\" id='JobNumber'>"); 

 

to

echo("<INPUT TYPE=\"hidden\"   NAME=\"JobNumber\" VALUE= \"$output['JobNo']\" id=\"JobNumber\">"); 

 

Link to comment
Share on other sites

echo "<INPUT TYPE=\"hidden\"   NAME=\"JobNumber\" VALUE= \"{$output['JobNo']}\" id=\"JobNumber\">"; 

 

I believe it is causing havoc because of the array not being put in properly. The above should work as should this:

echo "<INPUT TYPE=\"hidden\"   NAME=\"JobNumber\" VALUE= \"" . $output['JobNo'] . "\" id=\"JobNumber\">"; 

 

Give that a try and see what comes of it.

 

 

 

Link to comment
Share on other sites

The issue does not lie in how the data is coming out...well in a sense.

 

If you want to have a select option you will need to make JobNumber be unique for each item or put it as an array in the html. As it is the page sees 10 JobNumbers, of course it will default to the last one on the page.

 

echo "<INPUT TYPE=\"hidden\"   NAME=\"JobNumber[]\" VALUE= \"" . $output['JobNo'] . "\" id=\"JobNumber\">"; 

 

The [] after JobNumber will turn it into an array. So you just have to access on the post page by: $_POST['JobNumber'][x] where x is the index you want to display. A checkbox might be better than an input as if checked/selected the array will only contain those jobnumbers.

Link to comment
Share on other sites

Thanks for this, I have put in what you suggested by using the array as above but when I pass the value to the post page it now says "Job No: Array " when it of course should say Job No: and then the specific number.......This is all pretty new to me php code and apologise for the time its taking for you guys to help me out here

 

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.