Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Form update don't work

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Form update don't work

Postby catellor93 » Thu Oct 25, 2012 8:09 am

Hi,
I created the form for editing a record in a mysql table via PHP. The module is okay but does not update the data. The result is positive, do not give me no errors but does not update the data. I do not understand where is the problem, I'll post the code below:

Code: Select all
<?php
session_start();
include("../config.php");
$connessione = mysql_connect($host, $user, $pass);
$select_db = mysql_select_db($db);
?>
<html>
<head>
<title>Edit - JollyLab Manager</title>
</head>
<body>
<?php
$id = $_GET['id'];
if (isset($_GET['modifica'])) {
   $id = $_GET['id'];
   $newarticolo = ucwords(ucfirst(addslashes($_GET['newarticolo'])));
   $newnserie = ucwords(ucfirst(addslashes($_GET['newnserie'])));
   $newguasto = ucwords(ucfirst(addslashes($_GET['newguasto'])));
   $newintervento = ucwords(ucfirst(addslashes($_GET['newintervento'])));
   $newnote = $_GET['newnote'];
   $que = "UPDATE articolo SET articolo='$newarticolo', nserie='$newnserie', guasto='$newguasto', intervento='$newintervento', note='$newnote' WHERE id='$id'";
   $risultato = mysql_query($que);
   if ($risultato) {
      echo "Modifica effettuata.";
      header("refresh:1;url=../view.php");
   } else { echo "Modifica non effettuata. Problema: " . mysql_error(); }
} else {
   $query = "SELECT * FROM articolo WHERE id='$id'";
   $ris = mysql_query($query);
   while ($row = mysql_fetch_row($ris, MYSQL_ASSOC)) {
?>
   <form method="GET" action="#">
      <table>
      <tr><td>Articolo:</td><td><input type="text" name="newarticolo" size="60" value="prova di testo"></td></tr>
      <tr><td>N° Serie:</td><td><input type="text" name="newnserie" value="<?php echo $row['nserie']; ?>"></td></tr>   
      <tr><td>Guasto:</td><td><input type="text" name="newguasto" size="60" value="<?php echo $row['guasto']; ?>"></td></tr>
      <tr><td>Intervento:</td><td><input type="text" name="newintervento" size="60" value="<?php echo $row['intervento']; ?>"></td></tr>
      <tr><td>Note:</td><td><textarea id="eff" name="newnote" cols="46" rows="5"><?php echo $row['note']; ?></textarea></td></tr>
      <tr><td><input type="submit" name="modifica" value="Modifica"></td></tr>
      <input type="hidden" name="id" value="<?php echo $id; ?>">
      </table>
   </form>   
<?php
   }
}
?>
</body>
</html>


Sorry for my english, i have used translator of google.
Thanks in advance.
catellor93
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Oct 25, 2012 7:59 am

Re: Form update don't work

Postby egami » Thu Oct 25, 2012 8:34 am

Your fields will break if there are any special chars in the values.

use mysql_real_escape_string(ucwords(ucfirst(addslashes($_GET['newnserie']))));
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Form update don't work

Postby catellor93 » Thu Oct 25, 2012 8:39 am

I did what you said, but the same does not update the data.
catellor93
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Oct 25, 2012 7:59 am

Re: Form update don't work

Postby MeroD » Fri Oct 26, 2012 12:21 am

Try tracing the error from mysql:

if (!$risultato ) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $que;
die($message);
}
MeroD
New php-forum User
New php-forum User
 
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron