Jump to content

Having problem with a include connection string


arcset

Recommended Posts

I am having a problem with the following code. It will not show the post from the mysql database. I havent had this problem before when i have done this so maybe my tired eyes are missing a mistake in the code.

 

 

CS.php (Connection String)

<?php
$host="000.000.000.000"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="database"; // Database name  

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

?>

 

test.php (page i want to display contents of mysql query)

<?php
include("CS.php");
$sql = "SELECT post FROM indexphp WHERE locate = '1'";//I belive its right did the query in phpMyAdmin and it returned the results
$rows = mysql_query($sql);//run the query
$row = 0; 
   while($row < mysql_num_rows($rows)) { //grab the rows from the sql array
         $post = mysql_result($rows, $row, 0);
          echo = $post;
          $row = $row + 1;
            }      
?>

 

 

Are you getting any errors at all?

 

Try this

 

<?php
include("CS.php");
$sql = "SELECT post FROM indexphp WHERE locate = '1'";//I belive its right did the query in phpMyAdmin and it returned the results
if ( ($result = mysql_query($sql)) === FALSE )
    exit( 'Error with query syntax' );
if ( mysql_num_rows($result) < 1 )
    exit( 'Now rows found!' );
while( $row = mysql_fetch_assoc($result) )
    echo $row['post'];
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.