Jump to content

Not quite sure how to insert into a table


ondi

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.