Page 1 of 1

Update Table

Posted: Tue Jan 12, 2010 7:18 am
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

Re: Update Table

Posted: Tue Jan 12, 2010 7:21 am
by aravona
Can you please post up your form?

Re: Update Table

Posted: Tue Jan 12, 2010 7:22 am
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

Re: Update Table

Posted: Tue Jan 12, 2010 7:29 am
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

Re: Update Table

Posted: Tue Jan 12, 2010 11:08 am
by mariolopes
Yes I know the sql instrution, but where i have to write in my code?

Re: Update Table

Posted: Tue Jan 12, 2010 11:19 am
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)

Re: Update Table

Posted: Tue Jan 12, 2010 11:30 am
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?)

Re: Update Table

Posted: Tue Jan 12, 2010 11:37 am
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.