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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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