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

Assign mysql record values to gloabl variabel

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);

}

Jul 11 '06 #1
4 1414
Mel
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.

Jul 11 '06 #2
Rik
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
Jul 11 '06 #3
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-

Jul 11 '06 #4
Hi,

Thanks, it was a combinatrion of those things mentioned.

Jules.

Jul 11 '06 #5

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

Similar topics

19
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...
4
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...
4
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...
0
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...
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...
5
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...
6
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...
9
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...
1
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...
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
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
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...
0
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...
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
agi2029
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,...

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.