MySQL syntax issue with PHP -


i seem getting following error when running below code. i'm not sure why though works fine on localhost, not live :(

there error running query error02 [you have error in sql syntax; check manual corresponds mysql server version right syntax use near ')' @ line 3]

here script i'm running. seems having issue ($id)

function display_article() { $db = new mysqli('localhost', 'user', 'pass', 'database');  if($db->connect_errno > 0){     die('unable connect database [' . $db->connect_error . ']'); }  $id = mysql_real_escape_string($_get['id']); $sql = <<<sql     select *     `article_img`     `img_id` = ($id) sql;  if(!$result = $db->query($sql)){     die('there error running query error02 [' . $db->error . ']'); } while($row = $result->fetch_assoc()){     echo '<div class="article_title">';     echo '<h2>' . $row['title'] . '</h2>';         echo '<div class="article_date">';           echo 'posted ' . $row['date']. '';          echo '</div>';     echo '</div>';      echo '<div class="article_image">';     echo '<img src="'.$row['img_1'].'" alt="" width="584" height="368"/>';     echo '</div>';      echo '<div class="article_description">';     echo '<p>' . $row['description'] . '</p>';     echo '</div>';      echo '<br /><br />';     echo '<div class="article_image">';     echo '<img src="'.$row['img_2'].'" alt="" width="584" height="368"/>';      echo '</div>';     echo '<br /><br />';     echo '<div class="article_image">';     echo '<img src="'.$row['img_3'].'" alt="" width="584" height="368"/>';      echo '</div>';     echo '<br /><br />';     echo '<div class="article_image">';     echo '<img src="'.$row['img_4'].'" alt="" width="584" height="368"/>';      echo '</div>';     echo '<br /><br />';     echo '<div class="article_image">';     echo '<img src="'.$row['img_5'].'" alt="" width="584" height="368"/>';      echo '</div><br />';  }  $id_related = mysql_real_escape_string($_get['make']); $sql_related = <<<sql     select *     `article_img`     `make` != '$id_related' order rand() desc limit 2  sql;  if(!$result = $db->query($sql_related)){     die('there error running query error03[' . $db->error . ']'); } while($row = $result->fetch_assoc()){ echo '<a class="article_related_link" href="/article.php?id='.$row['img_id'].'&make='.$row['make'].'">';     echo '<div class="article_related">';             echo '<img src="' . $row['img_url'] . '" width="282" height="174"/>';     echo '</div>'; echo '</a>';    } echo '<div class="article_footer">';  echo '</div>';  // free result set mysqli_free_result($result);  mysqli_close($db); } 

$id won't evaluated in heredoc block.

change code have evaluated:

$id = (int) $_get['id']; $sql = "     select *     `article_img`     `img_id` = ($id) "; 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -