Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL Db is not updating from html form with php script


MySQL Db is not updating from html form with php script

Reply
  #1 (permalink)  
Old 07-16-11, 03:32 AM
observ observ is offline
New Member
 
Join Date: Jul 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL Db is not updating from html form with php script

Hi,

I am trying to update data from a column in a database using a php script. But for some reason it doesn't update the database, but i get no error feedback.
So first i select a random entry from the database and i add it as a parameter to the next page. This page contains the form and the php script to get the parameter:



PHP Code:

     <?

  $server 
"myserver";
  
$username "myusername";
  
$password "mypass";
  
$database "dbname";
  
$con mysql_connect($server$username$password);
  
$ok mysql_select_db($database$con);
 
 
' ' htmlspecialchars($_GET["param"]) . '';
 
if(empty(
$_GET))
    echo 
"<h2>The request is invalid</h2>";
else
    
$param_code = ($_GET[param]); 
 
?>
    <form name="form1" method="post" action="insert.php">
        <input type="text" name="code" disabled value="<? print_r ($param_code); ?>">
        <input type="submit" name="submit" id="submit" value="Submit">
    </form>
here is the insert.php:


PHP Code:

<?

  $server 
"myserver";
  
$username "myusername";
  
$password "mypass";
  
$database "dbname";
  
$con mysql_connect($server$username$password);
  
$ok mysql_select_db($database$con);
 
if(isset(
$_POST['submit']))
{
   
$submit $_POST['code'];
}
 
mysql_query(" UPDATE table_name SET code_used= '0' WHERE param_code ='{$submit}' "$con) or die (mysql_error());
 
mysql_close($con);
 
     
?>
My database is very simple. It has only one table and 3 columns.
PHP Syntax (Toggle Plain Text)
Code:
| id | param_code | code_used|
| 1  | abc2qsaa   |     1    |  --> This is a not used code
| 2  | safd3235   |     0    |  --> This is a used code.
Reply With Quote
  #2 (permalink)  
Old 07-22-11, 06:11 AM
maneetpuri maneetpuri is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

The code looks fine, try echo the update query on the screen, it might give some clue.

Cheers,


~Maneet
__________________
Maneet Puri
India Web Site Design Services
PHP Web Development
Reply With Quote
  #3 (permalink)  
Old 08-31-11, 11:10 PM
lufeceba lufeceba is offline
New Member
 
Join Date: Aug 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
check your form

Hi,

if you set the text field as disabled:

Code:
<input type="text" name="code" disabled value="<? print_r ($param_code); ?>">
then your insert.php script won't ever receive the variable, consequently your UPDATE query won't work because your are trying to match param_code field with an empty string

BTW. You should avoid using short tags for PHP code!

Regards,
Reply With Quote
Reply

Bookmarks

Tags
mysql, mysql problems, php script, update


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php mysql update script jaylam PHP 6 10-15-10 03:41 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
HTML Form 1 -> Perl -> return response to HTML form 2 Oleks Perl 13 10-18-06 04:59 PM
MySQL PHP Script request dflowers Script Requests 0 04-26-06 01:17 AM


All times are GMT -5. The time now is 08:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.