Current location: Hot Scripts Forums » Other Discussions » Database » info into array

info into array

 
Prev Previous Post   Next Post Next
  #1  
Old 07-07-09, 05:57 AM
zenix zenix is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
info into array

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">
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove value from array Nikas PHP 1 05-20-09 04:20 AM
Multi-Dimensional Array Help Nikas PHP 17 05-04-09 03:10 AM
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' Dr. Forensics PHP 3 07-15-06 04:54 PM
Serializing a set of arrays dannyallen PHP 2 10-11-04 04:04 AM
linking to iframe not working :( j0d JavaScript 5 01-19-04 09:14 PM


All times are GMT -5. The time now is 09:57 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)