Update Table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Update Table

Post by mariolopes »

Hi
I need to update one table. I have one grid and I want to refresh my webpage after updating the table. I use a form and what i have to write in action of that form?
Thank you
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Update Table

Post by aravona »

Can you please post up your form?
Last edited by aravona on Tue Jan 12, 2010 7:26 am, edited 1 time in total.
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Update Table

Post by mariolopes »

Here is my code
<?php
$mysql_id = mysql_connect('localhost', 'curso', '123');
mysql_select_db('vendas',$mysql_id);
$query='Select * from noite';
$result=mysql_query($query);
?>
/*construçao da tabela */
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<table border="1">
<?php
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><?php print $row['Nome'];?></td>
<td><?php print $row['Idade'];?></td>
</tr>
<?php
}
?>
</table>
<form action="selecciona.php" method="get">
<p><input type="text" name="Idade"/></p>
<p><input type="submit" value="Enviar!" /></p>
</form>

</html>
I need to update the field idade in my table
Thank you
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Update Table

Post by aravona »

Ok your sending your data to the selecciona.php?

If you want to update your table in your database using this form you need to use something like

Code: Select all

update [table name] where [field] = [what you want to update it with]
about updating
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Update Table

Post by mariolopes »

Yes I know the sql instrution, but where i have to write in my code?
Benwahballz
Forum Commoner
Posts: 25
Joined: Mon Sep 21, 2009 12:54 pm

Re: Update Table

Post by Benwahballz »

mariolopes wrote:Yes I know the sql instrution, but where i have to write in my code?

You need to write it in your code on the page that the data is being submitted to. In this case, it appears that it would be selecciona.php (as noted by aravona)
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Update Table

Post by mariolopes »

Sorry guys
I think i mispresent my problem. Selecciona.php is the unique file I have. Is the file I show.My question is where inside my file, selecciona.php, i have to write the update code.
(before the </html> tag?)
Benwahballz
Forum Commoner
Posts: 25
Joined: Mon Sep 21, 2009 12:54 pm

Re: Update Table

Post by Benwahballz »

If you want the updated data to be included in the table of names (Nome?), you need to perform the update BEFORE the select statment.
Post Reply