Hi,
I've been struggle with the code below.
I've tried mysql_fetch_assoc and various other functions, but can't
seem to get it to work.
The code works as far as that point though.
Any suggestions?
Jules.
global $first_name;
global $last_name;
global $password;
function get_acct_rec($email){
$conn = db_connect(HOST, USER, PASS, DB, PORT);
$sql = "SELECT * FROM `clients` WHERE `email` = '" . $email . "';";
$c_result = mysql_query($sql, $conn) or die("Failed to execute query
at line " . __LINE__ . ": " . db_error($conn));
while ($row = mysql_fetch_assoc($c_result)) {
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$password = $row['password'];
echo $row['first_name'];
}
mysql_free_result($result);
db_close($conn);
} 4 1414
On 2006-07-11 23:47:26 +1000, "Julian Moorhouse" <mi*********@gmail.comsaid:
Hi,
I've been struggle with the code below.
I've tried mysql_fetch_assoc and various other functions, but can't
seem to get it to work.
The code works as far as that point though.
Any suggestions?
Jules.
global $first_name;
global $last_name;
global $password;
function get_acct_rec($email){
$conn = db_connect(HOST, USER, PASS, DB, PORT);
$sql = "SELECT * FROM `clients` WHERE `email` = '" . $email . "';";
$c_result = mysql_query($sql, $conn) or die("Failed to execute query
at line " . __LINE__ . ": " . db_error($conn));
while ($row = mysql_fetch_assoc($c_result)) {
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$password = $row['password'];
echo $row['first_name'];
}
mysql_free_result($result);
db_close($conn);
}
Have you tried dumping out the SQL statement and running the SQL
directly on the database server? If that's okay, var_dump the $conn
variable to make sure it's a valid connection object. If it is, try
var_dump'ing the $row variable from inside the loop to see what it's
being populated with. Sorry if these suggestions seem a little obvious.
Julian Moorhouse wrote:
Hi,
I've been struggle with the code below.
I've tried mysql_fetch_assoc and various other functions, but can't
seem to get it to work.
The code works as far as that point though.
global $first_name;
global $last_name;
global $password;
If you want to make them of use inside the function, you have to declare
themn global inside the function...
function get_acct_rec($email){
$conn = db_connect(HOST, USER, PASS, DB, PORT);
$sql = "SELECT * FROM `clients` WHERE `email` = '" . $email . "';";
$c_result = mysql_query($sql, $conn) or die("Failed to execute query
at line " . __LINE__ . ": " . db_error($conn));
What's the output if you return mysql_num_rows() here? It might be a problem
in the database (such as fieldnames, no matching records etc.).
while ($row = mysql_fetch_assoc($c_result)) {
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$password = $row['password'];
echo $row['first_name'];
}
Seems OK, but won't do a thing besides echoing first_name, see the previous
remark about globals.
Grtz,
--
Rik Wasmus
Julian Moorhouse wrote:
Hi,
I've been struggle with the code below.
I've tried mysql_fetch_assoc and various other functions, but can't
seem to get it to work.
The code works as far as that point though.
Any suggestions?
Jules.
global $first_name;
global $last_name;
global $password;
function get_acct_rec($email){
$conn = db_connect(HOST, USER, PASS, DB, PORT);
$sql = "SELECT * FROM `clients` WHERE `email` = '" . $email . "';";
$c_result = mysql_query($sql, $conn) or die("Failed to execute query
at line " . __LINE__ . ": " . db_error($conn));
while ($row = mysql_fetch_assoc($c_result)) {
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$password = $row['password'];
echo $row['first_name'];
}
mysql_free_result($result);
db_close($conn);
}
Does the query work from the mysql command prompt?
Try putting echo "$sql\n"; after your $sql = line and cut and paste that
into a mysql prompt.
Also, it should probably be mysql_free_result($c_result);
Adding print_r($row) after the while() would show if you ever enter
the loop.
-david-
Hi,
Thanks, it was a combinatrion of those things mentioned.
Jules. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Westcoast Sheri |
last post by:
To keep track of how many fruits my visitors buy, I use a mySQL database
(2 columns: "fruit" and "quantity")....so can we make these following
mySQL queries work somehow?
(visitor buys 5...
|
by: sinasalek |
last post by:
i have a problem with MySQL 4.1.x and UTF8.
in version 4.0, i'm using html forms with utf8 charset for inserting
unicode strings. but in version 4.1.x it is not working! if i change the
charset of...
|
by: Brian Olivier |
last post by:
Hello,
What I try to do is create a string variabel with some intelligence.
I want this variabel to read the information sent by another page and
interpret the result.
The idea is that is a...
|
by: Duncan Smith |
last post by:
Hello,
I'm not very experienced in SQL and I need some advice. I have a
comma separarated values file containing around 20 million records and about
20 fields. There are many missing values...
|
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...
|
by: seddy |
last post by:
Hello !
I`m kinda new to it so I found this `job` very hard therefor I ask for Your help.
So, the thing is...
I have this XML file ( http://www.izishop.net/export.php )
which I need to open...
|
by: bill |
last post by:
I am about to start on a module that will accept a location from
a user, use Google geolocation services to get the lat/lon and
then compute the distance from the site visitor to about 100
kennels...
|
by: KDawg44 |
last post by:
Hi,
I have PHP function that adds a record to the database. The table has
an ID that is AUTO_INCREMENT. Is there anyway to get that ID back
when I do any kind of insert? That ID is a foreign...
|
by: javediq143 |
last post by:
Hi All,
This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |