trying to display database

Problems with the Windows version of XAMPP, questions, comments, and anything related.

trying to display database

Postby ckdoublenecks » 24. July 2010 18:11

I'm using Xampp, have created and populated a database "addtransdb" with a table "addtransinfo" and am trying to use the below program to display the table. It displayed when I created the table (generated by: phpmyadmin 3.2.4 / MYSQL 5.1.41 - SQL quert: SELECT * FROM 'addtransinfo' LIMIT 0,30 ; ) so I guess the problem is here in my program? I'm runnning win2000 prof,

<?php
$username="me";
$password="mine";
$database="addtransdb";
mysql_connect("localhost", "root", "");
@mysql_select_db($database) or die( "Unable to select database");
$query=" SELECT * FROM 'addtransinfo';
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<html><HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"><!-- this program is designed to show the database contents in a table
<META content="MSHTML 6.00.2800.1649" name=GENERATOR>
<META content="MSHTML 6.00.2800.1649" name=GENERATOR></HEAD>
<BODY><B><FONT size=+2>Project: Hammock Oaks In-house transfers & Add-ons</FONT>
<FORM>
<TABLE cellSpacing=0 cellPadding=0 border=1>
<TBODY>
<TR>
<TH>Appl</TH>
<TH>.</TH>
<TH>.</TH>
<TH>.</TH>
<TH>Race &amp;</TH>
<TH>Ethnic-</TH>
<TH>.</TH>
<TH>Displ.</TH>
<TH>Income</TH>
<TH>B/r s </TH>
<TH>Movein</TH>
<TH>Removal</TH>
<TH>.</TH>
<TH>.</TH>
<TR>
<TH>#</TH>
<TH>Date</TH>
<TH>Time</TH>
<TH>Name</TH>
<TH>Gender</TH>
<TH>City</TH>
<TH>LH %</TH>
<TH>Y/N</TH>
<TH>Level</TH>
<TH>Needed</TH>
<TH colSpan=2>Date</TH>
<TH>Code</TH>
<TH>Comments</TH></TR></TBODY></TABLE>
<?php
$i=0;
while ($i < $num) {
if ($num==0) {
echo "the database contains no contacts yet";
} else {

$appl=mysql_result($result,$i,"appl");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$name=mysql_result($result,$i,"name");
$racegend=mysql_result($result,$i,"racegend");
$ethnicity=mysql_result($result,$i,"ethnicity");
$laborhsg=mysql_result($result,$i,"laborhsg");
$displ=mysql_result($result,$i,"displ");
$incomelevel=mysql_result($result,$i,"incomelevel");
$brneeded=mysql_result($result,$i,"brneeded");
$moveindate=mysql_result($result,$i,"moveindate");
$removaldate=mysql_result($result,$i,"removaldate");
$code=mysql_result($result,$i,"code");
$comments=mysql_result($result,$i,"comments");
?>
<?php
<tr><TD><? echo $appl; ?></TD><TD><? echo $date; ?></TD><TD><? echo $time; ?></TD><TD><? echo $name; ?></TD><TD><? echo $racegend; ?></TD><TD><? echo $ethnicity; ?></TD><TD><? echo $laborhsg; ?></TD><TD><? echo $displ; ?></TD><TD><? echo $incomelevel; ?></TD><TD><? echo $brneeded; ?></TD><TD><? echo $moveindate; ?></TD><TD><? echo $removaldate; ?></TD><TD><? echo $code; ?></TD><TD><? echo $comments; ?></TD></TR>
<?php
$i++;
}
echo "</table>";
$i++;
}
?>
</B></FORM>
<P></P></BODY></HTML>
Last edited by ckdoublenecks on 24. July 2010 19:38, edited 1 time in total.
Double your music - double your fun
ckdoublenecks
 
Posts: 16
Joined: 11. July 2010 22:10
Location: Florida

Re: trying to display database

Postby Altrea » 24. July 2010 18:29

Do you use XAMPP 1.7.2 or 1.7.3?
If so, try the search for short_open_tags
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: trying to display database

Postby ckdoublenecks » 24. July 2010 20:17

It is 1.7.3 and my php.ini is set to short_open_tags=on
Double your music - double your fun
ckdoublenecks
 
Posts: 16
Joined: 11. July 2010 22:10
Location: Florida

Re: trying to display database

Postby Altrea » 24. July 2010 20:41

- Are your sure that the short_open_tags change takes effect? (check if the value is "On" in the phpinfo())

- Are you sure your database connection is established and your Querys takes effect? Maybe you should output errors with mysql_error(). Every mysql function can fail!
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: trying to display database

Postby ckdoublenecks » 24. July 2010 21:45

Altrea wrote:- Are your sure that the short_open_tags change takes effect? (check if the value is "On" in the phpinfo())

- Are you sure your database connection is established and your Querys takes effect? Maybe you should output errors with mysql_error(). Every mysql function can fail!



I set it on in php.ini. How do I "output errors with mysql_error()". No I am not sure if connection is established. That's why I asked if there is anything obvious re. my program. I got the coding from a manual. All I know is that my php is activated and running. I have placed the below program in c:/xampp/htdocs/the phptest program and the source code displayed:.

<html>
<head>
<title>PHP Test&amp;lt;/title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>

<body>
<h1>PHP Test</h1> &amp;lt;p>
<b>An Example of PHP in Action</b><br />
<?php echo "The Current Date and Time is: <br />";
echo date("g:i A l, F j Y.");?> &amp;lt;/p>
<h2>PHP Information</h2>
<p> <?php phpinfo(); ?> </p>
</body>
</html>
Double your music - double your fun
ckdoublenecks
 
Posts: 16
Joined: 11. July 2010 22:10
Location: Florida

Re: trying to display database

Postby Altrea » 24. July 2010 22:43

ckdoublenecks wrote:I set it on in php.ini.

Thats no answer on my question. You can change anything in the php.ini. But when you don't restart your Apache, changed the wrong php.ini file, or whatever else, the change don't take effect! Thats why i said take a look on the phpinfo() report. You can access it on the XAMPP Administration Site or just make your own php file with just this code

Code: Select all
<?php
phpinfo();
?>


ckdoublenecks wrote:How do I "output errors with mysql_error()". No I am not sure if connection is established. That's why I asked if there is anything obvious re. my program. I got the coding from a manual.

PHP does have a really good documentation. Take a look at the mysql_connect() explaination. There you can find a basic usage of database connection with mysql_error usage.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: trying to display database

Postby ckdoublenecks » 25. July 2010 00:51

My program is more detailed than yours but I got it to work and obviously PHP is working.. The only thing that stood out was the below although I don't know if it is important.


Configuration File (php.ini) Path : no value
Double your music - double your fun
ckdoublenecks
 
Posts: 16
Joined: 11. July 2010 22:10
Location: Florida

Re: trying to display database

Postby Altrea » 25. July 2010 01:10

The more important line is "Loaded Configuration File".
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: trying to display database

Postby ckdoublenecks » 25. July 2010 02:23

Thanks fellows, I made the changes as were suggested but of course the only one that could have made any difference was adding <table> in the PHP table: I still get an error at the "<tr>" in the PHP table (line 76). I can't resist responding to the remark by a Whole that I need to learn HTML. A couple of my websites http://www.ckdoublenecks.com and http://www.kirkwebsites.com have been running for years. I'm new to databases & php and just need some guidance.

<?php
$username="root";
$password="";
$database="addtransdb";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM addtransinfo";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
<HTML<BODY><B><FONT size=+2>Project: Hammock Oaks In-house transfers & Add-ons</FONT>
<FORM>
<TABLE cellSpacing=0 cellPadding=0 border=1>
<TBODY>
<TR>
<TH>Appl</TH>
<TH>.</TH>
<TH>.</TH>
<TH>.</TH>
<TH>Race &amp;</TH>
<TH>Ethnic-</TH>
<TH>.</TH>
<TH>Displ.</TH>
<TH>Income</TH>
<TH>B/r s </TH>
<TH>Movein</TH>
<TH>Removal</TH>
<TH>.</TH>
<TH>.</TH>
</tr><tr>
<TH>#</TH>
<TH>Date</TH>
<TH>Time</TH>
<TH>Name</TH>
<TH>Gender</TH>
<TH>City</TH>
<TH>LH %</TH>
<TH>Y/N</TH>
<TH>Level</TH>
<TH>Needed</TH>
<TH colSpan=2>Date</TH>
<TH>Code</TH>
<TH>Comments</TH></TR>
</TBODY></TABLE>
<?
$i=0;
while ($i < $num) {
if ($num==0) {
echo "the database contains no contacts yet";
} else {

$appl=mysql_result($result,$i,"appl");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$name=mysql_result($result,$i,"name");
$racegend=mysql_result($result,$i,"racegend");
$ethnicity=mysql_result($result,$i,"ethnicity");
$laborhsg=mysql_result($result,$i,"laborhsg");
$displ=mysql_result($result,$i,"displ");
$incomelevel=mysql_result($result,$i,"incomelevel");
$brneeded=mysql_result($result,$i,"brneeded");
$moveindate=mysql_result($result,$i,"moveindate");
$removaldate=mysql_result($result,$i,"removaldate");
$code=mysql_result($result,$i,"code");
$comments=mysql_result($result,$i,"comments");

<table>
<tr>
<TD><? echo $appl; ?></TD>
<TD><? echo $date; ?></TD>
<TD><? echo $time; ?></TD>
<TD><? echo $name; ?></TD>
<TD><? echo $racegend; ?></TD>
<TD><? echo $ethnicity; ?></TD>
<TD><? echo $laborhsg; ?></TD>
<TD><? echo $displ; ?></TD>
<TD><? echo $incomelevel; ?></TD>
<TD><? echo $brneeded; ?></TD>
<TD><? echo $moveindate; ?></TD>
<TD><? echo $removaldate; ?></TD>
<TD><? echo $code; ?></TD><TD>
<? echo $comments; ?></TD>
</TR>

$i++;
}

echo "</table>";

$i++;
}

?>
</B></FORM>
<P></P></BODY></HTML
Last edited by ckdoublenecks on 25. July 2010 16:53, edited 2 times in total.
Double your music - double your fun
ckdoublenecks
 
Posts: 16
Joined: 11. July 2010 22:10
Location: Florida


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 104 guests