• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

there is something wrong in my code and wont display the database properly

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

raident30

Member
Joined
Sep 8, 2011
Location
Las Pinas, Philippines
hi guys!
there is something wrong in my codes and i don't know what since i am still learning php

here is the first one (saved as configdb.php)
Code:
<?php
$hostname ="localhost";
$username ="root";
$password ="";
$db ="studinfodb";
mysql_connect($hostname,$username,$password) or die("cannot connect to server");
mysql_select_db($db) or die("database not found!");
?>

and here is the second one (saved as index.php)
Code:
<?
include "configdb.php";
$sql = "select * from tblstudinfo";
$result = mysql_query($sql) or die ("cannot execute query!");
while($row=mysql_fetch_array($result))
	{
		echo "Student No. : " . $row[0]."<br>";
		echo "Last Name   : " . $row[1]."<br>";
		echo "First Name  : " . $row[2]."<br>";
		echo "Course      : " . $row[3]."<br>";
		echo "<br>";
			}
?>

all of my other sql are functioning good like add and delete... its just that the index.php doesn't display the database properly and i am getting something like this:

Untitled_zpsf942bd9f.png
 
Try using an opening PHP tag, like <?php on your index page (instead of <?), and see if that makes a difference.
 
It's not your eyes as such, its the set up of the web-server, some will take your original input, where are others won't dependant on setup.

Although for clarity and ease of reading it is recommended to use <?php instead :)
 
It's not your eyes as such, its the set up of the web-server, some will take your original input, where are others won't dependant on setup.

Although for clarity and ease of reading it is recommended to use <?php instead :)

alright! thanks man! that's a great help for a newbie like me!:thup:
 
Back