Bird2819
New Members-
Posts
9 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
Bird2819's Achievements
Newbie (1/5)
0
Reputation
-
getting the _POST array to distinguish which button was clicked
Bird2819 replied to Bird2819's topic in PHP Coding Help
Here are the three php files and one database [attachment deleted by admin] -
getting the _POST array to distinguish which button was clicked
Bird2819 replied to Bird2819's topic in PHP Coding Help
Okay. I have the work zipped. How do I upload? Sorry - never done this. -
getting the _POST array to distinguish which button was clicked
Bird2819 replied to Bird2819's topic in PHP Coding Help
Thanks for the advice. This does change the name of each button, but they all still act the same: while($row=mysql_fetch_assoc($sql_res)){ echo "<input type='text' name='a_name' value='{$row["a_name"]}'>"; echo"<input type='submit' name='{$row["a_id"]}' value='send'>"; } -
This will be a fleet tracking/maintenance program. First, the user see's a table of all the equipment and vehicles with send buttons at the end of each record. The send buttons take the user to a form where he can enter maintenance data. The form will have the vehicle's name field already filled in to avoid misspelling/data redundancy for maintenance. - I have this working, except.. each send button isn't assigned to their respective vehicle name. In other words, when I click send, the same vehicle name is filled in for the name field on the form (the last vehicle name in the table). I'm thinking I may need a two dim array and a nested loop to individualize the send buttons, but there must be some tweaking to do with the _POST array in the other file. So I'm working with three files - one that displays the table with buttons (assets.php), one that displays a maintenance form with the name value already filled in (add_repair.php), and one that inserts the repair data into the repair table of my database. Here they are: //assets.php <?php //database connection. mysql_connect("localhost", "root", "xxxxxx") or die(mysql_error()); mysql_select_db("as_maintenance") or die(mysql_error()); //form out of loop echo '<form action="add_repair.php" method="post">'; $sql="SELECT * FROM asset"; $sql_res=mysql_query($sql)or die(mysql_error()); // loop all from select statement while($row=mysql_fetch_assoc($sql_res)){ //echo all the names. echo "<input type='text' name='a_name' value='{$row["a_name"]}'>"; //echo the send buttons echo"<input type='submit' name='submit' value='send'>"; } ?> //////////////////////////////////////////////////////////////////////////// //add_repair.php <?php echo '<form action="repair.php" method="post">'; echo'<fieldset>'; echo '<p><label for="a_name">Asset Name</label> </p>'; echo "<input type='text' name='a_name' value='{$_POST['a_name']}'>"; //echo '<input type="text" name="a_name"/>'; echo '<p><label for="employee_name">Mechanic</label> <input type="text" name="employee_name"/></p>'; echo '<p><label for="repair_date">Date</label> <input type="text" name="repair_date"/></p>'; echo '<p><label for="miles_hours">Miles/Hours</label> <input type="text" name="miles_hours"/></p>'; echo '<p><label for="notes">Notes</label> <input type="text" name="notes"/></p>'; echo '<p><label for="ser_or_vin">Serial-VIN</label> <input type="text" name="ser_or_vin"></p>'; echo '<p class="submit"><input type="submit" value="Submit" /></p>'; echo '</fieldset>'; echo '</form>'; mysql_query("INSERT INTO repair (a_name,employee_name,repair_date,miles_hours,notes,ser_or_vin)VALUES('$a_name','$employee_name','$repair_date','$miles_hours','$notes',$ser_or_vin')") or die(mysql_error()); echo "Data Inserted! "; echo "<a href=\"sa2-05.php\" target=\"_self\">back</a>"; ?> ////////////////////////////////////////////////////////////////////////////////// //repair.php <?php mysql_connect("localhost", "root", "xxxxxx") or die(mysql_error()); mysql_select_db("as_maintenance") or die(mysql_error()); echo "Connected!"; // recieving data values from the form repair_form.html $a_name = $_POST['a_name']; $employee_name = $_POST['employee_name']; $repair_date = $_POST['repair_date']; $miles_hours = $_POST['miles_hours']; $notes = $_POST['notes']; $ser_or_vin = $_POST['ser_or_vin']; // now make the query to input the data to the db mysql_query("INSERT INTO repair (a_name,employee_name,repair_date,miles_hours,notes,ser_or_vin) VALUES('$a_name','$employee_name','$repair_date','$miles_hours','$notes','$ser_or_vin')") or die (mysql_error()); echo "Data Inserted! "; ?> /////////////////////////////////////////////////////////////////////////////// I'll take any suggestions anyone has. Thanks very much.
-
How can I take values from a table into a form
Bird2819 replied to Bird2819's topic in PHP Coding Help
Red, Using some of your code I have: //file ex1.php //database connection. mysql_connect("localhost", "jay", "butters47") or die(mysql_error()); mysql_select_db("as_maintenance") or die(mysql_error()); echo '<form action="add_repair.php" method="post">'; $sql="SELECT * FROM asset"; //my equipment maintenance database $sql_res=mysql_query($sql)or die(mysql_error()); // loop all from select statement while($row=mysql_fetch_assoc($sql_res)){ //echo all the names. echo "<input type='text' name='a_name' value='{$row["a_name"]}'>"; // submit each name if need be. button named submit. echo"<input type='submit' name='submit' value='send'>"; } //I've directed the input to a form (add_repair.php), here: <?php echo '<form action="repair.php" method="post">'; //repair.php inserts the repair info into the repair table of my database. //the form: echo'<fieldset>'; echo '<p><label for="a_name">Asset Name</label> </p>'; echo "<input type='text' name='a_name' value='{$_POST['a_name']}'>"; echo '<p><label for="employee_name">Mechanic</label> <input type="text" name="employee_name"/></p>'; echo '<p><label for="repair_date">Date</label> <input type="text" name="repair_date"/></p>'; echo '<p><label for="miles_hours">Miles/Hours</label> <input type="text" name="miles_hours"/></p>'; echo '<p><label for="notes">Notes</label> <input type="text" name="notes"/></p>'; echo '<p><label for="ser_or_vin">Serial-VIN</label> <input type="text" name="ser_or_vin"></p>'; echo '<p class="submit"><input type="submit" value="Submit" /></p>'; echo '</fieldset>'; echo '</form>'; mysql_query("INSERT INTO repair (a_name,employee_name,repair_date,miles_hours,notes,ser_or_vin)VALUES('$a_name','$employee_name','$repair_date','$miles_hours','$notes',$ser_or_vin')") or die(mysql_error()); echo "Data Inserted! "; ?> //ex1.php displays the asset names with send buttons so I can choose which asset to repair. When I click a send button, the first field of the form is filled in which is great. However it is always the last record processed in the foreach() loop of ex1.php (I think). I want the form's a_name field to be filled in with the particular asset name's button I clicked on. How can I get add_repair.php to know which asset I want to work on? -
How can I take values from a table into a form
Bird2819 replied to Bird2819's topic in PHP Coding Help
Redarrow - you're awesome. Haven't got it all the way yet but have renewed confidence. Looking forward to a day of success! -
How can I take values from a table into a form
Bird2819 replied to Bird2819's topic in PHP Coding Help
Thanks for the replies dudes. I'll try your suggestions. -
How can I take values from a table into a form
Bird2819 replied to Bird2819's topic in PHP Coding Help
Thanks. I don't want you to write the code for me but to clarify, I want to click somewhere on the table of assets (like the name of an asset) and go to the repair form. I want this repair form to already see which asset I'm updating, so it will already have name, serial, and hours-mileage. Is this possible? -
I'm using byethost - a free web hosting service that has MySQL, PHP available. I have created a fleet maintenance database consisting of at least two tables - asset and repair. Some asset table fields are: asset_id, name, serial_number, hours_mileage After displaying the asset table, I thought I would have one of the fields be a link to a form which populates the repair table. Can I possibly take the asset_id and hours-mileage values from the table to this form? Other fields would be: date, mechanic, repair_notes. Any ideas, or reading material suggestions would be appreciated. Thanks.