Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL webpage connection problem

Status
Not open for further replies.

pepy

Technical User
Jan 14, 2004
19
US
i have made a mysql database at freesql.org
i can connect to it using different myadmin progams.

but i cant for the life of me connect to it using a web page??
For "weeks" i have tried many different ways using php.

freesql.org is not my server, this may have something to do with it??
I have tried 100s of different ways to connect to it....
below is one of the ways i have tried....

Maybe one of you can see what i am doing wrong
Please help

Thank you
Pepy


<html>
<head>
<TITLE></TITLE>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html&quot;>

</head>

<BODY>

<?
$username=&quot;xxxxxxxxxxxxxx&quot;;
$password=&quot;xxxxxxxxxxxxxx&quot;;
$database=&quot;dbsell&quot;;

$db = mysql_connect(&quot;freesql.org&quot;, $username, $password);
@mysql_select_db(dbsell) or die( &quot;Unable to select database&quot;);

$query=&quot;SELECT * FROM t1&quot;;
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


echo &quot;<b><center>Database Output</center></b><br><br>&quot;;

$i=0;
while ($i < $num) {

$domain=mysql_result($result,$i,&quot;name&quot;);
$code=mysql_result($result,$i,&quot;code&quot;);


echo &quot;<b>$domain $code</b>&quot;;

++$i;
}

?>

</body>
</html>

 
I've tried and cannot connect as well.
Like me, you are probably behind a firewall that does not allow the connection.



&quot;If you always do what you've always done, you will always be where you've always been.&quot;
 
no i have no fire wall-

freesql.org is not my server, this may have something to do with it??

this sql is all new to me and i think the above is my problem?

freesql.org is a site that provides free mysql databases, &quot;for ppl to learn sql&quot; i have imported some test tables and i am now tring to connect to them by making a php web page on my own ftp site.

There must be a way to do it,
i am just stumped at this point.

pepy
 
I've also signed up for a database on the site.

What is you substitute the hostname 'freesql.org' with the IP address.
(which is 24.218.161.96 for the freesql server)

<?php
$server=&quot;24.218.161.96&quot;;
$user = &quot;testuser&quot;;
$pass = &quot;testpass&quot;;
$db = &quot;testdb&quot;;
$link = mysql_connect( $server, $user, $pass );
if ( ! $link )
die( &quot;Couldn't connect to MySQL&quot; );
print &quot;Successfully connected to server<P>&quot;;
mysql_select_db( $db )
or die ( &quot;Couldn't open $db: &quot;.mysql_error() );
print &quot;Successfully selected database \&quot;$db\&quot;<P>&quot;;
mysql_close( $link );
?>

&quot;If you always do what you've always done, you will always be where you've always been.&quot;
 

thank you rzs0502
but that didnt work either.

pepy
 
Can you 'telnet 24.218.161.96 3306'

You should see something like:
Escape character is '^]'.
+
3.23.51-nt¼ {j!cRQ~I^B



&quot;If you always do what you've always done, you will always be where you've always been.&quot;
 
Have you tried to change your password at:

I found that it only accepted when the database name was in uppercase.
All fields will then be case sensitive.

Try to change your password with your normal values.
At least you will know that the database is active.


&quot;If you always do what you've always done, you will always be where you've always been.&quot;
 
i use port 3306

like i said i can connect to it using 5 different admin programs.

i just cant make a web page connection.

i will try the uppercase thing and let you know if it worked.

thank you
pepy
 
Thanks again for your input rzs0502
but none of those ideas worked for me eeeeeeeeeek!


ok this is where i am.
i get an error which reads

Parse error: parse error in /mnt/web_i/d25/s15/b01ce1a1/ on line 20



###line 20 is
SELECT * FROM dbsell.t1;

###which works in the mysql control center&quot;
###t1 is my table.


####i have tired
&quot;SELECT * FROM dbsell.t1&quot;;
SELECT * FROM 'dbsell.t1';
$query=SELECT * FROM dbsell.t1;
$query=&quot;SELECT * FROM dbsell.t1&quot;;
ect ect....



#####my full entry is

<body>
<?
$username=&quot;xxxxxxxxx&quot;;
$password=&quot;xxxxxxxxx&quot;;
$database=&quot;dbsell&quot;;

$db = mysql_connect(&quot;freesql.org&quot;, $username, $password);
@mysql_select_db(dbsell) or die( &quot;Unable to select database&quot;);

SELECT * FROM dbsell.t1;

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


echo &quot;<b><center>Database Output</center></b><br><br>&quot;;

$i=0;
while ($i < $num) {

$domain=mysql_result($result,$i,&quot;domain&quot;);
$code=mysql_result($result,$i,&quot;code&quot;);


echo &quot;<b>$domain $code</b>&quot;;

++$i;
}

?>
</body>
</html>
-------------------------------------------



#####and i have also tried
<body>
<?
$username=&quot;xxxxxxxxx&quot;;
$password=&quot;xxxxxxxxx&quot;;
$database=&quot;dbsell&quot;;

$db = mysql_connect(&quot;freesql.org&quot;, $username, $password);

SELECT * FROM dbsell.t1;

?>

</body>
</html>


------------------------------------------------
can anyone else see what i am doing wrong?


I have spent over 100 hours reading the help files and i must say they really do suck! and I still cant pin point it.................the content help files didnt seem to down load with any of the admin programs lol.

i have tried so many things i am just going around in loops now......


thank you
pepy
 
Pepy,
I did a google search for &quot;php mysql tutorial&quot; and the first thing I found led me to this:

So, what you probably need to do is:
Code:
$query = &quot;SELECT * FROM dbsell.t1&quot;;
$result = mysql_query($query,$db);
(you left the database connection out of the mysql_query statement)


Now, how many apples were on the tree?!
 
Oh, and you also left the db connection off of mysql_select_db and you probably also need quotes around dbsell on that line. I also have no idea what that @ is for on that line, but then again, I don't know php. Follow the example in the link I gave and see if that helps.

 
If you are behind a firewall and/or using a proxy server, be sure to make an exception of the exact URL you are trying to connect to.

This will bypass any restrictions on port 80 and 88, caching issues, etc., for connection to that URL.

Hope this helps.
 
no idea what that @ is for
to 'suppress any error messgae that function would produce'

Parse error: parse error in /mnt/web_i/d25/s15/b01ce1a1/ on line 20 becuse PHP has nothing like SELECT command.

it is better ide to keep the string variables quoted in functions also i.e. in place of
$db = mysql_connect(&quot;freesql.org&quot;, $username, $password);
use
$db = mysql_connect(&quot;freesql.org&quot;, &quot;$username&quot;, &quot;$password&quot;);

i also tried freesql.org bu i alwasy got connection refuded too may users. seems to be a very pouplar site.

if u wish to learn it onur own on windows then download wampp from - an excellent thing. WAMP is euqivalet to LAMP. it is Apache/MySql/PHP on Windows/Linux. and it comes as one bubndle



[ponder]
----------------
ur feedback is a very welcome desire
 
Thank you philote, but it didnt work grrrrrrrrrrrr lol
yes i read that page also.
i am not kidding when i say i have read about 100 hours over 3 week on this stuff.

but never the less i did try that script and a few verions of it has well again just in case...... one thing i notice with that that script is there is no password??????
not sure if that matters, i would think it would?



-----------------------------------------------
OK
lets put all the cards down..........
this freesql.org is a free server for learning how to do sql so.............
i am going to include my user name and password this time!!!!!!!!!

I can change it to something else later,
if i or anyone else can get this thing to connect.
---------------------------------------------------

this way here anyone who wants to try to actually make a php web page connect and succeeds, they can paste the connection script back here.

--------------------------------------------------

<html>
<head>
<TITLE></TITLE>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html&quot;>
</head>

<BODY>
<?
$username=&quot;pepy&quot;;
$password=&quot;damit&quot;;
$database=&quot;dbsell&quot;;

$db = mysql_connect(&quot;freesql.org&quot;, $username, $password);
$mysql_select_db(dbsell) or die( &quot;Unable to select database&quot;);

$mysql = SELECT * FROM dbsell.t1;

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


echo &quot;<b><center>Database Output</center></b><br><br>&quot;;

$i=0;
while ($i < $num) {

$domain=mysql_result($result,$i,&quot;domain&quot;);
$code=mysql_result($result,$i,&quot;code&quot;);


echo &quot;<b>$domain $code</b>&quot;;

++$i;
}

?>
</body>
</html>




 
Pepy,
this worked for me, though you'll need to get your results from the query from the array instead of how you were doing it. Again, I don't know PHP. I just found this code by doing searches.
Code:
$username=&quot;pepy&quot;;
$password=&quot;damit&quot;;
$database=&quot;dbsell&quot;;

$db = mysql_connect(&quot;freesql.org&quot;, $username, $password);
mysql_select_db(&quot;dbsell&quot;, $db) or die( &quot;Unable to select database&quot;);

$mysql = &quot;SELECT * FROM dbsell.t1&quot;;

$result=mysql_db_query(&quot;dbsell&quot;, $mysql);

$result_array=mysql_fetch_array($result);
$num=$SQL_Result_Array['Total'];

mysql_close();

 
I found a way to do it with the functions you were using. I found the references for these functions at

This worked for me:
Code:
<html>
<head>
<TITLE></TITLE>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html&quot;>
</head>

<BODY>
<?
$username=&quot;pepy&quot;;
$password=&quot;damit&quot;;
$database=&quot;dbsell&quot;;

$db = mysql_connect(&quot;freesql.org&quot;, $username, $password);
mysql_select_db('dbsell', $db) or die( &quot;Unable to select database&quot;);

$mysql = &quot;SELECT * FROM dbsell.t1&quot;;

$result=mysql_query($mysql);

$num=mysql_num_rows($result);

mysql_close();



echo &quot;<b><center>Database Output</center></b><br><br>&quot;;

$i=0;
while ($i < $num) {

$domain=mysql_result($result,$i,&quot;domain&quot;);
$code=mysql_result($result,$i,&quot;code&quot;);


echo &quot;<b>$domain $code</b>&quot;;

++$i;
}

?>
</body>
</html>
 
Thank you philote , but when i load it all i got these errors?????????????

-----------------------------------------------------
Warning: Can't connect to MySQL server on 'freesql.org' (13) in /mnt/web_i/d25/s15/b01ce1a1/ on line 13

Warning: MySQL Connection Failed: Can't connect to MySQL server on 'freesql.org' (13) in /mnt/web_i/d25/s15/b01ce1a1/ on line 13

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /mnt/web_i/d25/s15/b01ce1a1/ on line 14
Unable to select database
------------------------------------------------------

########## line 13 and 14 ##########
$db = mysql_connect(&quot;freesql.org&quot;, $username, $password);
mysql_select_db('dbsell', $db) or die( &quot;Unable to select database&quot;);
------------------------------------------------------

at least i now know
someone can connect to it..... sigh
just not me. lol
a
 
Hi pepy.
i can understand ur frustation. But still trying some more. Yr line 14 error is because of line 13 error i.e. no connection to mysql server hence no databse.

so your primary issue here is connectivity to freesql.

try directly connecting from mysql client as mysql -h freesql.org -u peppy -p&quot;damit&quot;. and whatever succeds then give that in mysql_connect



[ponder]
----------------
ur feedback is a very welcome desire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top