Bird2819 Posted January 24, 2009 Share Posted January 24, 2009 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. Quote Link to comment Share on other sites More sharing options...
rubing Posted January 25, 2009 Share Posted January 25, 2009 of course you can. you should get a php mysql book. you need to do the following 1. connect to and query your DB for the info you want via php. 2. return the result as an associative array 3. echo the values were you want them don't ask me to write the program for you. start working on step 1 and ask us for help when you need it! Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 25, 2009 Share Posted January 25, 2009 quick array example with a form. <?php if($_POST['submit']){ echo" name: {$_POST['name']} <br> age: {$_POST['age']} <br> message: {$_POST['message']} "; } $a=array("name"=>"redarrow","age"=>"35","message"=>"love php"); echo "<form method='POST' action=' '>"; foreach($a as $key=>$val){ echo "<br><br> please prvide $key<br><br>"; echo "<input type='text' name='$key' value='$val'>"; } echo "<br><br><input type='submit' name='submit' value='SEND!'>"; ?> Quote Link to comment Share on other sites More sharing options...
Bird2819 Posted January 25, 2009 Author Share Posted January 25, 2009 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? Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 25, 2009 Share Posted January 25, 2009 try this for fun as an idea does what you want m8. <?php if($_POST['submit']){ echo" {$_POST['name']} <br> {$_POST['age']} <br> {$_POST['message']} <br><br> "; } $a=array("name"=>"redarrow","age"=>"35","message"=>"love php"); foreach($a as $key=>$val){ echo"<a href='{$_SERVER['PHP_SELF']}?cmd=$key'>$key</a>\n <br>"; } if($_SERVER['PHP_SELF']==$_SERVER['PHP_SELF']){ } if($_GET['cmd']=="name" || $_GET['cmd']=="age" || $_GET['cmd']=="message" ){ echo "<form method='POST' action=' '>"; echo "<br><br> please provide {$_GET['cmd']}<br><br>"; echo "<input type='text' name='{$_GET['cmd']}' value='{$a[$_GET['cmd']]}'>"; echo "<br><br><input type='submit' name='submit' value='SEND!'>"; }else{}; ?> Quote Link to comment Share on other sites More sharing options...
rubing Posted January 25, 2009 Share Posted January 25, 2009 yes this is very simple. again: 1. you store all your info in a database. 2. you query the database & store the resulting info in variables using php. 3. you populate your form with these variables. You should probably start by figuring out how to connect to your DB using php. I don't know what else to tell you dude i am giving you the theoretical background. now you have to get a book and start working through it or pay somebody and they will do it for you. There are plenty of people here who would set something up like that for you very quickly. Quote Link to comment Share on other sites More sharing options...
Bird2819 Posted January 25, 2009 Author Share Posted January 25, 2009 Thanks for the replies dudes. I'll try your suggestions. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 25, 2009 Share Posted January 25, 2009 little example i posted a min ago might also help you out in learning forms m8. <?php //database connection. $db=mysql_connect("localhost","username","password"); $db_res=mysql_select_db("db_name",$db); //form out off loop echo"<form method='POST' method=' '>"; //select every database field names. $sql="SELECT * FROM what_ever"; $sql_res=mysql_query($sql)or die(mysql_error()); // loop all from select statement while($row=mysql_fetch_assoc($sql_res)){ //echo al the names. echo "<input type='text' name='name' vlaue='{$row["name"]}'>"; // submit each name if need be. button named submit. //echo"<input type='submit' name='submit' value='send'>"; } // submit all the names if need be. button named submit. echo"<input type='submit' name='submit' value='send'>"; ?> Quote Link to comment Share on other sites More sharing options...
Bird2819 Posted January 25, 2009 Author Share Posted January 25, 2009 Redarrow - you're awesome. Haven't got it all the way yet but have renewed confidence. Looking forward to a day of success! Quote Link to comment Share on other sites More sharing options...
Bird2819 Posted February 7, 2009 Author Share Posted February 7, 2009 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? Quote Link to comment 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.