![]() |
Proper path for PHP?
I'm just trying to learn PHP and would like to know how to setup an easy path to the proper directory to store my php files. Any suggestions,Thanks
|
php path?
If you are talking about .php script files that you are working on, there is really no 'right' place to put them. If you are using apache on localhost to test these scripts then a good place to put them is in ~/Sites. This way you can run your scripts in a web browser using the url:
http://localhost/~USERNAME/phpscript.php Where USERNAME is your short username and phpscript.php is the name of your php script inside of ~/Sites. Good luck with the PHP. It's a really fun language thats pretty easy to learn. |
Hello ezmobius, I had them there, but they wouldn't run, I had to put them in my
/Websever/Documents to run them, I'm on a Mac OS X.2 and I can't rum them from my ~/Sites? They run from there, I have to go there to run them. Thanks |
are you sure that you have apache set to run php files? php is not turned on by default i dont think. the apache manual is on your own computer at http://localhost/manual/ or you can just reply back and we can help to get you going.
Edit: I did not read carefully enough. if you go into the /etc/httpd/users/USERNAME.conf file you will have to add the option in there i believe. That give the admin more control over who can do what on the computer. man do i wish i was near my mac right now. |
Hosting a website on your computer
You can use the Apache Web server software included with Mac OS X to host a website on your computer. Open System Preferences and click Sharing. Click Services. Turn on Personal Web Sharing. webpages you put in your Sites folder (in your home folder) can be browsed at http://your.computer.address/~yourusername/. For yourusername, use your short user name, and include the ending slash (/). Pages you put on your hard disk in Library/WebServer/Documents can be browsed at http://your.computer.address. To find your computer's address, select Personal Web Sharing in the Services window of Sharing preferences. The address is displayed below the Services window. To learn more, use a browser to open index.html in your Sites folder, or look in /Library/WebServer/Documents/Manual. This came right from apples help. You might have already done this though. You can tell if you can see your .php pages at http://localhost/ but not at http://localhost/~username/ Also by default you need to turn on .php parsing in your apache.conf file. Look for a line that say something about server parsed applicationX languages or something to that extent and uncomment the line with the .php extenstions. If you can't get it working right email me at ezra@yakima-herald.com and I will wend you my apache.conf file that is all set up for everything you'll ever need to do with your mac server. |
Thanks Ezra & Jeffo, I think I have it all set up, I'm now trying to get mysql/php to my apache web page. I'd like to read mysql data on my web page. I've tried a few scripts and I haven't succeeded yet. Got error;
Warning: Failed opening 'dbconnect' for inclusion (include_path='.:/usr/lib/php') in /Library/WebServer/Documents/usedata.php on line 2 No Database Selected I don't know what it means? I guess my script is wrong or I left out something. |
"Warning: Failed opening 'dbconnect' for inclusion (include_path='.:/usr/lib/php') in /Library/WebServer/Documents/usedata.php on line 2
No Database Selected" It looks like you are trying to include a file called 'dbconnect' and your script is having a hard time finding the file to include. You need to have the 'dbconnect' file in the same directory as the script that you are trying to include it in. Or if the 'dbconnect' script needs to be in a different directory then you should include it like this: <?php include '/path/to/dbconnect'; ?> That way it is unambiguous(sp?) and the include will work. Also that line where it says No Database selected is probably because your include failed so it did not give your script the info it needed to connect to the db which is what I assume 'dbconnect' is trying to do. Post your whole script here and I will help you get it running. |
Hello Ezra, I probebly need more that this script to link up to php, I put a few scripts in this file already,
<?php unset ($dbfailed); if (mysql_connect("localhost","root")) { mysql_select_db("duckwear") or $dbfailed=mysql_error(); } else { $dbfailed="Could not connect to database"; } if(isset($dbfailed)) { echo $dbfailed; } ?> |
It looks like you are making things too complicated for yourself. Without the rest of the script, I can't tell exactly what you are trying to do but as far as what you just posted goes, try this instead:
PHP Code:
Good lUck. Post your whole script and I can help you get it done! |
I stiil get an error;
Warning: Access denied for user: 'root@localhost' (Using password: NO) in /Library/WebServer/Documents/linktomysql.php on line 2 Warning: MySQL Connection Failed: Access denied for user: 'root@localhost' (Using password: NO) in /Library/WebServer/Documents/linktomysql.php on line 2 Warning: Supplied argument is not a valid MySQL-Link resource in /Library/WebServer/Documents/linktomysql.php on line 3 Access denied for user: 'root@localhost' (Using password: NO) It seems I have to enter a password, I don't know how to enter one for php, I have one for mysql in my terminal and it works, How do I enter one that accesses web? Can we start from begining to get link from mysql/php? Thanks Ezra |
You need to pass the password for mysql in the mysql_connect statement. I assumed that you had not set a password for mysql from your code that you entered above. The way to do it like this:
PHP Code:
PHP Code:
|
by default mysql has a root password and you would need to reset it to your own password. I think the reason why you are getting rejected is because you are trying to access the database with no password being used and one should be required so it is failing. have you been using mysql all along on this computer, or is it a new install?
edit: sorry aparently i should have refreshed the page before i posted. (I had it open for a while before i went back to reply) |
jeffo, I have been using mysql right along, I do have a password for mysql and it works fine in the terminal and I'm using it. I did enter a password into $db = mysql_connect('localhost','root','password'); But it didn't work.
I still can't access the mysql data from php code. |
When you log in to mysql from the terminal, do you use this command?
mysql -u root -p and then mysql asks for your password? If you're just typing mysql by itself then you are not using the root user. Heres how you can change the password and be sure it will work. Type the following command: mysqladmin -u root -p password secret This command will run and ask for your CURRENT root password, after you type your password correctly it will change the password to 'secret' so replace 'secret' with whatever you want to change the password to. If you complete the command succesfully it will dump you back to the command prompt with no errors and your new password will be set. |
Hi Ezra, Your script worked with html, But with [No Data Selected] message your box [] was there and I think I got the password in there now to get the data into the web. I guess the html part is working, but no data from php? Thanks for staying with me. fvs
|
I'm a little unclear as to what you are talking about in your last post. Can you explain it a bit better? What kind of data are you trying to get out of the database? Will you need more than 1 result? Please post ALL of the code you are using and explain what you are trying to do. Also tell me what your database is called and what the name of the column in the db is called that you are trying to get information out of. If you post all this info I will write the script for you and you will just have to replace the password with the correct one to get it to work. Then once your script is working you can start to see how and why things are working and move on from there.
I'm about to get on the road to drive to my families house for thanksgiving. So I won't be able to get back to you until later tonight or tommorow. But I will help you get this script up and running. Also you might try removing the ORDER BY RAND() part of the query until you can get the data to print and the rest of the script to work, then we'll get the random part to work. |
Ezra Happy Thanksgiving, I'm also traveling and will be back Friday night.
The data code is from a book "Mysql Essential Skills" The database is called "duckwear" the tables are duck_cus, duck_sales the tables have name,address, city, state, zip, the sales report have design,winter ,spring,summer,fall., I tried following from the book but lost a step or two, Learning from a book is kind of hard for me when I start to stumble I need to talk it out that's why I'm on this forum to get a different view of how I'm looking at it. Your php code you posted above didn't work. But I did straighten out the "localhost, user, password" that's taken care of. Thanks again, Happy Holiday. regards, fvs |
PHP Code:
|
Hello Ezra,
Thanks for staying, I tested it out and the first time I got an error message that said that there was no db duckwear, so I tried another db that is work_2004 and to select * from current_cus; I got a blank web page? I'm really trying to get it, but I think I'm missing something. Here is the code without my name and pw, Check it out. <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[name]</td><td>$row[address]</td><td>$row[city]</td><td>$row[state]</td><td>$row[zip]</td>"; echo "</tr>"; } ?> </table> </body> </html> |
Heya-
OK lets see if we can fix this for you. Actually getting a blank web page is good. It probably means that everything is working but the query is not yielding any results. So lets take a look at this line: PHP Code:
echo "<td>$row[id]</td<td>$row[name]</td> Do you follow me? You can use the script that got you a blank web page for a different db but you need to change the indexes inside of the $row[] array in order for it to work. You also need to change the $query line. Since you changed to the db 'work_2004' then you need to change the name of the table in the SELECT statement. So if you tanle in 'work_2004 was called 'customer' then you would change the SELECT line to" PHP Code:
Try this and get back to me! |
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> |
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:
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! |
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> |
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. |
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...
|
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 |
Just a quickie - have you tried removing the ";" from the end of the "while" line in your code?
|
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 |
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:
|
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
|
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. |
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? |
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.
|
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) ) { |
| 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.