PHP & mySQL Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bcyork
Forum Newbie
Posts: 8
Joined: Wed Sep 17, 2008 11:42 am

PHP & mySQL Query

Post by bcyork »

$content = mysql_query("SELECT * FROM 'content' WHERE 'purl' = "$purl"", $DBCNX);

I am getting this error for the above line. Parse error: syntax error, unexpected T_VARIABLE

I have been trying to figure it out and can't any ideas? I'm new a this.

I can post more if it will help
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP & mySQL Query

Post by VladSun »

Column/table names in MySQL are surrounded with the ` symbol, not like the MS SQL - the ' symbol.
Also string concatenation is done this way:

Code: Select all

$string2 = "You are looking at " . $string1 . " - the first string value concatenated"
There are 10 types of people in this world, those who understand binary and those who don't
bcyork
Forum Newbie
Posts: 8
Joined: Wed Sep 17, 2008 11:42 am

Re: PHP & mySQL Query

Post by bcyork »

It seems like everyone has a different syntax. Some people say to put periods before variables ... does that do anything besides cause more errors. Some of the simplest things there are about 5 different ways people write it varying ) ' . " ] all in different places. (I'm speaking of people not on this forum)

So the above post helped get rid of the errors but I still can't get anything to show up from the data base.

Is their any issues with any of this?

Code: Select all

<?php require_once("cnx.php");  
    mysql_select_db("DBname", $DBCNX);
    $content = mysql_query("SELECT * FROM 'content' WHERE 'purl' = '$purl'", $DBCNX);
    mysql_close($DBCNX); 
?>
<title>
    <?php if ($purl == "index")     {
            echo $content[title]; echo "Static Title Home Page."; 
        } else { 
            echo $content[title]; echo "Static Title";  
        }
    ?>
</title>
cnx.php

Code: Select all

<?php 
$DB_HOST = 'localhost';
$DB_USER = 'hpread'; 
$DB_PW = 'sdfsdfsdfsdf';  
$DBCNX = mysql_connect($DB_HOST, $DB_USER, $DB_PW);
if (!$DBCNX)
{
die('Could not connect: ' . mysql_error());
}
?>
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP & mySQL Query

Post by VladSun »

VladSun wrote:Column/table names in MySQL are surrounded with the ` symbol, not like the MS SQL - the ' symbol.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply