jamezz98 Posted March 16, 2013 Share Posted March 16, 2013 Hi all, I am writing a simple time tracking web app in php with a backend mysql database to run on my NAS at home. When entering time in to the timesheet i have a drop down for school then a drop down to location. Once these are selected you select the date and enter the hours and click the submit button to add your time. It does not seem to be passing the school ID correctly. Here is the section from my main time entry page which select the school names from the School table and puts the id from the table in $school. <td> <select id='schoolid' name="school"> <option value="">-- Select School --</option> <?php // Get records from database Locations $list=mysql_query("select * from School order by school_name asc"); // Show records by while loop in the drop down box. while($row2=mysql_fetch_assoc($list)){ ?> <option value=<? echo $row2['id']; ?>><? echo $row2['school_name']; ?></option> <?php $school = $row2['id']; ?> <?php } ?> </select> </td> I have two hidden fields which store this information to pass to the post page. I have even changed them from hidden to text as you can see below to see what they are being set to. When i change school in the dropdown to another school it does not seem to change the id passed. </table> Mileage <input type="text" name="mileage" value=<?php echo $mileage_id; ?> /> SchoolID <input type="text" name="school" value=<?php echo $school; ?> /> <input type="submit" name="submit" value="Add Time" /> </form> Is this enough information to see what i am doing wrong? Thanks in advance Regards James Quote Link to comment https://forums.phpfreaks.com/topic/275737-issue-with-variable-not-updating/ Share on other sites More sharing options...
davidannis Posted March 16, 2013 Share Posted March 16, 2013 You need quotes around the value in your select <option value="<? echo $row2['id']; ?>"><? echo $row2['school_name']; ?></option> and I don't understand why you have the line below it: <?php $school = $row2['id']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/275737-issue-with-variable-not-updating/#findComment-1419013 Share on other sites More sharing options...
Solution jamezz98 Posted March 16, 2013 Author Solution Share Posted March 16, 2013 Thanks for the response daviddannis. I have been playing with it more today and worked out that i had removed the school_id field from my table therefore the insert was not working. Once i had added this in the code works fine. I left out the " in that string as the value was integer Cheers Quote Link to comment https://forums.phpfreaks.com/topic/275737-issue-with-variable-not-updating/#findComment-1419026 Share on other sites More sharing options...
davidannis Posted March 16, 2013 Share Posted March 16, 2013 jamezz98: You taught me me something new too. I thought that the html standards required quotes around all values. I looked it up and found out that they are just recommended. By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa. Authors may also use numeric character references to represent double quotes (") and single quotes ('). For double quotes authors can also use the character entity reference ". In certain cases, authors may specify the value of an attribute without any quotation marks. The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (ASCII decimal 58). We recommend using quotation marks even when it is possible to eliminate them. Quote Link to comment https://forums.phpfreaks.com/topic/275737-issue-with-variable-not-updating/#findComment-1419043 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.