php - MySQL Syntax for Where clause -
im not in php. have web application displays data mysql database. not getting erros need fetch data want.
ex. code.
<?php $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); $token = $_get['token']; if(! $conn ) { die('could not connect: ' . mysql_error()); } $sql = "select * table token = '" . $token . "'"; mysql_select_db('database'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('could not data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, mysql_assoc)) { //displays data echo "the token here"; } mysql_close($conn); ?>
i have no errors in here. need like, if token data not yet added table, put echo message like.. "the token not yet added here". can put syntax here? please me. new in php.
use this:
if(mysql_num_rows($retval)) { while($row = mysql_fetch_array($retval, mysql_assoc)) { //displays data echo "the token here"; } } else { echo "the token not yet added here"; }
Comments
Post a Comment