Jump to content

Recommended Posts

Where am I going wrong here???

 

I am receiving 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 'div='g910'' at line 1

 

From this code:

// mySQL Table
    $db_con = mysql_connect(***, ***, ***) or die("Connetion to database failed!");
    mysql_select_db(***);
$div = $_GET['div'];
$sql = "SELECT div, division, gameid, date, time, home, h_score, visitor, v_score, field, field_no FROM s2007schedules WHERE div='$div'";
$result = mysql_query($sql) or die(mysql_error());
$i = 0;

    echo "<font face='Arial' size='4' color='#000000'><b>Spring 2007 Schedules & Scores for $div:</b></font><p style='margin-top: 0'>
<font face='Arial' size='3'>To report game results, <u>
<font color='#0000ff'><a href='http://www.******.***/viewpage.php?page_id=32'>
<font color='#0000cc'>click here<br></font></a></font></u></font><br><br>\n\n";

echo "<table width='100%' border='1' cellspacing='0' cellpadding='5' bordercolorlight='#000000' bordercolordark='#000000'><tr>
         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#FF0000' bordercolordark='#000000' width='15%'>
		<font face='Arial' color='#FFFFFF'>Date</font></th>
         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#FF0000' bordercolordark='#000000' width='10%'>
		<font face='Arial' color='#FFFFFF'>Game ID</font></th>
         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#FF0000' bordercolordark='#000000' width='50%'>
		<font face='Arial' color='#FFFFFF'>Teams</font></th>
         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#FF0000' bordercolordark='#000000' width='5%'>
		<font face='Arial' color='#FFFFFF'>Scores</font></th>
         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#FF0000' bordercolordark='#000000' width='20%'>
		<font face='Arial' color='#FFFFFF'>Details</font></th>
         </tr>";
         
    while ($row = mysql_fetch_array($result)) {
    echo "<tr>
    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#FF0000' bordercolordark='#000000' width='15%'>
    <table border='0' width='100%' id='table1' cellspacing='0' cellpadding='0'>
	<tr>
		<td><font face='Arial' size='2'>" . $row['Date'] . "</font></td>
	</tr>
</table>
</td>
    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#FF0000' bordercolordark='#000000' width='10%'>
    <table border='0' width='100%' id='table2' cellspacing='0' cellpadding='0'>
	<tr>
		<td><font face='Arial' size='2'>" . $row['gameid'] . "</font></td>
	</tr>
	<tr>
		<td>
		<p align='right'><font face='Arial' size='2' color='#FF0000'>@</font></td>
	</tr>
</table>
</td>
    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#FF0000' bordercolordark='#000000' width='50%'>
    <table border='0' width='100%' id='table3' cellspacing='0' cellpadding='0'>
	<tr>
		<td><font face='Arial' size='2'>" . $row['visitor'] . "</font></td>
	</tr>
	<tr>
		<td><font face='Arial' size='2'>" . $row['home'] . "</font></td>
	</tr>
</table>
</td>
    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#FF0000' bordercolordark='#000000' width='5%'>
    <table border='0' width='100%' id='table4' cellspacing='0' cellpadding='0'>
	<tr>
		<td><font face='Arial' size='2'>" . $row['h_score'] . "</font></td>
	</tr>
	<tr>
		<td><font face='Arial' size='2'>" . $row['v_score'] . "</font></td>
	</tr>
</table>
</td>
    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#FF0000' bordercolordark='#000000' width='20%'>
    <table border='0' width='100%' id='table5' cellspacing='0' cellpadding='0'>
	<tr>
		<td><font face='Arial' size='2'>" . $row['time'] . "</font></td>
	</tr>
	<tr>
		<td><font face='Arial' size='2'>" . $row['field'] . " " . $row['field_no'] . "</font></td>
	</tr>
</table>
</td>
    </tr>";
    }
echo "</table>\n";

  // mySQL ends

 

Assistance is greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/42030-solved-error-in-my-sql-syntax/
Share on other sites

<?php
    mysql_select_db(***);
$div = mysql_real_escape_string($_GET['div']);
$sql = "SELECT div, division, gameid, date, time, home, h_score, visitor, v_score, field, field_no FROM s2007schedules WHERE div='$div'";
$result = mysql_query($sql) or die(mysql_error());
$i = 0;
?>

 

See where that gets ya. What is throwing you off are the single quotes in the $div portion.

 

--FrosT

I have checked all of the quotes and yet I am still getting:

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 'div, division, gameid, date, time, home, h_score, visitor, v_score, field, field' at line 1

hmm maybe try this:

 

$sql = "SELECT `div`, `division`, `gameid`, `date`, `time`, `home`, `h_score`, `visitor`, `v_score`, `field`, `field_no` FROM `s2007schedules` WHERE div='$div'";

 

If that does not work, what version of MySQL are you using?

 

--FrosT

CREATE TABLE `s2007schedules` (
  `div` text NOT NULL,
  `division` text NOT NULL,
  `gameid` text NOT NULL,
  `date` text NOT NULL,
  `time` text NOT NULL,
  `home` text NOT NULL,
  `h_score` text NOT NULL,
  `visitor` text NOT NULL,
  `v_score` text NOT NULL,
  `field` text NOT NULL,
  `field_no` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- 
-- Dumping data for table `s2007schedules`
-- 

INSERT INTO `s2007schedules` VALUES ('g910', 'Girls U-9/10 Blue', '071231', 'Saturday, April 17, 2007', '12:00 pm', 'Test Team 2', '8', 'Test Team 45644', '0', 'Test Field', '45');

 

And, I am sure my structure is awful.  this is not my final database, obviously.  I am preparing for final version for two weeks from now.

$sql = "SELECT `div`, `division`, `gameid`, `date`, `time`, `home`, `h_score`, `visitor`, `v_score`, `field`, `field_no` FROM `s2007schedules` WHERE div='$div';";

 

Maybe the semi-colon at the end is required? Have you been able to pull any data at all? If so what query did you use?

 

--FrosT

Adding that gave me:

Parse error: syntax error, unexpected T_STRING in /home/kemper/public_html/****/scores.php on line 26

 

I have been unable to pull any data.

 

I have pulled from another script and I was modified this from.

 

My original and working script is:

// mySQL Table

    $db_con = mysql_connect(***, ***, ***) or die("Connetion to database failed!");

    mysql_select_db(******);

$age = $_GET['age'];

$sql = "SELECT age, division, team, coach, ctelephone, cemail, manager, mtelephone, memail FROM s2007_contacts WHERE age='$age'";

$result = mysql_query($sql) or die(mysql_error());

$i = 0;

 

    echo "<font face='Arial' size='4' color='#000000'><b>Team contacts for all divisions of $age:</b></font><p style='margin-top: 0'>

<font face='Arial' size='3'>To update your team's contact listing,

<font color='#0000ff'><a href='http://www.***.***/viewpage.php?page_id=43'>

<font color='#0000cc'>click here<br></font></a></font></font><br><br>\n\n";

 

echo "</p>

<table width='100%' border='1' cellspacing='0' cellpadding='5' bordercolorlight='#000000' bordercolordark='#000000'><tr>

         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#ff0000' bordercolordark='#000000'><font face='Arial' color='#FFFFFF'>Age</font></th>

         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#ff0000' bordercolordark='#000000'><font face='Arial' color='#FFFFFF'>Division</font></th>

         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#ff0000' bordercolordark='#000000'><font face='Arial' color='#FFFFFF'>Team</font></th>

         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#ff0000' bordercolordark='#000000'><font face='Arial' color='#FFFFFF'>Manager</font></th>

         <th align='left' bgcolor='#FF0000' style='border-style: solid; border-width: 1px' bordercolor='#000000' bordercolorlight='#ff0000' bordercolordark='#000000'><font face='Arial' color='#FFFFFF'>Coach</font></th>

         </tr>";

         

    while ($row = mysql_fetch_array($result)) {

    echo "<tr>

    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#ff0000' bordercolordark='#000000'>

    <p style='margin-top: 0; margin-bottom: 0'><font face='Arial' size='2'>" . $row['age'] . "</font><p style='margin-top: 0; margin-bottom: 0'>

    <font face='Arial' size='2'> </font><p style='margin-top: 0; margin-bottom: 0'>

    <font face='Arial' size='2'> </font></td>

    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#ff0000' bordercolordark='#000000'>

    <p style='margin-top: 0; margin-bottom: 0'><font face='Arial' size='2'>" . $row['division'] . "</font></td>

    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#ff0000' bordercolordark='#000000'>

    <p style='margin-top: 0; margin-bottom: 0'><font face='Arial' size='2'>" . $row['team'] . "</font></td>

    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#ff0000' bordercolordark='#000000'>

    <p style='margin-top: 0; margin-bottom: 0'><font face='Arial' size='2'>" . $row['manager'] . "</font></p>

    <p style='margin-top: 0; margin-bottom: 0'><font face='Arial' size='2'>" . $row['mtelephone'] . "</font></p>

    <p style='margin-top: 0; margin-bottom: 0'><font face='Arial' size='2'>" . $row['memail'] . "</font></td>

    <td valign='top' style='border-style: solid; border-width: 1px' bordercolor='#ff0000' bordercolorlight='#ff0000' bordercolordark='#000000'>

    <p style='margin-top: 0; margin-bottom: 0'><font face='Arial' size='2'>" . $row['coach'] . "</font></p>

    <p style='margin-top: 0; margin-bottom: 0'><font face='Arial' size='2'>" . $row['ctelephone'] . "</font></p>

    <p style='margin-top: 0; margin-bottom: 0'><font face='Arial' size='2'>" . $row['cemail'] . "</font></td>

    </tr>";

    }

echo "</table>\n";

 

  // mySQL ends

 

Even if I pull my echo tables, I still get that original error.  I am so lost.

Maybe "div" is a special word in MySQL? I would check your column names and make sure that they do not also dub as a special word in mysql. IE: Sum for a column name would throw an error because sum(column) is a function in MySQL.

 

--FrosT

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.