php - Syntax error with a sql query -
below code, getting error
you have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 3
any appreciated.
<?php include("../includes/conn.php"); $sql = "select * `t_maincontent` uid_page =". $_get['page'] ; $results = mysql_query($sql, $conn) or die(mysql_error()); $content = mysql_fetch_assoc($results); //print $content['nv_content']."¬".$content['nv_title']."¬".$content['nv_meta']; ?>
please read basics on doing database queries php.
you should check whether $_get['page']
exists via isset( $_get['page'] );
send query if exists.
include( '../includes/conn.php' ); if( isset( $_get['page'] ) ) { /* cast int enough cancel sql injection attacks */ $sql = 'select * t_maincontent uid_page = ' . (int) $_get['page'] ; $results = mysql_query($sql, $conn) or die(mysql_error()); $content = mysql_fetch_assoc($results); }