The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - General (http://hintsforums.macworld.com/forumdisplay.php?f=16)
-   -   Proper path for PHP? (http://hintsforums.macworld.com/showthread.php?t=30960)

fvs 11-29-2004 04:56 PM

Hi Ezra, I followed you exactly and it still wont open web page, Here it is, I'm missing something? Your very clear and I do understand the code now that you've explained it to me.

<html>
<body>
<table width='450'>
<?php
$dbconnect = mysql_connect('localhost','','');
mysql_select_db('work_2004');
$query="SELECT * FROM current_cus";

$result = mysql_query($query, $dbconnect) or die(mysql_error());
while($row = mysql_fetch_assoc($result));
{
echo "<tr>";
echo
"<td>$row[id]</td><td>$row[Customers_name]</td><td>$row[First_name]</td><td>$row[Last_name]</td><td>$row[address]</td><td>$row[city]</td><td>$row[state]</td><td>$row[zip]</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>

ezmobius 11-29-2004 05:56 PM

So it just loads an empty page? What happens when you view the source on that empty page?
Lets try to break it down and find out where the error is. Add something like this after every line of code so we can see where it makes it to.

PHP Code:

<html>
<body>
<table width='450'>
<?php
$dbconnect 
mysql_connect('localhost','','');
echo 
'made it here 1';
mysql_select_db('work_2004');
echo 
'made it here 2';
$query="SELECT * FROM current_cus";
echo 
'made it here 3';
$result mysql_query($query$dbconnect) or die(mysql_error());
echo 
'made it here 4';
while(
$row mysql_fetch_assoc($result));
{
echo 
"<tr>";
echo 
'made it here 5';
echo
"<td>$row[id]</td><td>$row[Customers_name]</td><td>$row[First_name]</td><td>$row[Last_name]</td><td>$row[address]</td><td>$row[city]</td><td>$row[state]</td><td>$row[zip]</td>";
echo 
'made it here 6';
echo 
"</tr>";
echo 
'made it here 7';
}
?>
</table>
</body>
</html>

Try that out and see where you make it to. Also make sure that the permissions are set correctly on your script. for now just do this in the terminal:
chmod 777 scriptname.php
If none of these things work lets try something else. get yourself a terminal window and do the following command:
mysqldump -u root -p work_2004 >> sqldump.txt
It will ask for your password and then exit. You will then be the proud owner of a backup of you work_2004 database. Post here again and attach the sqldump.txt text file so that I can load it in my database and run the script to see if it works on my end or not. If you don't want to post it up here then just email it to me at ez@yakima-herald.com
I can't think of much else that could be wrong here without being able to try it out myself, so send me the mysqldump and we'll get this puppy running for you!

fvs 11-29-2004 07:14 PM

Ezra that worked; What did I do wrong on other code? Where am I entering the wrong things to get mysql db into the web page?

made it here 1made it here 2made it here 3made it here 4made it here 5made it here 6made it here 7

Ezra, I also tried to enter mysqldump, check it out;

on:fvs % mysqldump -u fvs -p work_2004 >> sqldump.txt
Enter password:
Mon:fvs % mysql -u fvs -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 57 to server version: 4.0.15

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+-----------+
| Database |
+-----------+
| duckwear |
| mysql |
| sample |
| test |
| work_2004 |
+-----------+
5 rows in set (0.01 sec)

mysql>

ezmobius 11-29-2004 07:29 PM

So all that showed up on the web page was the made it here 1-7 ? Is there data in your database? It seems that if it is making it through all of the echoes then the only thing I can think of is that it is not SELECTing anything in the query. Open up your terminal and login to mysql with this line:
mysql -u root -p
Use root unless you are using a different username in your script. After it opens do this command:
SELECT * FROM current_cus;
Do you get a results table? If you do then I can't fiigure oput what the heck is going wrong. The only way I can go any further is to try it out on my end. So send me a mysqldump file of the database so I can see whats going wrong. Short of that, if we can't get it working then I will make a small test db and send you a mysqldump[ file of it and a script that works to make a web page of all the data in the db and have you load the data into your install of mysql and run the php script to see if it works the same on your end as it does on my end.

ezmobius 11-29-2004 07:36 PM

I didn't read your whole post before I replied. It looks like your mysqldump worked fine. Its not supposed to go into mysql mode, it just dumps a text file and then exits back to your normal command line. So there should now be a file called sqldump.txt in your home folder or whatever your current working directory was when you ran the mysqldump command. If you can send me that file I will be able to find out once and for all what the heck is going on...

fvs 11-30-2004 06:39 AM

Hello Ezra,
Here it is;

-- MySQL dump 9.10
--
-- Host: localhost Database: work_2004
-- ------------------------------------------------------
-- Server version 4.0.15

--
-- Table structure for table `current_cus`
--

CREATE TABLE current_cus (
id int(11) NOT NULL auto_increment,
Customers_Name char(35) default NULL,
First_name char(15) default NULL,
Last_Name char(20) default NULL,
Address char(30) default NULL,
City char(18) default NULL,
State char(5) default NULL,
Date date default NULL,
zip int(8) default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;

--
-- Dumping data for table `current_cus`
"sqldump.txt" 30L, 821C

mysql> use work_2004;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from current_cus;
+----+-----------------+------------+-----------+----------------+------------+-------+------------+-------+
| id | Customers_Name | First_name | Last_Name | Address | City | State | Date | zip |
+----+-----------------+------------+-----------+----------------+------------+-------+------------+-------+
| 3 | Koch Tom | Tom | Koch | 128 Belview Rd | Philpsburg | NJ | 2004-11-20 | 8865 |
| 4 | Dallinger Frank | Frank | Dallinger | NULL | Palmer | Pa | NULL | 18045 |
+----+-----------------+------------+-----------+----------------+------------+-------+------------+-------+
2 rows in set (0.00 sec)

Sorry if I can't get back as soon as I like, I have to go in and out freqently, Thanks again. fvs

JayBee 11-30-2004 07:01 AM

Just a quickie - have you tried removing the ";" from the end of the "while" line in your code?

fvs 11-30-2004 10:13 AM

Hi Jay, I just removed ";" from the while line, It showed me only the [id] [First_name]
[zip] and nothing else? As you can see I have other columns that have more data that don't show? Thanks for helping. fvs

ezmobius 11-30-2004 12:24 PM

Hehe- Jay was right... Man sometimes it's the smallest things that get overlooked. And since I wasn't running the code on my end, just posting it I never noticed the ; after my while loop. So after much bumbling about here it is: And the reason why some of your fields were not displaying fvs is because mysql is case sensitive. So some of your fields were like Last_Name and you were calling them like this: Last_name so heres the final script... it works just fill in your name and pass.
PHP Code:

<html> 
<body> 
<table width='450' border='1'> 
<?php 
$dbconnect 
mysql_connect('localhost','root','reversal'); 
mysql_select_db('work_2004'); 
$query="SELECT * FROM `current_cus`"
$result mysql_query($query$dbconnect) or die(mysql_error());
while(
$row mysql_fetch_assoc($result))

echo 
"<tr>"
echo 
"<td>$row[id]</td><td>$row[Customers_Name]</td><td>$row[First_name]</td><td>$row[Last_Name]</td><td>$row[Address]</td><td>$row[City]</td><td>$row[State]</td><td>$row[Date]</td><td>$row[Zip]</td>";  
echo 
"</tr>"

?> 
</table> 
</body> 
</html>


fvs 11-30-2004 04:14 PM

Hello Ezra, That worked GREAT! and I want to THANK YOU very much for all your patience and tolerence, I'm on my way to getting started on the right foot, I'll practice practice and practice, Thanks once more. fvs

ezmobius 11-30-2004 04:24 PM

Hey your very welcome-
I've been helped out a lot by people on this and other forums in the past so I'm just giving back. Good luck, php is a great loanguage to learn programming concepts with especially if you are already a web designer. Just stick with it and you'll go far.

fvs 12-02-2004 07:37 AM

Ezra, I downloaded phpMyAdmin-2.2.7 and I thought it would help, but I don't know where to start, I got this message on my web page;

The $cfgPmaAbsoluteUri directive MUST be set in your configuration file!

Can this phpMyAdmin help me?

ezmobius 12-02-2004 11:15 AM

Yes, PHPmyAdmin is awesome. I don't recall having any trouble installing it myself. So maybe you need to start over and install it again. Do you have any instructions? If you stilll have trouble installing phpmyadmin then you should get a free program called yourSQL, google for it. I think you can get it at sourceforge or something. Anyway let me know if you need more help with phpmyadmin. I use it EVERY day myself. It's an indespensable tool if you use mysql. But yoursql works good too.

JayBee 12-02-2004 11:47 AM

Heh - I feel like a NINJA now :) Glad I could help!

btw, if you're looking for a quick bit of code to debug mysql connections, instead of doing the table rendering thing, just try this with your result set

Code:

while ( $row = mysql_fetch_assoc($result) ) {
    print_r($row);
}

This will look terrible in a browser, but view source and you'll see a nicely formatted note of each record. The advantage here is that this bit of code will work for whatever query you poll the database with - you don't have to remember to change column names, watch cases etc. The downside is that it's pretty much useless for production deployment :(


All times are GMT -5. The time now is 06:00 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.