Storing Values taken from a DB...


Posted on 16th Feb 2014 07:03 pm by admin

Using this code it will generate a short list from my database

<?php
mysql_connect('localhost','root','');
mysql_select_db("clients");
$fname = $_POST['firstname'];
$SQL = "SELECT * FROM members WHERE firstname = '$fname'";
$result = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($result)) {
print $db_field['firstname'] . "<BR>";
print $db_field['lastname'] . "<BR>";
print $db_field['email'] . "<BR>";
print $db_field['date'] . "<BR>";
echo $db_field['firstname'];
}

?>


but I need to be able to use the values its pulled out later down in the page.
if I try to use echo $db_field['firstname']; somewhere else on my page it just leaves a blank spot...

I tried doing this:

<?php
mysql_connect('localhost','root','');
mysql_select_db("clients");
$fname = $_POST['firstname'];
$SQL = "SELECT * FROM members WHERE firstname = '$fname'";
$result = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($result)) {
$name = print $db_field['firstname'] . "<BR>";
$lname = print $db_field['lastname'] . "<BR>";
$mail = print $db_field['email'] . "<BR>";
$day = print $db_field['date'] . "<BR>";
echo $db_field['firstname'];
}

?>


and then using echo $thevariable i wanted but that didnt work either...

thanks

No comments posted yet

Your Answer:

Login to answer
165 Like 39 Dislike
Previous forums Next forums
Other forums

Target costs on Process orders not calculating
Hi All,

We have released standard costs for all the materials. We have also done Goods r

Form errors in an array
I'm processing a form and putting the errors in an array. empty($errors) doesn't seem to do the tric

FPDF Help
I've been playing with the FPDF module. I was building a form and rolling right along and then sudde

Transferring session variables into MySQL
I am trying to transfer $_SESSION variables into MySQL. However there is an error in my MySQL statem

Multiple Pages
Hi. Im very new to php. I'm trying to create a basic login/registration page.

So I have a bas

Retrieving the 25 most recently added entries from all tables in a MySQL databas
Hello,

The code below works great. It creates a table that shows the 25 most recently added t

Session problem?!?
Hello All! I am very new to the php world but I am working on fixing things that a previous programm

Multithreading design
Hi

I have come up with a Singleton class that manages a pool of database connections. Basical

Displaying image pathname instead of image
Hello

Im trying to upload and then display images from a mysql database - Its only basic and

ScriptResource.axd gives an error on fresh install of ASP.NET Ajax 1.0
Hello,I have a fresh install of Microsoft ASP.NET Ajax 1.0. When I create an Ajax enabled website in

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash