Hi, I am new to programming and have been working on this sample database I've made up to solidify what I have learned. All seems to be going pretty well, but I seem to have stumbled into a wall. Is it possible to go through all the elements of a database (like: first name, last name, phone...) and place them into an array to be used for populating an HTML form? I'm looking to make it so I can click a button at the bottom of the form and view the next record in sequence.
Is this possible? The code I have for the sample db is here. It works well.
Code:
<?php
$conn = mysql_connect('localhost', 'root')or die(mysql_error());
$create = mysql_query("CREATE DATABASE IF NOT EXISTS db1") or die(mysql_error());
mysql_select_db ("db1");
?>
<form name ="form"method ="post" action ="browse.php">
<p>First Name: <input type ="text" name ="fname">
Last Name: <input type ="text"name ="lname"><br><br>
address: <input type="text" name ="address"><br><br>
address2: <input type="text" name ="address2" ><br><br>
City: <input type ="text" name ="city"><br><br>
State: <input type ="text" name ="state"><br><br>
Zip: <input type ="text" name ="zip"><br><br>
Phone:<input type ="text" name ="phone"><br><br>
Notes:<textarea name ="notes"></textarea><br><br>
<input type ="hidden" name ="key">
<input type ="submit" name ="submit" value ="Query">
</p>
</form>
<?php
//create table
$testdb = 'CREATE TABLE IF NOT EXISTS testable(id int (11) NOT NULL auto_increment,
lname varchar(40) NOT NULL,
fname varchar(40) NOT NULL,
address varchar(40) NOT NULL,
address2 varchar(40) NOT NULL,
city varchar(15) NOT NULL,
state varchar(2) NOT NULL,
zip int(5) NOT NULL,
phone varchar(11) NOT NULL,
notes longtext NOT NULL,
PRIMARY KEY(id),
KEY testype(lname, fname))';
$result = mysql_query($testdb) or die(mysql_error());
$lname = $_POST['lname'];
$fname = $_POST['fname'];
$address = $_POST['address'];
$address2= $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$notes = $_POST['notes'];
//"$address", address,
$insert = "INSERT INTO testable( id, lname, fname, address, address2, city, state, zip, phone, notes,)
VALUES(0, '$lname', '$fname', '$address', '$address2', '$city', '$state', '$zip', '$phone', '$notes' )";
$results =mysql_query($insert) or die ("Couldn't insert into database because: " .mysql_error());
if(mysql_affected_rows()==1)
{
echo "Success!";
}
else
{
echo "Failed" . mysql_error();
}
if($insert)
{
echo 'Data inserted successfully!';
}
?>
<form name ="form1" method ="post" action ="form1.php">
<input type ="submit" name ="submit" value ="ADD">