473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Can't seem to connect to mysql database and output results

I'm new to mysql but seem to understand it enough to do what simple stuff I need but I can't get even this basic script to echo what is in the one colum, one row table.
I am able to connect now it seems since I don't get any errors anymore in logs or browser.
Im trying to get this working first then I need to access it from another domain and write to it.
I only need a reference # that I can read and then add 1 to it. I tried to do it with a text file with fread and fwrite the way I used to but now I need to be able to write to it from other domains and can't figure it out to save my life.
I was told mysql database would work. Any help would be GREATLY appreciated. I should be able to figure most of it out myself when I get some basic functionality going.
Thanks.
-----------------------------------------------------------
PHP Version 4.3.9
phpMyAdmin 2.6.4-pl3
MySQL 4.1.20 running on localhost:3306 as counterlead2@localhost
-------------------------------------------------------------
SCRIPT:
<?

$mysql_server = 'localhost';
$mysql_user = "counterlead";
$mysql_pass = "fhujeduu";
$mysql_db = "leadsnumfile";

$ntable = 'ntable';
$column = 'number';

mysql_connect($mysql_server,$mysql_user,$mysql_pas s) or die("Unable toconnect1 to database");

mysql_select_db($mysql_db) or die("Unable toconnect2 to database");

$sql = 'SELECT * FROM `ntable` LIMIT 0, 30 ' or die(mysql_error);

echo "$sql";


?>
Mar 23 '07 #1
7 1719
amrhi
22
I'm new to mysql but seem to understand it enough to do what simple stuff I need but I can't get even this basic script to echo what is in the one colum, one row table.
I am able to connect now it seems since I don't get any errors anymore in logs or browser.
Im trying to get this working first then I need to access it from another domain and write to it.
I only need a reference # that I can read and then add 1 to it. I tried to do it with a text file with fread and fwrite the way I used to but now I need to be able to write to it from other domains and can't figure it out to save my life.
I was told mysql database would work. Any help would be GREATLY appreciated. I should be able to figure most of it out myself when I get some basic functionality going.
Thanks.
-----------------------------------------------------------
PHP Version 4.3.9
phpMyAdmin 2.6.4-pl3
MySQL 4.1.20 running on localhost:3306 as counterlead2@localhost
-------------------------------------------------------------
SCRIPT:
<?

$mysql_server = 'localhost';
$mysql_user = "counterlead";
$mysql_pass = "fhujeduu";
$mysql_db = "leadsnumfile";

$ntable = 'ntable';
$column = 'number';

mysql_connect($mysql_server,$mysql_user,$mysql_pas s) or die("Unable toconnect1 to database");

mysql_select_db($mysql_db) or die("Unable toconnect2 to database");

$sql = 'SELECT * FROM `ntable` LIMIT 0, 30 ' or die(mysql_error);

echo "$sql";


?>
you should use
$sql1=mysql_query($sql);
to show your data you should use
while ($row=mysql_fetch_array($sql1)){
echo "$row";
}
You still must learn alo of about mysql script try to open
http://www.tizag.com
Mar 23 '07 #2
Thank you that helps but now my browser output is:
Array

My database seems to be connecting fine. I'm at a loss.
Mar 23 '07 #3
I changed the WHILE statement to:
echo $sql1;

and I get browser output:
Resource id #3

Still at a loss but plugging away.
Mar 23 '07 #4
ronverdonk
4,258 Expert 4TB
The fact that you freely exchange part of the shown sample (while statement) with an echo and don't have a clue as what a resource id is, makes me advise you to follow some basic tutorials on MySQL (and maybe PHP).

You cannot just learn databases and languages by trial and error or fiddling around. So here are some tutorials on the basics of MySQL:

http://www.w3schools.com/php/php_mys...L introduction
http://www.devshed.com/c/a/MySQL/Beg...ySQL-Tutorial/
http://www.freewebmasterhelp.com/tut...MySQL Tutorial
http://www.tizag.com/mysqlTutorial/
http://www.sitepoint.com/subcat/php-tutorials
http://www.php-mysql-tutorial.com/
http://bmw.ws.utk.edu/nsu/php/
http://www.developer.com/lang/php/article.php/3288671
Using MySQL from PHP part 1
Using MysQL from PHP part 2

Ronald :cool:
Mar 23 '07 #5
thank you for your reply. The resources you listed are very helpful.
I have to disagree about trial and error as a way to learn. I need to learn this fast and get something up running now. I'm not trying to create some complex database. I am just trying to create a one column, one row table i a single database that I can read AND write to from different domain. At this point I just need to get it to echo the single value to see that mysql is running correctly so I can move on to the next step. I added two more rows for a total of three just for experimental purposes and now get browser output:
ArrayArrayArray

The data in the table is:
22
33
55

Type=text MIME: text/plain
Mar 23 '07 #6
This the presesnt script:

<?

$mysql_server = 'localhost';
$mysql_user = "counterlead"; // Your Database Username eg: "you_you"
$mysql_pass = "fhujeduu"; // Your Database Password eg: "mypass"
$mysql_db = "leadsnumfile"; // Your Database Name eg: "you_you"

$ntable = 'ntable';
$column = 'number';

mysql_connect($mysql_server,$mysql_user,$mysql_pas s) or die("Unable toconnect1 to database");

mysql_select_db($mysql_db) or die("Unable toconnect2 to database");

$sql = ("SELECT * FROM ntable");
$sql1=mysql_query($sql);
while ($row=mysql_fetch_array($sql1)){
echo "$row";
}
?>
Mar 23 '07 #7
Finally got it all worked out. Thanks for your help.
Mar 23 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Eric W. Holzapfel | last post by:
Hello PHP group, I have mysql running on a linux box. I have apache (2.0.4) running on a diff linux box. I have php 4.X. I can connect to the mysql db using odbc from a windows box, but...
1
by: Marc | last post by:
Hello, Newbie here..... Searching and working this for a week now. We too are having the same problems. Using MySql 4.0.14 and there are "no problems" at all.
7
by: atlasyeo | last post by:
Hi, my first time posting on a newsgroup. anyway, let's cut to the chase. I'm trying to migrate mysql database form one server to another server. So I copied the data from /var/lib/mysql to the...
1
by: Peter Nikolaidis | last post by:
Greetings, I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a Fink distribution of Python 2.2.2. I have seen only a few posts on the subject, some of them relate to...
4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
11
by: grumfish | last post by:
I'm trying to add a row to a MySQL table using insert. Here is the code: connection = MySQLdb.connect(host="localhost", user="root", passwd="pw", db="japanese") cursor = connection.cursor()...
0
by: Jim S. | last post by:
I'm having a horrible time simply inserting the date in a MySQL database through a Visual Basic program. I have a table, called "ORDERS"; "ID" is the primary key. I'm trying the insert the date,...
0
by: Chris W | last post by:
I have mysql 4.0.16 on my windows machine and have just installed suse linux on another machine. It comes with mysql 4.0.15. After I got the user setup I was able to use the mysql client on the...
4
by: d3vkit | last post by:
Okay so I am at a loss here. I have a website that I've previously had no trouble connecting to the mysql DB on. I have an include to a connect file with the relevant connection info, and it was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.