您的代码中有一些疏忽或问题。包括无缘无故地重复自己,以及在你进步的过程中未能测试你的变量/行动。
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbbase = 'dynamic';
// WAS
// $con = mysql_connect("localhost","elemental","");
// why have your variables above if you hardcode them?
if( !( $con = mysql_connect( $dbhost , $dbuser , $dbpass ) ) ){
error_log( 'MySQL Server Connection Failed - '.mysql_error() );
// Never echo your errors publicly
die( 'Cannot connect to database, but I am not going to show you why publicly.' );
}
if( !mysql_select_db( $dbbase ) ){
error_log( 'MySQL Database Connection Failed - '.mysql_error() );
// Never echo your errors publicly
die( 'Cannot connect to database, but I am not going to show you why publicly.' );
}
include( 'test2.php' );
// WAS
// $query="selelct * from data";
// check your spelling!
$query = 'SELECT * FROM data';
if( !( $result = mysql_query( $query ) ) ){
error_log( 'MySQL Query Failed - '.mysql_error() );
die( 'Cannot query the database, but I am not going to show you why publicly.' );
}
if( !mysql_num_rows( $result ) ){
echo 'No Records Found';
}else{
while( $d = mysql_fetch_array( $result ) ){
echo '<h3>'.$d['id'].'</h3><h3>'.$d['name'].'</h3>';
}
}