Log in

View Full Version : Populate form form MySQL data



Rob (SA)
04-10-2009, 11:11 AM
Hi Folks,

I am trying to produce a webpage that will show numbers /text in tables on a webpage.

The data is to be in MySQL database.

If there is somebody that has already doen this your assitance would be most welocme.

My knowledge of this process is next to zero.

I look forward to any replys, examples, help.

Kind Regard
ROb

AdrielGreene
04-10-2009, 10:33 PM
Are you looking to fill a form with your data or fill your data with a form?
Will you be using PHP to contact your DB? Do you have PHPMyAdmin?

http://www.w3schools.com/php/php_mysql_intro.asp

This site has some good guides. To call data from the DB you can use the SELECT function... although I am stuck on a SELECT function myself.

Rob (SA)
04-11-2009, 05:00 AM
Thanks for the speedy reply.

I have a php forms that will send info to MySQL.

Once it is there I am trying to create webpages that will populate using data from the MySQL Database and in some instances additional new data directly typed in.

So to answer your quetion I guess it would be both.

Thanks for the link I will have a look at it.

I have managed to get my page to look something like this www.gnjgf.co.za/GolfMembers.html

Regards
Rob

borris83
04-11-2009, 01:30 PM
Hi, Right now the table displays the php variables and not the actual values...

I think the data has been inserted to database with php variables and that is why it shows the variable names there...

I have just used a part of variables as example to show how it should be inserted:


$Surname=$_POST['Surname'];
$Name=$_POST['Name'];

$query_string = "INSERT INTO the_table_name (field_surname, field_name) VALUES ('$Surname', '$Name') ";

$query = mysql_query($query_string);

if(!$query){
die(mysql_error());
}
else
{
echo "Entries successfully updated";
}

Make sure that you change the table_name into the actual table name in your database and field_surname, field_name to the respective field names in the table...


Also, the table in the page is too long... Make sure that you actually split it into several rows instead of 1 row

Rob (SA)
04-11-2009, 03:01 PM
I have made some changes and cosmetically it is already looking better.

I will sort out the database side and see if I can get the desired result.

Regards
Rob

forum_amnesiac
04-14-2009, 01:00 PM
Hi

Because of the way that PHP immediately executes I use HTML forms to collect the data/amendments and then have a form action="somecode.php" that updates the MYSQL database.

I have recently written some code that takes all the selected records from the database, stores it in a PHP array and converts that array into a javascript array.

Using this array I can display all the records and fields, using array.split, or I can retrieve an individual record, display its current values, for amendment, and the updates the MYSQL table with the changes.

If this is of interest then let me know

Rob (SA)
04-14-2009, 06:41 PM
Hi,

Thanks for this reply and it sounds very interesting.

As I am very new to the whole programming side of html and php I would love to consider all my options and learn more about what you have done.

Kind Regards
Rob

forum_amnesiac
04-16-2009, 09:32 AM
I hav sent you a PM, check your inbox

Rob (SA)
04-16-2009, 03:29 PM
Hi,

Thanks for the info.

I will have a look at the PM -and give feed back

Regards
Rob

Rob (SA)
04-17-2009, 07:30 PM
Hi Folks,

I have managed to get my page www.gnjgf.co.za/GolfMembers.html to look ok yet need to find out if this information below is correct will populate the page ?


<!--------------------------------------------------------------------->
<! THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE >
<!--------------------------------------------------------------------->

<table border=3 width="35%" cellspacing=0 style="background-color:#FFFFFF;">

<!--------------------------------------------------------------------->
<!MAKE CHANGES TO THIS SECTION IF YOU WANT THE PAGE HEADING/s TO CHANGE>
<!--------------------------------------------------------------------->

<caption>
<font style>&nbsp</font>
</caption>
<caption>
<b><font style="font-size:20px" color="#00008B" face="Arial">
GAUTENG NORTH JUNIOR GOLF FOUNDATION</font><b>
</caption>
<caption>
<font style="font-size:16px" color="#00008B" face="Arial">
MEMBERSHIP LIST</font>
</caption>
<caption>
<font style>&nbsp</font>
</caption>

<!--------------------------------------------------------------------->
<! CHANGE COLUMN HEADING/s OF THE TABLE HERE >
<!--------------------------------------------------------------------->

<tr>
<th><td align="center" valign="middle" width="100" height="30"><b><font style="font-size:10px" color="#00008B" face="Arial">SURNAME</font></b></td></th>
<th><td align="center" valign="middle" width="100" height="30"><b><font style="font-size:10px" color="#00008B" face="Arial">NAME</font></b></td></th>
<th><td align="center" valign="middle" width="100" height="30"><b><font style="font-size:10px" color="#00008B" face="Arial">DATE OF BIRTH</font></b></td></th>
<th><td align="center" valign="middle" width="100" height="30"><b><font style="font-size:10px" color="#00008B" face="Arial">IDENTITY NO.</font></b></td></th>
<th><td align="center" valign="middle" width="100" height="30"><b><font style="font-size:10px" color="#00008B" face="Arial">CELL PHONE</font></b></td></th>
<th><td align="center" valign="middle" width="100" height="30"><b><font style="font-size:10px" color="#00008B" face="Arial">HOME PHONE</font></b></td></th>
<th><td align="center" valign="middle" width="100" height="30"><b><font style="font-size:10px" color="#00008B" face="Arial">WORK PHONE</font></b></td></th>
<th><td align="center" valign="middle" width="100" height="30"><b><font style="font-size:10px" color="#00008B" face="Arial">&nbsp &nbsp FAX &nbsp &nbsp</font></b></td></th>
<th><td align="center" valign="middle" width="100" height="30"><b><font style="font-size:10px" color="#00008B" face="Arial">E-MAIL</font></b></td></th>
</tr>

<!--------------------------------------------------------------------->
<! THIS SECTION IS WHAT CALLS IT FROM THE DATABASE TABLE >
<!--------------------------------------------------------------------->

<?
$MySQLhost="local****";
$MySQLusername="******h";
$MySQLpassword="f********n";
$MySQLdatabase="egh***_members";
$dbconnect = mysql_connect($MySQLhost,$MySQLusername,$MySQLpass word)
or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($MySQLdatabase)
or die ("Could not select database because ".mysql_error());

$Surname=.$_POST['Surname'].;
$Name=.$_POST['Name'].;
$Date of Birth=.$_POST['Date_of_Birth'].;
$Identity Number=.$_POST['Identity_No'].;
$Cell_Phone=.$_POST['Cell_Phone'].;
$Home_Phone=.$_POST['Home_phone'].;
$Work Phone=.$_POST['Work_phone'].;
$Fax=.$_POST['Fax'].;
$Email=.$_POST['Email'];
$query = mysql_query("INSERT INTO MEMBERS (Surname, Name, Date_of_Birth, Identity_No, Cell_Phone, Home_phone, Work_phone, Fax, email)
VALUES
('$Surname','$Name','$Date_of_Birth','$Identity_No ','$Cell_Phone', '$Home_phone','$Work_phone','$Fax','$email')", $dbconnect);
exit;
}
?>

Regards
Rob

borris83
04-18-2009, 01:55 AM
This code will not populate the page but it will insert values into the database from the data submitted using form..

Instead, modify the following code and use it


<?php

$MySQLhost="local****";
$MySQLusername="******h";
$MySQLpassword="f********n";
$MySQLdatabase="egh***_members";
$dbconnect = mysql_connect($MySQLhost,$MySQLusername,$MySQLpass word)
or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($MySQLdatabase)
or die ("Could not select database because ".mysql_error());

$query = mysql_query("SELECT * FROM MEMBERS" );

if(!$query ){die(mysql_error());}


while ($result = mysql_fetch_array($query)){



#### Use the two lines below as example and populate other fields...
####### Make sure that you type <?php echo $result['Field name ']; ?> in every line
?>
<tr>
<td align="center" valign="middle" width="100" height="30"><b><?php echo $result['Surname']; ?> </b></td>
<td align="center" valign="middle" width="100" height="30"><b><?php echo $result['Name']; ?> </b></td>



</tr>
<?php

}

?>

Rob (SA)
04-18-2009, 07:01 AM
Hi,

Thanks for your reply.

I see at the end of each example line you use </th>

Not being a fundie on writing this sort of programs but rather a cut and paste guy and learning fast in the process should this not be removed as it is between the <td> ...</td> statements that you want me to place the lines

I thought </th> closes the heading

Please see this not as a crit but a question as I need to enter it and do not want to make to many errors

Regards
Rob

borris83
04-18-2009, 10:06 AM
hi.. sorry, that was my mistake.. I copied and pasted few things from your code and forgot to clear out the </th> which u had used for table header

Now I edited my post and removed < /th>

Rob (SA)
04-18-2009, 10:48 AM
Hi Borris,

No problem this is how I learn.

I have published my page at www.gnjgf.co.za/GolfMembers.php however the rows do not populate.

This could be one of three things:

Either my table is wrong
Either my posting to table is wrong or
Maybe my fetching from the table is wrong - we have just worked on the fetching side.

Any ideas would be welcome

regards
Rob