Jump to content


Photo

[solved] Inserting Forms Information into MySql Tables


  • Please log in to reply
28 replies to this topic

#21 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 28 August 2006 - 04:24 PM

ooops. :)

I changed the table name

Should be
<?
$db = mysql_connect("db5.awardspace.com:3306", "fmpsite_reg", "pitstop") or die("Could not connect.");
if(!$db)
   die("no db");
if(!mysql_select_db("fmpsite_reg",$db))
    die("No database selected.");
if(!get_magic_quotes_gpc())
mysql_select_db("fmprotasy_reg", $con);
$player = addslashes($_POST['Player']);
$price = addslashes($_POST['Price']);
$sql="INSERT INTO Market SET
        Player = '".$player."',
        Price = '".$price."',
        Type = '".$_POST['Type']."',
        Position = '".$_POST['Pos']."',
        Age = '".$_POST['Age']."',
        Ka = '".$_POST['GK']."',
        Ta = '".$_POST['DEF']."',
        Pa = '".$_POST['MID']."',
        Sa = '".$_POST['ATT']."'";
// echo $sql;  for testing purposes
if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
?>

I also noticed you have a Team field in your form but none in the table. ????
Ray

#22 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 04:27 PM

Oh no, you are right, i have no part for the Team. Do i need to recreate the table in the database?

#23 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 28 August 2006 - 04:29 PM

No you can insert it using phpmyadmin. You will have to alter the insert query also.

Ray

#24 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 04:37 PM

Ok is this right:

Form:
<form action="insert.php" method="post">
<table>
  <tr>
    <td align="center" width="119">Player<br /><font face="Arial"><input type="text" name="Player" size="10"></font></td>
	<td align="center" width="95">Price<br /><font face="Arial"><input type="text" name="Price" size="7"></font></td>
	<td align="center" width="184">Team<br />
      <select size="1" name="Team">
					<optgroup label="Premiership">
					<option value="Asnl">Arsenal
					<option value="AV">Aston Villa
					<option value="Birm">Birmingham City
					<option value="Bkbn">Blackburn Rovers
					<option value="Bltn">Bolton Wanderers
					<option value="Cltn">Charlton Athletic
					<option value="Chel">Chelsea
					<option value="Evtn">Everton
					<option value="Flhm">Fulham
					<option value="Lpol">Liverpool
					<option value="Manc">Manchester City
					<option value="Manu">Manchester United
					<option value="Boro">Middlesbrough
					<option value="Newc">Newcastle United
					<option value="Pomp">Portsmouth
					<option value="Sund">Sunderland
					<option value="Sprs">Tottenham Hotspur
					<option value="WBA">West Bromwich Albion
					<option value="WHam">West Ham United
					<option value="Wign">Wigan Athletic
					<optgroup label="Championship">
					<option value="burn">Burnley
					<option value="cardiff">Cardiff City
					<option value="cov">Coventry
					<option value="cry p">Crystal Palace
					<option value="derby">Derby
					<option value="hull">Hull City
					<option value="ips">Ipswich
					<option value="leeds">Leeds
					<option value="leicester">Leicester
					<option value="luton">Luton
					<option value="norwich">Norwich
					<option value="Plymouth">Plymouth
					<option value="preston">Preston
					<option value="qpr">Queens Park Rangers
					<option value="reading">Reading
					<option value="sheff u">Sheffield United
					<option value="south">Southampton
					<option value="stoke">Stoke
					<option value="watford">Watford
					<option value="wolves">Wolves
      </select>
    </td>
	<td align="center" width="116">Points<br /><font face="Arial">
      <select size="1" name="Type">
					<option value="Transfer">Transfer
					<option value="Loan">Loan
					<option value="Release">Release
      </select></font>
    </td>
	<td align="center" width="177">Position<br /><font face="Arial">
      <select size="1" name="Pos">
					<option value="GK">GK
					<option value="DEF">DEF
					<option value="MID">MID
					<option value="ATT">ATT
      </select></font>
    </td>
	<td align="center" width="42">Age<br /><font face="Arial">
      <select size="1" name="Age">
      <?
        for($age = 15; $age<=38; $age++){
          echo "<option value=\"$age\">$age</option>";
        }
      ?>
      </select></font>
    </td>
	<td align="center" width="42">GK<br /><font face="Arial">
      <select size="1" name="GK">
	  <?
        for($gk=1; $gk<=14; $gk++){
          echo "<option value=\"$gk\">$gk</option>";
        }
      ?>
      </select></font>
    </td>
	<td align="center" width="42">DEF<br /><font face="Arial">
      <select size="1" name="DEF">
	  <?
        for($def=1; $def<=14; $def++){
          echo "<option value=\"$def\">$def</option>";
        }
      ?>
      </select></font>
    </td>
	<td align="center" width="42">MID<br /><font face="Arial">
      <select size="1" name="MID">
	  <?
        for($mid=1; $mid<=14; $mid++){
          echo "<option value=\"$mid\">$mid</option>";
        }
      ?>
      </select></font>
    </td>
	<td align="center" width="42">ATT<font face="Arial">
      <select size="1" name="ATT">
	  <?
        for($att=1; $att<=14; $att++){
          echo "<option value=\"$att\">$att</option>";
        }
      ?>
      </select></font>
    </td>
  </tr>
  <tr>
    <td colspan=10 align=center>
      <input type=submit name=submit value=submit />
    </td>
  </tr>
</table>
</form>

insert.php

<?
$db = mysql_connect("db5.awardspace.com:3306", "fmpsite_reg", 

"pitstop") or die("Could not connect.");
if(!$db)
   die("no db");
if(!mysql_select_db("fmpsite_reg",$db))
    die("No database selected.");
if(!get_magic_quotes_gpc())
mysql_select_db("fmprotasy_reg", $con);
$player = addslashes($_POST['Player']);
$price = addslashes($_POST['Price']);
$sql="INSERT INTO Market SET
        Player = '".$player."',
        Price = '".$price."',
        Type = '".$_POST['Type']."',
        Team = '".$_POST['Team']."'
        Position = '".$_POST['Pos']."',
        Age = '".$_POST['Age']."',
        Ka = '".$_POST['GK']."',
        Ta = '".$_POST['DEF']."',
        Pa = '".$_POST['MID']."',
        Sa = '".$_POST['ATT']."'";
// echo $sql;  for testing purposes
if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }
?>


#25 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 04:45 PM

New error

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Position = 'ATT', Age = '16', Ka = '5', Ta = '6', ' at line 6

#26 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 28 August 2006 - 04:47 PM

You forgot the comma after the team insert in your query

Team = '".$_POST['Team']."'

put the comma at the end

Also you way want to clean up your form. Internet explorer may end you form tags for you but other browsers may not. Close out all you option tags and any others

example:
<option value="Cltn">Charlton Athletic

should be
<option value="Cltn">Charlton Athletic</option>

Ray


#27 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 04:58 PM

It completely works now. I can't Thank You enough ray you have been a huge help as has Crayon.

Now i have the possibly tougher task of extracting the information from the database to a html table but i have read a tutorial so it shouldn't be too bad.

#28 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 28 August 2006 - 05:00 PM

No problem. Start a new tread for that when the time comes. That way they can mark this thread as solved.

Ray

#29 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 05:02 PM

No problem. I would hope to think ill be able to do it without help but i doubt i will be able to do it on my own. Ill give it a good go though.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users