FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Strange SQL error





welshsteve
Hi everyone. I'm building a mobile version of a website that I manage and have come across an error.

The page in question is here - http://www.ldbsa.co.uk/mobile/s_res_prem.php

It gives a SQL syntax error. But if you choose week 1 (only week I've done so far) and click the button, all works fine. Can anybody explain?

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LDBSA Mobile Website</title>

<!-- SCRIPT FOR SHOWING OR HIDING FRAMES SCORES -->
<script type="text/javascript">
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
</script>
<!-- END SCRIPT -->
</head>
<body>
<div style="text-align:center;">
   <img src="../images/ldbsa_logo.jpg" style="width:90px;width:80px;">
   <h1 style="font:bold 12pt arial;text-decoration:underline;">Snooker Fixtures/Results - Premier Division</h1>
      <form method="post" action="s_res_prem.php">
         <span style="font:10pt verdana;">Select a week:</span>
         <select name="week" id="week">
            <option> Please select a week...</option>
            <option value="1"> Week 1 - 4 September</option>
            <option value="2"> Week 2 - 11 September</option>
            <option value="3"> Week 3 - 18 September</option>
            <option value="4"> Week 4 - 25 September</option>
            <option value="5"> Week 5 - 2 October</option>
            <option value="6"> Week 6 - 9 October</option>
            <option value="7"> Week 7 - 16 October</option>
            <option value="8"> Week 8 - 23 October</option>
            <option value="9"> Week 9 - 30 October</option>
            <option value="10"> Week 10 - 6 November</option>
            <option value="11"> Week 11 - 13 November</option>
            <option value="12"> Week 12 - 20 November</option>
            <option value="13"> Week 13 - 27 November</option>
            <option value="14"> Week 14 - 4 December</option>
            <option value="15"> Week 15 - 11 December</option>
            <option value="16"> Week 16 - 18 December</option>
            <option value="17"> Week 17 - 8 January</option>
            <option value="18"> Week 18 - 22 January</option>
            <option value="19"> Week 19 - 29 January</option>
            <option value="20"> Week 20 - 12 February</option>
            <option value="21"> Week 21 - 19 February </option>
            <option value="22"> Week 22 - 26 February</option>
            <option value="23"> Week 23 - 12 March</option>
            <option value="24"> Week 24 - 19 March</option>
            <option value="25"> Week 25 - 2 April</option>
            <option value="26"> Week 26 - 16 April</option>
            <option value="27"> Week 27 - 23 April</option>
            <option value="28"> Week 28 - 30 April</option>
            <option value="29"> Week 29 - 7 May</option>
            <option value="30"> Week 30 - 21 May</option>
         </select>
         <input type="submit" name="btnSubmit" id="btnSubmit" class="btn" value="View Fixtures" />
            </form>
<!-- START PHP -->
<?php
$week = $_REQUEST['week'] ;
$con = mysql_connect("HOSTADDRESS","USERNAME","PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error();
  }

mysql_select_db("DBNAME", $con);

$sql = "SELECT * FROM Fixtures WHERE Week =".$week. ";";
$result = mysql_query($sql);
if (!$result)
//CHANGED THIS BIT
//echo mysql_error();
echo "No week selected";

echo "<h2>Week " .$week. "</h2>
<table style='font:10pt verdana;border:0;text-align:left;margin-left:auto;margin-right:auto;width:400px;'>";
      
while($row = mysql_fetch_array($result))
  {
      echo "<tr>";
      echo "<td>". $row['Home']. "</td><td>" .$row['HScore']. "</td><td>-</td><td>" .$row['AScore']. "</td><td>" .$row['Away']. "</td>";
      echo "</tr>";               
  }
echo "</table>";
mysql_close($con);
?>
<!-- END PHP -->
   <p>&nbsp;</p>
   <p style="font:10pt verdana;"><a href="main.html">Back To Main Menu</a></p>
   <img src="../images/wbc_logo.gif" style="width:221px;width:112px;">
</div>
</body>
</html>



EDIT: I've sorted this myself. I was telling it to show a sql error, instead I am now telling it to say "No Week Selected". Commented out what I have changed.
DjMilez
Lol, reminds me of the silly mistakes I've made in coding, mostly gta3 scripting.
Related topics
Help: SQL error after uploading new files(thread updated)
Forum error when posting
Error Posting...
Frihost Forum Error (30/08/2005)
Sql Error: 1017. Missing all the indexes files of phpbb
SQL error notification in my forum
SQL error
SQL error on my site
[man] SQL Error : 1054 Unknown column \'session_admin\ en DB
SQL error
SQL ERROR [ mysql4 ] - due to hosting? -
SQL error
[SQL] Error in SQL Code
SQL ERROR [ mysqli ]
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.