nd3_2000 Posted August 11, 2009 Share Posted August 11, 2009 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, 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 Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/ Share on other sites More sharing options...
waterssaz Posted August 11, 2009 Share Posted August 11, 2009 post your code for the hidden field that you pass :-) Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895633 Share on other sites More sharing options...
nd3_2000 Posted August 11, 2009 Author Share Posted August 11, 2009 Well its here, it isnt hidden yet but will be when I sort this out echo("<INPUT TYPE=\"text\" NAME=\"JobNumber\" VALUE= \"$JobNo\" id='JobNumber'>"); Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895637 Share on other sites More sharing options...
waterssaz Posted August 11, 2009 Share Posted August 11, 2009 Ok, I'm surprsied that you can see any list of jobs. I have never seen array keys accessed without the quotes around them like this??? Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895644 Share on other sites More sharing options...
nd3_2000 Posted August 11, 2009 Author Share Posted August 11, 2009 ok well fair enough, how would you do this job then?? All it does is continuasly passes the last job number through not the one I need (unless I want the last one of course) Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895646 Share on other sites More sharing options...
waterssaz Posted August 11, 2009 Share Posted August 11, 2009 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>";} Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895652 Share on other sites More sharing options...
nd3_2000 Posted August 11, 2009 Author Share Posted August 11, 2009 HI I tried this but this gives me an error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/19/d153224249/htdocs/SelectAllEBJobs.php on line 34 Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895678 Share on other sites More sharing options...
waterssaz Posted August 11, 2009 Share Posted August 11, 2009 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\">"); Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895685 Share on other sites More sharing options...
nd3_2000 Posted August 11, 2009 Author Share Posted August 11, 2009 Still giving me exacty the same error...this is driving me nuts, one of those things can spend days on and finally see its somethignstupid but am just not seeing it this week Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895690 Share on other sites More sharing options...
waterssaz Posted August 11, 2009 Share Posted August 11, 2009 remove the brackets around the input fileds Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895698 Share on other sites More sharing options...
premiso Posted August 11, 2009 Share Posted August 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895699 Share on other sites More sharing options...
nd3_2000 Posted August 11, 2009 Author Share Posted August 11, 2009 Ok, that last one worked so its not erroring anymore but its still has the original problem of passing through the last one one the list no matter which one I choose :'( Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895709 Share on other sites More sharing options...
waterssaz Posted August 11, 2009 Share Posted August 11, 2009 And the job nos are displaying correctly from this line yes? echo "<p><b>Job ID:</b> ". $output['JobNo']; Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895714 Share on other sites More sharing options...
nd3_2000 Posted August 11, 2009 Author Share Posted August 11, 2009 Yes that works fine, the number is there and is different for each job as is on the database! Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895718 Share on other sites More sharing options...
premiso Posted August 11, 2009 Share Posted August 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-895728 Share on other sites More sharing options...
nd3_2000 Posted August 12, 2009 Author Share Posted August 12, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/169772-solved-php-passing-single-value-rather-than-entire-section/#findComment-896241 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.