php forms and database navigatio
Posted on
16th Feb 2014 07:03 pm by
admin
Hello,
I'm new to php and i'd like to post the following.
I have written code to get records from a DB and i need one record at a time to be filled in a form i created. Then the next record should be displayed after the user hits the "press any ket button". It does not work
PLEASE HELP !
code is following
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<?php
$labels = array( "user_name" => "User Name", "create_date" => "Creation Date", "password" => "Password",
"last_name" => "Last Name",
"first_name" => "First Name",
"street" => "Street",
"city" => "City",
"state" => "State",
"zip" => "Zip",
"email" => "Email",
"phone" => "Phone",
"fax" => "Fax");
$submit = "Press any key";
include("dbstuff.inc");
$cxn = mysqli_connect($host,$user,$passwd,$databname);
if (!cxn) {
printf("Can't connect to localhost. Errorcode: %dn", mysqli_connect_errno ());
}
else { echo "connection successful !";
}
/* or die ("could not connect to server");*/
$query = "SELECT * FROM customer ";
$result = mysqli_query ($cxn,$query) or die ("could not execute query");
/*$customer = mysqli_fetch_assoc($result);*/
?>
<html>
<head><title>Customer Record</title>
<style type='text/css'>
/*div {background-color:#b0c4de}*/
body {color:blue}
body {background-color:#b0c4de}
<!--
#form {margin: 1.5em 0 0 0;
padding: 15;
}
#field {padding-bottom: 1em;}
label {
font-weight: bold;
float: left;
width: 10%;
margin-right: 1em;
text-align: right;
}
-->
</style>
</head>
<body>
<h3> Customer Details</h3>
<?php
/* Loop that displays the form fields */
/* print_r ($customer);*/
while ($customer = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<form action = '$_SERVER[PHP_SELF]' method = 'POST'>
<div id='form'>";
foreach($labels as $field => $label)
{
echo "<div id='field'><label for='$field'>$label</label>
<input id='$field' name='$field' type='text'
size='50%' maxlength='65' value = {$customer[$field]} />
</div>n";
} /* foreach*/
echo "<input style='margin-left: 33%' type='submit' value='$submit' />n";
} /*while*/
/*echo "</div>n";*/
/* free result set */
mysqli_free_result($result);
/* close connection */
mysqli_close($cxn);
?>
</form></body></html>
No comments posted yet
Your Answer:
Login to answer
262
7
Other forums
Serial number of exernal hard disk/Thumbdrive
Hi guys,
I am new tio java networking concepts.Please tel me how to get Serial
number of exernal
Using Microsoft Exchange Server with PHP
Hi,
I wanted to know if its possible to fetch email attachments from the exchange server usin
PHP submit form script causing blank page
Im trying to submit a form using this script, however nothing shows up on the page, does anyone know
Get dump of MySQL DB from Live Site
I'm after an easy, but secure way of generating and importing a MySQL dump from a remote server.
Not capturing all the information we require in the form.......
Hi Guys,
I was wondering if you would share some more of your knowledge today, I'm hoping it
PHP, Arrays & A Lot Of Confusion
I've been doing basic PHP work on sites for a few years now, but I've never been tempted to learn ho
Multiple PHP errors when clicking a link..and..removing a ghost..
Hi - I have 2 problems with a new website - homeswapvacations.com, which I need help solving.
How to store checkbox array in a session, and then be able to add to it?
I'm trying to store an array of checkbox values into a session array, sort of like a shopping cart,
LinkedList help
Ok so I just learned quickly about lists, so I have a not too hard project I think, but am having a
Sharing PHP Sessions Across Domains
I am in the process of writing a script to share a php session across various domains I have.
The