ondi Posted April 12, 2009 Share Posted April 12, 2009 This is what my page looks like: http://79.170.43.200/adp-design-demos.com/findmeagame/addgame.php And here is my code: <?php $host = 'localhost'; $user = 'user'; $password = 'pass'; $txt_db_name = 'web176-findme'; $connection = mysql_connect("$host","$user","$password") or die(mysql_error()); mysql_select_db("$txt_db_name",$connection) or die(mysql_error()); $get_matches = mysql_query(" SELECT MD.matchid AS matchid, DATE_FORMAT(MD.date, '%W %d %b') AS date, DATE_FORMAT(MD.date, '%H:%i') AS clock, MD.teamname AS teamname, MD.homeaway AS venue, MD.level AS level, MD.contact AS contact FROM matchdetails MD ORDER BY MD.date ASC ", $connection) or die(mysql_error()); ?> <table> <form method="post" action="<?php echo "$PHP_SELF?sessioid=$sessio" ?>"> <table width="100%" cellspacing="3" cellpadding="3" border="0"> <tr> <td align="left" valign="top"> Date and time: </td> <td align="left" valign="top"> <select name="day"> <?php //printataan päivät for($i = 1 ; $i < 32 ; $i++) { if($i<10) { $i = "0".$i; } if($i == "01") echo "<option value=\"$i\" SELECTED>$i</option>\n"; else echo "<option value=\"$i\">$i</option>\n"; } ?> </select> / <select name="month"> <?php //printataan kuukaudet for($i = 1 ; $i < 13 ; $i++) { if($i<10) { $i = "0".$i; } if($i == "05") echo "<option value=\"$i\" SELECTED>$i</option>\n"; else echo "<option value=\"$i\">$i</option>\n"; } ?> </select> / <select name="year"> <?php //printataan vuodet for($i = 2009 ; $i < 2015 ; $i++) { if($i<10) { $i = "0".$i; } if($i == "2015") echo "<option value=\"$i\" SELECTED>$i</option>\n"; else echo "<option value=\"$i\">$i</option>\n"; } ?> </select> at <select name="hour"> <?php //printataan tunnnit for($i = 0 ; $i < 24 ; $i++) { if($i<10) { $i = "0".$i; } if($i == "15") echo "<option value=\"$i\" SELECTED>$i</option>\n"; else echo "<option value=\"$i\">$i</option>\n"; } ?> </select> : <select name="minute"> <?php //printataan minuutit for($i = 0 ; $i < 60 ; $i++) { if($i<10) { $i = "0".$i; } if($i == "00") echo "<option value=\"$i\" SELECTED>$i</option>\n"; else echo "<option value=\"$i\">$i</option>\n"; } ?> </select> </td> </tr> <tr> <td align="left" valign="top"> Team Name:</td> <td align="left" valign="top"> <input type="text" name="pob" size="30"></td> </tr> <tr> <td align="left" valign="top"> Looking For (Home/Away/Neutral):</td> <td align="left" valign="top"> <input type="text" name="pod" size="30"></td> </tr> <tr> <td align="left" valign="top"> Level of Your Team:</td> <td align="left" valign="top"> <input type="text" name="pod" size="30"></td> </tr> <tr> <td align="left" valign="top"> Contact Details:</td> <td align="left" valign="top"> <input type="text" name="pod" size="30"></td> </tr> </table> <input type="submit" name="add_submit" value="Add game request"> </form> I want to make it so when the user clicks the submit button, 'Date and time:' goes into 'MD.date' 'Team Name:' goes into 'MD.teamname' And so on... can someone help me out please? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/153718-not-quite-sure-how-to-insert-into-a-table/ Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Yeah, use mysql_query("INSERT INTO... Quote Link to comment https://forums.phpfreaks.com/topic/153718-not-quite-sure-how-to-insert-into-a-table/#findComment-807795 Share on other sites More sharing options...
ondi Posted April 12, 2009 Author Share Posted April 12, 2009 I gathered that much... do i put it after each <td align="left" valign="top"> Looking For (Home/Away/Neutral):</td> <td align="left" valign="top"> <input type="text" name="pod" size="30"></td> Quote Link to comment https://forums.phpfreaks.com/topic/153718-not-quite-sure-how-to-insert-into-a-table/#findComment-807811 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 No. Considering you're pointing the form to itself, I'd do something like so if(isset($_POST['something_in_your_form'])) { $post = $_POST['something_in_your_form']; //$_POST all your variables mysql_query("INSERT INTO table SET whatever='$post_variable'"); } Along the lines of that. Quote Link to comment https://forums.phpfreaks.com/topic/153718-not-quite-sure-how-to-insert-into-a-table/#findComment-807814 Share on other sites More sharing options...
ondi Posted April 12, 2009 Author Share Posted April 12, 2009 I'm still rather lost could you give me an example using my code? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/153718-not-quite-sure-how-to-insert-into-a-table/#findComment-807819 Share on other sites More sharing options...
jackpf Posted April 12, 2009 Share Posted April 12, 2009 Why not have another file then, it'll be simpler. Put action="update.php" in your form, and then make a file called update.php. In it, put something like this. $name = $_POST['name']; //post the rest of your variables. mysql_query("INSERT INTO yourTable (name) VALUES ($name)") or die(mysql_error()); // insert the rest of your $_POSTs as well header('Location: '.$_SERVER['HTTP_REFERER']); //redirect back to the original pages //or display a message like echo 'Update completed.'; If you have any trouble, google a php-mysql tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/153718-not-quite-sure-how-to-insert-into-a-table/#findComment-807823 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.