TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-04-2009, 05:18 PM   #1 (permalink)
The Visitor
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
calexandru is on a distinguished road
Default update table with php form

Hello all.

I try to create a graphical interface, with php and mysql (db). First time the database was in excel.I import from excel in mysql, I created a page to read the table, and now I try to create a page for modify table, but I do not know very well how can i create. Anybody can help me?

this is view.php
PHP Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>C.A.S. Angajator 9.5% | Vizualizare</title>

<left>
<?php include("meniu.html"); ?>
</left>



<center>
<?PHP
//Legatura fisier baza de date
include 'conectare.php';

$con mysql_connect("localhost"$user_name$password);

mysql_select_db($database$con);

$result mysql_query("SELECT * FROM casangaj95");
    echo 
"<table border='1'>
        <tr>
            <th>Coloana A</th>
            <th>Coloana B</th>
            <th>Coloana C</th>
        </tr>"
;
        while (
$row mysql_fetch_array($result)) {
            echo 
"<tr>";
            echo 
"<td>" $row['Field1'] . "</td>";
            echo 
"<td>" $row['Field2'] . "</td>";
            echo 
"<td>" $row['Field3'] . "</td>";
            echo 
"</tr>";
        }
    echo 
"</table>";


    
mysql_close($con);

?> 
</center>
and modify.php

PHP Code:
<?
// Connect database.
$host="localhost"// Host name.
$db_user="root"// MySQL username.
$db_password=""// MySQL password.
$database="excel"// Database name.
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);

// Select all data records in table "name_list" and put them into $result.
$result=mysql_query("select * from casangaj95 order by Field1");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="update.php">
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td align="center" bgcolor="#FFCC00"><strong>Field1</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Field2</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Field3</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Field4</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Field5</strong></td>
<td align="center" bgcolor="#FFCC00"><strong>Field6</strong></td>
</tr>
<?
// Fetch record rows in $result by while loop and put them into $row.
while($row=mysql_fetch_assoc($result)){
?>
<tr>
<td bgcolor="#FFFFCC"><? echo $row['Field1']; // Show record's ID ?></td>
<td bgcolor="#FFFFCC"><input name="name_<? echo $row['Field1']; ?>" type="text" id="name_<? echo $row['Field1']; ?>" value="<? echo $row['name']; ?>" /></td>
</tr>
<? // End while loop. ?>
</table>
<input type="submit" name="Submit" value="Update" />
</form>
</body>
</html>
and update.php
PHP Code:
<?
if($_POST['Submit']){ // If receive Submit button variable.

// Connect database.
$host="localhost"// Host name.
$db_user="root"// MySQL username.
$db_password=""// MySQL password.
$database="excel"// Database name.
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);

// Select all data records in table "name_list" and put them into $result.
$result=mysql_query("select id from name_list order by id asc");

// Fetch record rows in $result by while loop and put them into $row.
while($row=mysql_fetch_assoc($result)){
// Get the posted value "name_ID value" from form.php. This variable change it's value by while loop.
$name=$_POST["name_".$row[id]];

// Update field "name", matching with "id" value by while loop.
mysql_query("update name_list set name='$name' where id='$row[id]'");
}
echo 
"--- Update Complete ---";
}
?>
I'm a very beginner :) The table is casangaj95 and the field that i want to modify are Field1 Field2 Field3 etc..Field 21. The update.php ins't configured for my db

Thanks a lot
calexandru is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
feedback on my class please frostyboy33 Advanced PHP Programming 7 10-22-2012 09:12 AM
Basic php form update mysql script dp2 Absolute Beginners 3 03-11-2009 04:06 PM
Databse structure Village Idiot TalkPHP Developer Team 3 01-16-2009 10:31 PM
This project has begun! Village Idiot TalkPHP Developer Team 40 01-01-2009 04:29 AM
email fill in form help? PHP sacred_tinker Absolute Beginners 19 05-28-2008 05:58 AM


All times are GMT. The time now is 09:00 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design