Jump to content

elie

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

elie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. good day to all of you! my page is all about asking a user to input any number of 'equipments' and the output will produce number of sets of fields which the user inputted on the previous page.. i have already the scripts on inserting and viewing these records using mysql and php; these codes are working well already... (inventory1) -- after the user inputted the number [code] . . . <?php for($i=0; $i<$num; $i++) {     echo "     <tr><td align=center><input type='text' name='field_a[]' size='15'/></td>         <td align=center><input type='text' name='field_b[]' size='15'/></td>         <td align=center><input type='text' name='field_c[]' size='25'/></td>         <td align=center><input type='text' name='field_d[]' size='15'/></td>         <td align=center><input type='text' name='field_e[]' size='15'/></td>         <td align=center><input type='text' name='field_f[]' size='25'/></td></tr>     "; } ?> . . . [/code] (inventory2.php) -- the records being inserted in database [code] <?php $field_a = $_POST['field_a']; $field_b = $_POST['field_b']; $field_c = $_POST['field_c']; $field_d = $_POST['field_d']; $field_e = $_POST['field_e']; $field_f = $_POST['field_f']; $num = $_POST['num']; foreach($field_a as $key => $val) { $sql="INSERT INTO inventory (field_a, field_b, field_c, field_d, field_e, field_f, title) VALUES ('".$val."','".$field_b[$key]."','".$field_c[$key]."','".$field_d[$key]."','".$field_e[$key]."','".$field_f[$key]."', '$title')"; $connection = mysql_connect("localhost","root","") or die ("Couldn't connect to server."); $db = mysql_select_db("setup", $connection) or die ("Couldn't select database."); mysql_query($sql) or die(mysql_error()); } . . . [/code] (view.php) -- viewing them [code] <?php include("config.php"); $query = "SELECT * FROM inventory where title='$title'"; $result = mysql_query($query) or die(mysql_error()); if($result && mysql_num_rows($result) > 0) {      while($row = mysql_fetch_array($result))      {           extract($row); echo " <tr> <td>$field_a<br /></td> <td>$field_b<br /></td> <td>$field_c<br /></td> <td>$field_d<br /></td> <td>$field_e<br /></td> <td>$field_f<br /></td> </tr> ";                } } [/code] my problem now is how to update the arrayed fields?? in mysql and php?? please help!
  2. thanks for the help ober!! [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]
  3. i have stored arrayed fields into the database... i want to create a new page where i can call and retrieve these values stored from the database? please help... [code] <?php include("config.php"); $field_a = $_POST['field_a']; $field_b = $_POST['field_b']; $field_c = $_POST['field_c']; $field_d = $_POST['field_d']; $field_e = $_POST['field_e']; $field_f = $_POST['field_f']; $num = $_POST['num']; foreach($field_a as $key => $val) { $sql="INSERT INTO sample (field_a, field_b, field_c, field_d, field_e, field_f, code) VALUES ('".$val."','".$field_b[$key]."','".$field_c[$key]."','".$field_d[$key]."','".$field_e[$key]."','".$field_f[$key]."','$code')"; mysql_query($sql) or die(mysql_error()); } ?> [/code]
  4. oh well... i got it solved! [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] jst made slight errors with the underscore thing... thanks for the help guys! ur all geniuses!
  5. elie

    mysqldump

    im having a hard time doing this mysqldump thing... what if i don't have a username and password since i only use mysql locally?(at home), i dunno how it's called.. i just wanna copy my database coz i need to transfer them to another workstation, and in the mean time create a backup for it... what am i gonna do??
  6. thanks for the help guys... i kinda got it already, but only field_a values are stored in the database... here's the code.. [code] <?php $field_a = $_POST['field_a']; $field_b = $_POST['field_b']; $field_c = $_POST['field_c']; $field_d = $_POST['field_d']; $field_e = $_POST['field_e']; $field_f = $_POST['field_f']; $num = $_POST['num']; foreach($field_a as $key => $val) { $sql="INSERT INTO inventory (field_a, field_b, field_c, field_d, field_e, field_f) VALUES ('".$val."','".$field_b[$key]."','".$field_c[$key]."','".$field_d[$key]."','".$field_e[$key] ."','".$field_f[$key]."')"; $connection = mysql_connect("localhost","root","") or die ("Couldn't connect to server."); $db = mysql_select_db("investigatory", $connection) or die ("Couldn't select database."); mysql_query($sql) or die(mysql_error()); } ?> [/code]
  7. what i wanted to happen is that... say $num=3, it will output... field_a0, field_b0, field_c0, field_d0, field_e0, field_f0 field_a1, field_b1, field_c1, field_d1, field_e1, field_f1 field_a2, field_b2, field_c2, field_d2, field_e2, field_f2 a user enters anything into every field, which means each field has different values, say... field_a0 = hello field_b0 = world . . . field_f2 = goodbye i want these values to be inserted into the database... is it possible to do such thing?? [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]
  8. okay... so here's my entire code... [code] <?php $num = $_POST['num']; for($i=0; $i<$num; $i++) { $sql="INSERT INTO inventory (field_a, field_b, field_c, field_d, field_e, field_f) VALUES ('$field_a_$i', '$field_b_$i', '$field_c_$i', '$field_d_$i', '$field_e_$i', '$field_f_$i')"; } $connection = mysql_connect("localhost","root","") or die ("Couldn't connect to server."); $db = mysql_select_db("investigatory", $connection) or die ("Couldn't select database."); $sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query."); if (!sql_result) { echo "<p>Couldn't insert into table"; } else { echo "<p>created!!!"; } ?> [/code] the message i got was "Couldn't execute query." doesn't it have something to do with [b]$num = $_POST['num'];[/b] ???
  9. [!--quoteo(post=374537:date=May 16 2006, 09:56 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 16 2006, 09:56 PM) [snapback]374537[/snapback][/div][div class=\'quotemain\'][!--quotec--] first, try putting some ' ' around the variable names: $sql="INSERT INTO inventory (field_a, field_b, field_c, field_d, field_e, field_f) VALUES ('$field_a_$i',' $field_b_$i', '$field_c_$i', '$field_d_$i', '$field_e_$i', '$field_f_$i')"; [/quote] yep i already tried it.. still the same error i got.. hmm.. what could've been wrong?
  10. actually im using php 4.1.1, so i guess it has slight difference in their syntax... does it?? this is my first page... inventory.php [code] <form method="POST" action="inventory1.php"> <p>Number of equipments:<br><input type="text" name="num" size=5></p> <input type="submit" value="Go"> </form> [/code] going to inventory1.php... [code] <form method="POST" action="add_inventory.php"> <table> <?php for($i=0; $i<$num; $i++) {     echo "<tr><td><input type='text' name='field_a_$i'/></td>";     echo "<td><input type='text' name='field_b_$i'/></td>";     echo "<td><input type='text' name='field_c_$i'/></td>";     echo "<td><input type='text' name='field_d_$i'/></td>";     echo "<td><input type='text' name='field_e_$i'/></td>";     echo "<td><input type='text' name='field_f_$i'/></td></tr>"; } ?> <tr> <td><input type="submit" value="Next"></td> </tr> </table> </form> [/code] and lastly, this starts my problem.. add_inventory.php [code] <?php $num = $_POST['num']; for($i=0; $i<$num; $i++) { $sql="INSERT INTO inventory (field_a, field_b, field_c, field_d, field_e, field_f) VALUES ($field_a_$i, $field_b_$i, $field_c_$i, $field_d_$i, $field_e_$i, $field_f_$i)"; } ... ?> [/code] the first two pages worked alright, but when i start inserting the values, it wouldnt execute... =(
  11. hmmm... i tried it but it wouldn't work... it creates an error msg couldn't execute query... why is that?? thanks for taking time to help me with this..
  12. hello everyone... i am quite new to php and i have a problem regarding php loops and arrays... i want to have a form which will ask a user to input a number of 'set of fields' .. when the form is submitted, it will create a table with its rows(set of fields) being looped accdg. to the user input... in my case i have 6 textfields; (field1, field2, field3, field4, field5, field6) = 1 set of fields... say if a user submits 4, it will create 4 rows(or sets of fields) how do i implement this using arrays? another problem is how will i insert all the textfield values in mysql? im so clueless... please help me! [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]
×
×
  • 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.