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 Like 7 Dislike
Previous forums Next forums
Other forums

Is it possible to stop reservation creation in PM Order?
Hi All,

Is it possible to stop reservation creation in PM Order?

Thanks in adv

Will an XHTML DOCTYPE interfere with my PHP if I'm not experienced enough?
I've read this article here: http://friendlybit.com/html/why-xhtml-is-a-bad-idea/

In a nutshe

Random date selection
i want to select random date with time(hour+minutes+sec) where date is specified(10/22/2009) and tim

tell csv import script to ignore blank rows?
Hi i have the below script but i get an error if a row is blank ie a return in the csv file at the e

Time script, set to my time zone?
I am using this line to get the date and time

Code: $time = date(F." ".d.", &q

PHP/Database issue
My friend is helping me make a database where you go to a certain webpage of my site and the page wi

Problem with DB connection
Hello there! I'm new to this forum and I'm new to PHP coding also. I wrote something that doesn't ma

Array disappearing in foreach loop
Okay, I have this problem where an array will become undefined in a foreach loop.

Here is the

mails going in spam??
The mails I sent to folks in my database using mail(function) are going in spam??

Any idea ho

frame help
on the bottom frame is menu.html

Code: <body><form action='link.php' met

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