Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 01-10-2003, 06:00 PM   #1 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
yeah...i didn't fix it.....mySQL trouble (permissions?)

yeah......it made a lot of sense in computer class, but when I got home and tried it out,....well yeah, no luck.

still, I type in http://darkstar/index.php and >>NOTHING<< loads.

I was thinking, it should of at least outputed the invalid password error or something. Here is some code I am trying to get work - straight from the book "SAMS Teach yourself PHP4 in 24hours".

the code:

<html>
<head>
<title>testing mySQL connection</title>
</head>
<body>
<?php
$user = "root";
$pass = "123";
$db = "ao_db2003";
$link = mysql_connect("localhost", $user, $pass );
if ( ! $link )
die( "Couldn't connect to MySQL");
print "Successful connecting to server <p>";
mysql_select_db ( $db )
or die (could't connect to $db: ".mysql_error() );
print "Successfully connected to database \"$db"\<p>;
mysql_close ($link);
?>
</body>
</html>

WTF!!!! I tried it in a bunch of different browsers, and it is compliling fine because I cant see the source in "view source".

thanks A LOT for anyones help,

Trevor

:butt: - hehehe
trevor is offline   Reply With Quote
Old 01-10-2003, 06:21 PM   #2 (permalink)
Ilya020
Techno Rat
 
Ilya020's Avatar
 
Join Date: Jan 2003
Location: San Diego
Posts: 559
Ilya020 is on a distinguished road
Send a message via AIM to Ilya020
Well, even if It did work when you viewed the source you wouldnt see it because PHP is server side which means it gets exectued before you go there (something like that. )

Therefore, it is perfectly fine if you cant see it.

Ilya


BTW. could you give me ALL the source with the variables and all, ill test on my box.
__________________
> SELECT * FROM users WHERE clue > 0
0 rows returned
Ilya020 is offline   Reply With Quote
Old 01-10-2003, 06:21 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
hey trevor,

what is the real link to the page? or is it on your internal network?

sounds more like a web server problem. have you tried making a regular html page without any php on your web server?

the text outside the <?php and ?> should all show up like regular html.
sde is offline   Reply With Quote
Old 01-10-2003, 06:28 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
Quote:
Originally posted by ilya020
Well, even if It did work when you viewed the source you wouldnt see it because PHP is server side which means it gets exectued before you go there (something like that. )

Therefore, it is perfectly fine if you cant see it.
ilya,
i guess we posted at the same time or i woulda corrected you.

as i mentioned above, if there is text outside the <?php and ?> , then it is not parsed by php, and you would see everything above the php script no matter what, .. and everything below it provided the php script didn't 'die'.

also, if it was working, it wouldn't be perfectly fine because the script should either echo:
Couldn't connect to MySQL
or
Successful connecting to server
sde is offline   Reply With Quote
Old 01-10-2003, 06:48 PM   #5 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
thanks guys, but i dont think it is that simple.

I have other pages that have php but no database access that work fine through http://darkstar:80/

if any of you read this during the next 6 hours (providing i dont get disconnected) try it for yourself at

http://209.167.16.230/connect.php is the code above, no html involved, all it is designed to do is print to the screen wether or not it successfully connected to the database.

the page
http://209.167.16.230/ao/register.php works fine.

I idealy want ao/index.php to work.

thanks alot for your help so far,

Trevor
trevor is offline   Reply With Quote
Old 01-10-2003, 06:57 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
i see you seeing the html outside your php..

try this connect script:
PHP Code:
<?
$hostname
="localhost";
$mysql_login="username";
$mysql_password="password";
$database="database";

if (!(
$db mysql_connect("$hostname""$mysql_login" "$mysql_password"))){
  print(
"Can't connect.");    
}else{
  if (!(
mysql_select_db("$database",$db))) {
    print(
"Can't connect database.");
  }else{
    print(
"Connection Successful.");
  }
}
?>
sde is offline   Reply With Quote
Old 01-10-2003, 08:00 PM   #7 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
well at least it shows something. it says "can't connect" (yeah!)

but it always says that.

what I dont get is
where does the $db come from?

thanks,

Trevor

hey, if your not to busy can you meet me in the irc and help me figure this out?
trevor is offline   Reply With Quote
Old 01-10-2003, 08:29 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
$db is the name of the connection variable.

lets say your database name is "data" and your username is "trevor" and your pass is "trevor00"

have you created a user in your mysql database with the permissions to access that database? also, have you created the actual databse?

create database
Code:
create database trevor;
create user with administrative permissions
Code:
grant all privileges on *.* to trevor@localhost identified by 'trevor00';
now that connection script should work assuming that it resides on the same server as mysql.
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
and on to mysql .. sde Linux / BSD / OS X 2 01-18-2003 07:39 PM
permissions in MySQL trevor PHP 3 01-10-2003 01:47 PM


All times are GMT -8. The time now is 11:55 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting