Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
updating fields not working
Old 03-13-2008, 08:48 PM updating fields not working
Junior Talker

Posts: 2
Trades: 0
Hi there, I am stumped on what is wrong with this update script, Hopefully someone more knowledgeable than myself can point me in the right direction
update.php
PHP Code:
<?php
require ('db.php');
 
$sql "SELECT * FROM profiles WHERE `id` = " mysql_real_escape_string$_GET['id'] );
 
mysql_select_db $database$connect );
 if ( @
mysql_query $sql ) )
 {
  
$query mysql_query $sql );
  
$row mysql_fetch_assoc $query );
  if ( 
array_key_exists '_submit_check'$_POST ) )
  {
   if ( 
$_POST 'f_name' ] != '' && $_POST 'l_name' ] != '' && $_POST 'description' ] != '' )
   {
    
mysql_select_db $database$connect );
    
$query =  "UPDATE 
       `profiles` 
      SET
       `f_name` = " 
mysql_real_escape_string$_POST 'f_name' ] ) . "
       `l_name` = " 
mysql_real_escape_string$_POST 'l_name' ] ) . "
       `description` = " 
mysql_real_escape_string$_POST 'description' ] ) . "
      WHERE
       `id` = " 
mysql_real_escape_string$_GET[`id`] );
 
 
    if ( @
mysql_query $query ) )
    {
     
$success 'profile updated successfully!';
    }
    else {
     die ( 
mysql_error () );
    }
   }
   else {
    echo 
'Please ensure that you have entered some data!';
   }
  }
 }
 else {
  die ( 
mysql_error () );
 }
 
 if ( isset ( 
$success ) ) {
  echo 
$success;
 }
 else {
?>
form to update
HTML Code:
<form id="update" name="update" method="post" action="<?=$_SERVER['PHP_SELF']?>">
  <input type="hidden" name="_submit_check" value="1"/> 
  Change First Name:<br />
  <input name="f_name" type="text" id="f_name" size="55" value="<?php if ( isset ( $_POST['f_name'] ) ){ echo $_POST['f_name']; }else{ echo $row['f_name'];} ?>" />
   <br /><br />
   Change Lirst Name:<br />
  <input name="l_name" type="text" id="l_name" size="55" value="<?php if ( isset ( $_POST['l_name'] ) ){ echo $_POST['l_name']; }else{ echo $row['l_name'];} ?>" />
   <br /><br />
  Description:<br />
  <textarea name="description" cols="55" rows="5" id="description"><?php if ( isset ( $_POST['description'] ) ){ echo $_POST['description']; }else{ echo $row['description'];} ?></textarea>
   <br /><br />
  <input type="submit" name="Submit" value="Submit" />
 </form>
end of update.php
PHP Code:
<?php ?>
this is the error message I get
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"
any help here would be appreciated
gettingitslowly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-13-2008, 10:07 PM Re: updating fields not working
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The error is a SQL query syntax error meaning that you have left out quoting, cammas, etc. Also noticed some unessecary spaces in your PHP vars. Replace the two SQL queries with the updated versions below and that should solve your problem.

PHP Code:
$sql "
  SELECT *
  FROM profiles
  WHERE id = '" 
mysql_real_escape_string($_GET['id']) . "'
"
;
 
 
$query "
  UPDATE profiles
  SET
    f_name = '" 
mysql_real_escape_string($_POST['f_name']) . "',
    l_name = '" 
mysql_real_escape_string($_POST['l_name']) . "',
    description = '" 
mysql_real_escape_string($_POST['description']) . "'
  WHERE id = '" 
mysql_real_escape_string($_GET['id']) . "'
"

__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-13-2008, 10:22 PM Re: updating fields not working
Junior Talker

Posts: 2
Trades: 0
Thankyou for your speedy reply mgraphic, your solution has advanced the end resut a bit, which i truely appreciate, however the database itself still does not update, the script runs through to completion without errors and gives a confirmation that the profile has been updated but alas the database stays unchanged.

Last edited by gettingitslowly; 03-13-2008 at 10:24 PM.. Reason: fixed a typo ...oooops
gettingitslowly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to updating fields not working
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14579 seconds with 12 queries