deadendstreet
deadendstreet

Reputation: 111

PHP not posting information from database

I'm trying to post information from a database I created but it's not working.

I keep getting this 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 ''Content Calendar' ORDER BY Program' at line 1

I've googled and everything I show says that with a table with spaces (which I was stupid for naming it that btw) is using 'Content Calendar'. Is there another error that I'm not catching? Thanks for your help.

<?php
require_once("db_connx.php");
$result = mysql_query("SELECT * FROM 'Content Calendar' ORDER BY Program") or die($myQuery."<br/><br/>".mysql_error());
echo "<table border='1'>
<tr>
<th>Program</th>
<th>Air Date</th>
<th>Description</th>
<th>Production</th>
<th>Promotion</th>
<th>Web</th>
</tr>";
while($row = mysql_fetch_array($result)){ 
  echo "<tr>";
  echo "<td>" . $row['Program'] . "</td>";
  echo "<td>" . $row['Air Date'] . "</td>";
  echo "<td>" . $row['Description'] . "</td>";
  echo "<td>" . $row['Production'] . "</td>";
  echo "<td>" . $row['Promotion'] . "</td>";
  echo "<td>" . $row['Web'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
require_once("db_connx_close.php");
?>

Upvotes: 0

Views: 45

Answers (2)

Kim Oliveros
Kim Oliveros

Reputation: 711

I have 2 suggestions

1 is use backticks

$result = mysql_query("SELECT * FROM `Content Calendar` ORDER BY Program") or die($myQuery."<br/><br/>".mysql_error());

or 2 rename your table as Content_Calendar

$result = mysql_query("SELECT * FROM Content_Calendar ORDER BY Program") or die($myQuery."<br/><br/>".mysql_error());

Upvotes: 2

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

Your table should not be wrapped in quotes but with backticks since you have two words seperated by a space.

$result = mysql_query("SELECT * FROM `Content Calendar` ORDER BY Program") or die($myQuery."<br/><br/>".mysql_error());

Footnotes:

mysql_* functions deprecation notice:

http://www.php.net/manual/en/intro.mysql.php

This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.

These functions allow you to access MySQL database servers. More information about MySQL can be found at » http://www.mysql.com/.

Documentation for MySQL can be found at » http://dev.mysql.com/doc/.

Upvotes: 3

Related Questions