473,394 Members | 1,870 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,394 software developers and data experts.

new to php and mysql and need a little help

I am try to teach myself PHP and MYSQL.

Below I have a php file I have created which when i look at it in a browser
returns a nice list of people and there addresses.

When I change the $data line from
$data = mysql_query("SELECT * FROM dir ORDER BY SURNAME") or
die(mysql_error());
to
$data = mysql_query("SELECT * FROM dir WHERE SURNAME = 'SMITH'") or
die(mysql_error());

I expected my page to show all the people who had the surname SMITH. But
instead I get nothing.

When I run the query SELECT * FROM dir WHERE SURNAME = 'SMITH';
against my mysql databse it returns the lines with SURNAME Smith.

Can anyone tell me why it doesnt work in my php file?
<html>
<head>
<title></title>
</head>
<body>
<font size="2" face="Century Gothic" color="#0000FF">

<?php

//Connect information
mysql_connect("localhost", "gaspa", "blah123") or die (mysql_error());
mysql_select_db("SBC") or die (mysql_error());

// Collects data from "dir" table
$data = mysql_query("SELECT * FROM dir ORDER BY SURNAME") or
die(mysql_error());

// puts the "dir" info into the $info array
$info = mysql_fetch_array( $data );

// Print out the contents of the entry
while($info = mysql_fetch_array( $data ))
{
Print "<b>SURNAME:</b".$info['SURNAME'] . " ";
Print "<b>HOME PHONE:</b".$info['HOME_PHONE'] . " ";
Print "<b>Name:</b".$info['NAME_1'] . " ";
Print "<b>Mob:</b".$info['PHONE_1'] . " ";
Print "<b>Birthday:</b".$info['BIRTHDAY_1'] . " ";
Print "<b>Name:</b".$info['NAME_2'] . " ";
Print "<b>Mob:</b".$info['PHONE_2'] . " ";
Print "<b>Birthday:</b".$info['BIRTHDAY_2'] . "<br><Br";
}
Print "</table>";

?>

</font>
</strong>
</body>
</html>


Feb 24 '07 #1
1 1101
On Feb 24, 5:45 am, "glenn" <g...@bigpond.comwrote:
I am try to teach myself PHP and MYSQL.

Below I have a php file I have created which when i look at it in a browser
returns a nice list of people and there addresses.

When I change the $data line from
$data = mysql_query("SELECT * FROM dir ORDER BY SURNAME") or
die(mysql_error());
to
$data = mysql_query("SELECT * FROM dir WHERE SURNAME = 'SMITH'") or
die(mysql_error());

I expected my page to show all the people who had the surname SMITH. But
instead I get nothing.

When I run the query SELECT * FROM dir WHERE SURNAME = 'SMITH';
against my mysql databse it returns the lines with SURNAME Smith.

Can anyone tell me why it doesnt work in my php file?

<html>
<head>
<title></title>
</head>
<body>
<font size="2" face="Century Gothic" color="#0000FF">

<?php

//Connect information
mysql_connect("localhost", "gaspa", "blah123") or die (mysql_error());
mysql_select_db("SBC") or die (mysql_error());

// Collects data from "dir" table
$data = mysql_query("SELECT * FROM dir ORDER BY SURNAME") or
die(mysql_error());

// puts the "dir" info into the $info array
$info = mysql_fetch_array( $data );

// Print out the contents of the entry
while($info = mysql_fetch_array( $data ))
{
Print "<b>SURNAME:</b".$info['SURNAME'] . " ";
Print "<b>HOME PHONE:</b".$info['HOME_PHONE'] . " ";
Print "<b>Name:</b".$info['NAME_1'] . " ";
Print "<b>Mob:</b".$info['PHONE_1'] . " ";
Print "<b>Birthday:</b".$info['BIRTHDAY_1'] . " ";
Print "<b>Name:</b".$info['NAME_2'] . " ";
Print "<b>Mob:</b".$info['PHONE_2'] . " ";
Print "<b>Birthday:</b".$info['BIRTHDAY_2'] . "<br><Br";}

Print "</table>";

?>

</font>
</strong>
</body>
</html>
take out the first mysql_fetch_array line
Craig

Feb 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason Reljac | last post by:
Howdy, I'm looking for a little help. I had a W2K server with Apache/PHP/mySQL installed and working. I had a specific page that ran a mySQL SELECT INTO OUTFILE and dumped the outfile into a...
51
by: w_curtis | last post by:
I'm an Access user, and I'm trying to learn MySQL and then PHP so I can make some web databases. But it just isn't clicking. I've followed some tutorials, and picked up a book, but just getting...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
0
by: Jason Reljac | last post by:
Howdy, I'm looking for a little help. I had a W2K server with Apache/PHP/mySQL installed and working. I had a specific page that ran a mySQL SELECT INTO OUTFILE and dumped the outfile into a...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
6
by: MBS | last post by:
Yeah, read the previous posts...I did that. None answer my question. I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few days ago on WinXP SP2. My goal is to learn to use these...
175
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
2
by: Lodovikus | last post by:
Hello Everybody, glad I found you all here. I desprately want to understand PHP and MYSQL in relation to develope web sites. I'm sick and tired of build static pages. Brief reading PHP and MYSQL its...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.