Jump to content


Photo

Loading SQL Problem


  • Please log in to reply
3 replies to this topic

#1 OCHE1976

OCHE1976
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 April 2006 - 03:36 PM

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
<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>

and here is the PHP 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);
?>


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 03 April 2006 - 03:43 PM

Try some debugging. For starters.. lets see if your query worked.
$results = mysql_query($insert) or die(mysql_error();
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.

#3 OCHE1976

OCHE1976
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 April 2006 - 03:54 PM

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


<?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());


#4 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 04 April 2006 - 02:12 AM

looks like you might have the quotations switched around in your INSERT query

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

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

got a problem? Google helps many of those in need




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users