Current location: Hot Scripts Forums » Programming Languages » PHP » Some reason its not updating


Some reason its not updating

Reply
  #1 (permalink)  
Old 06-12-09, 04:52 AM
aburrows182 aburrows182 is offline
Newbie Coder
 
Join Date: Jul 2004
Location: Ashtead, Surrey, UK
Posts: 61
Thanks: 0
Thanked 1 Time in 1 Post
Some reason its not updating

Tested it and for some reason it just wont update, its running the query as i echoed the query.

PHP Code:

<?php

$id 
1;

 if (isset(
$_POST['id'])){
 
     foreach(
$_POST as $name => $value){
    
        
mysql_query("UPDATE languagefiletest SET ".$name." = ".$value." WHERE id = ".$id."");
        
    }
 
 } else {
 
     
$result mysql_query("SELECT * FROM languagefiletest WHERE id = $id") or die(mysql_error());
    
    while (
$row mysql_fetch_array($resultMYSQL_ASSOC)){
    
        echo 
'<form action="'.$PHP_SELF.'" method="post">';
        echo 
'<input type="hidden" value="'.$row['id'].'"/>';
        
        echo 
'<ol>';
        
            foreach (
$row as $key => $value){
            
                echo 
'<li><label for="'.$key.'">'.$key.'</label>: <input type="text" name="'.$key.'" value="'.$value.'" /></li>';
            
            }
            
            echo 
'<input type="submit"/>';
            echo 
'</form>';
            echo 
'</ol>';
    
    }
    
    
 
 }

?>
Reply With Quote
  #2 (permalink)  
Old 06-12-09, 07:33 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
You need to quote the value.
I also changed and quoted the value of id, just in case it's value isn't strictly numeric.
PHP Code:

<?php
$id 
1;

 if (isset(
$_POST['id'])){

     foreach(
$_POST as $name => $value){

        
mysql_query("UPDATE languagefiletest SET ".$name." = '".$value."' WHERE id = '".$_POST['id']."'");

    }

 } else {

     
$result mysql_query("SELECT * FROM languagefiletest WHERE id = $id") or die(mysql_error());

    while (
$row mysql_fetch_array($resultMYSQL_ASSOC)){

        echo 
'<form action="'.$PHP_SELF.'" method="post">';
        echo 
'<input type="hidden" value="'.$row['id'].'"/>';

        echo 
'<ol>';

            foreach (
$row as $key => $value){

                echo 
'<li><label for="'.$key.'">'.$key.'</label>: <input type="text" name="'.$key.'" value="'.$value.'" /></li>';

            }

            echo 
'<input type="submit"/>';
            echo 
'</form>';
            echo 
'</ol>';

    }



 }

?>
__________________
Jerry Broughton
Reply With Quote
  #3 (permalink)  
Old 06-12-09, 07:44 AM
aburrows182 aburrows182 is offline
Newbie Coder
 
Join Date: Jul 2004
Location: Ashtead, Surrey, UK
Posts: 61
Thanks: 0
Thanked 1 Time in 1 Post
Thanks Jerry!
Reply With Quote
  #4 (permalink)  
Old 06-12-09, 10:02 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your welcome.
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


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
League Table Updating Script j-a-m-i-n PHP 4 11-24-06 05:17 PM
need script for updating updating concert dates rebelbwb Script Requests 1 03-16-06 08:51 AM
Resource not accepted - and the reason? mateuszchol Hot Scripts Forum Questions, Suggestions and Feedback 0 08-23-05 03:24 PM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 12:11 AM
getting -2147217900 error while inserting and updating skchakri ASP 3 09-20-03 10:34 AM


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