Jump to content

Archived

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

OCHE1976

Loading SQL Problem

Recommended Posts

Not sure if I am doing this correcly, but the SQL database is NOT being loaded. For each person listed on the form, I need to create a seperate record with different information.

You can view the form at:
[a href=\"http://www.usadarts.com/adorep/lod.htm\" target=\"_blank\"]http://www.usadarts.com/adorep/lod.htm[/a]


Form Code
[code]
<form action="post.php" method="POST">
    <b><i>
    <center>
      Enter LOD Results
    </center>
    </i></b>
    <table border="5" cellspacing="10" cellpadding="10" align="center">
      <tr>
        <td> <b>Date:</b> </td>
        <td>
          <select name="date">
            <OPTION VALUE="">Select Date
            <OPTION VALUE="20060304">March 4, 2006
            <OPTION VALUE="20060311">March 11, 2006
            <OPTION VALUE="20060318">March 18, 2006
           </select>
        </td>
      </tr>
      <tr>
        <td valign="top"> <b>Number of Entries:</b> </td>
        <td>
          <input type="text" name="entries" size="3">
        </td>
      </tr>
      <tr>
        <td valign="top"> <b>1st Place:</b> </td>
        <td> Player 1
          <input type="text" name="1sta" size="30">
          <br>
          Player 2
          <input type="text" name="1stb" size="30">
        </td>
      </tr>
      <tr>
        <td valign="top"> <b>2nd Place:</b> </td>
        <td> Player 1
          <input type="text" name="2nda" size="30">
          <br>
          Player 2
          <input type="text" name="2ndb" size="30">
        </td>
      </tr>
      <tr>
        <td valign="top"> <b>3/4th Place:</b> </td>
        <td> Player 1
          <input type="text" name="3rda" size="30">
          <br>
          Player 2
          <input type="text" name="3rdb" size="30">
        </td>
      </tr>
      <tr>
        <td valign="top"> <b>3/4th Place:</b> </td>
        <td> Player 1
          <input type="text" name="4tha" size="30">
          <br>
          Player 2
          <input type="text" name="4thb" size="30">
        </td>
      </tr>
      <tr>
        <td>
          <input type="reset" name="Submit" value="Clear Form">
        </td>
        <td>
          <input type="submit" name="Submit" value="Submit Form">
        </td>
      </tr>
    </table>
  </form>[/code]

and here is the PHP code:
[code]
<?php
$event = 'Ringside Pub LOD'
$date = $_POST['date'];

$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("username_rankings");

$player = $_POST['1sta'];
$place = '1st';
$points = 5 * $_POST['entries'];
$insert = "INSERT INTO 2006 (date, event, player, place, entries, points)
    VALUES ('$date', '$event', '$player', '$place', '$entries', '$points')";
$results = mysql_query($insert);

$player = $_POST['1stb'];
$place = '1st';
$points = 5 * $_POST['entries'];
$insert = "INSERT INTO 2006 (date, event, player, place, entries, points)
    VALUES ('$date', '$event', '$player', '$place', '$entries', '$points')";
$results = mysql_query($insert);

$player = $_POST['2nda'];
$place = '2nd';
$points = 3 * $_POST['entries'];
$insert = "INSERT INTO 2006 (date, event, player, place, entries, points)
    VALUES ('$date', '$event', '$player', '$place', '$entries', '$points')";
$results = mysql_query($insert);

$player = $_POST['2ndb'];
$place = '2nd';
$points = 3 * $_POST['entries'];
$insert = "INSERT INTO 2006 (date, event, player, place, entries, points)
    VALUES ('$date', '$event', '$player', '$place', '$entries', '$points')";
$results = mysql_query($insert);

$player = $_POST['3rda'];
$place = 'Top 4';
$points = 1 * $_POST['entries'];
$insert = "INSERT INTO 2006 (date, event, player, place, entries, points)
    VALUES ('$date', '$event', '$player', '$place', '$entries', '$points')";
$results = mysql_query($insert);

$player = $_POST['3rdb'];
$place = 'Top 4';
$points = 1 * $_POST['entries'];
$insert = "INSERT INTO 2006 (date, event, player, place, entries, points)
    VALUES ('$date', '$event', '$player', '$place', '$entries', '$points')";
$results = mysql_query($insert);

$player = $_POST['4tha'];
$place = 'Top 4';
$points = 1 * $_POST['entries'];
$insert = "INSERT INTO 2006 (date, event, player, place, entries, points)
    VALUES ('$date', '$event', '$player', '$place', '$entries', '$points')";
$results = mysql_query($insert);

$player = $_POST['4thb'];
$place = 'Top 4';
$points = 1 * $_POST['entries'];
$insert = "INSERT INTO 2006 (date, event, player, place, entries, points)
    VALUES ('$date', '$event', '$player', '$place', '$entries', '$points')";
$results = mysql_query($insert);
?>[/code]

Share this post


Link to post
Share on other sites
Try some debugging. For starters.. lets see if your query worked.
[code]
$results = mysql_query($insert) or die(mysql_error();
[/code]
Also.... youve got a hell of allot of redundant code in there. This could all be done in far fewer lines of code using loops.

Share this post


Link to post
Share on other sites
Receiving the following 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 'Blind Draw, David Hascup, 1st, 12, 60)' at line 2


[code]
<?php
$event = "Ringside Blind Draw";
$date = $_POST['date'];

$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("username_rankings");

$player = $_POST['1sta'];
$place = '1st';
$points = 5 * $_POST['entries'];
$insert = "INSERT INTO `2006` (`date`, `event`, `player`, `place`, `entries`, `points`)
    VALUES ($date, $event, $player, $place, $entries, $points)";
$results = mysql_query($insert) or die(mysql_error());
[/code]

Share this post


Link to post
Share on other sites
looks like you might have the quotations switched around in your INSERT query

try changing
[code]
$insert = "INSERT INTO `2006` (`date`, `event`, `player`, `place`, `entries`, `points`)
    VALUES ($date, $event, $player, $place, $entries, $points)";
[/code]

to
[code]
$insert = "INSERT INTO `2006` (date, event, player, place, entries, points)
    VALUES ('$date', '$event', '$player', '$place', '$entries', '$points')";
[/code]

Share this post


Link to post
Share on other sites

×

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.