[PHP-DB] DB will INSERT wont UPDATE..error in code?

2004-10-12 Thread Matthew Kiehne
forgive the poor structure of my code, im pretty new at this and havent
figured out exactly what it should be formed like to look its best, anyway
whenever i run this code it works on inserting new information into the
database, however when i want to update the SQL query returns an output like
this 'SQL statement = UPDATE badges (staff,ttlpst,mnthpst,ttlicon,mnthicon)
VALUES ('1','1','1','/ribbons','/ribbons') WHERE fid=2' but when i try to
pull the information from the database it hasnt updated, can someone help me
out with this...im not sure why it wouldnt update even though the statement
looks correct.

 if (empty($form_status)){

$staff = $HTTP_POST_VARS[staff];
$ttlpst = $HTTP_POST_VARS[ttlpst];
$mnthpst = $HTTP_POST_VARS[mnthpst];
$ttlicon = $HTTP_POST_VARS[ttlicon];
$mnthicon = $HTTP_POST_VARS[mnthicon];

 $exists = SELECT * FROM badges WHERE fid = $fid;

 $result = mysql_query($exists);

 if (mysql_num_rows($result) == 0)
 {
 $sql = INSERT INTO badges (fid,staff,ttlpst,mnthpst,ttlicon,mnthicon)
VALUES ('$fid','$staff','$ttlpst','$mnthpst','$ttlicon','$mnthicon');
 db_query($sql);
 $form_status = span class=\msgUpdated\Description
Updated!/spanbr\n;
 }
 else
 {
 $sql = UPDATE badges SET staff = '.$HTTP_POST_VARS[staff].' ttlpst =
'.$HTTP_POST_VARS[ttlpst].' mnthpst = '.$HTTP_POST_VARS[mnthpst].'
ttlicon = '.$HTTP_POST_VARS[ttlicon].' mnthicon =
'.$HTTP_POST_VARS[mnthicon].' WHERE fid = $fid;
 db_query($sql);
 $form_status = span class=\msgUpdated\Description
Updated!/spanbr\n;
 }
}

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] DB will INSERT wont UPDATE..error in code?

2004-10-12 Thread Graham Cossey
I'm no 'expert' (opening myself up for much criticism here) but try the
following:

(I'm assuming you are setting $fid somewhere)

 if (empty($form_status))
 {
$staff = $_POST[staff];
$ttlpst = $_POST[ttlpst];
$mnthpst = $_POST[mnthpst];
$ttlicon = $_POST[ttlicon];
$mnthicon = $_POST[mnthicon];

$exists = SELECT * FROM badges WHERE fid = $fid;
$result = mysql_query($exists) or die(Query1 failed: .mysql_error());
if (mysql_num_rows($result) == 0)
{
  $sql = INSERT INTO badges
 (fid,staff,ttlpst,mnthpst,ttlicon,mnthicon)
  VALUES ('$fid','$staff','$ttlpst','$mnthpst','$ttlicon','$mnthicon');
  echo Insert query = $sql;
  mysql_query($sql) or die(Query2 failed: .mysql_error());
  $form_status = span class=\msgUpdated\Description
Inserted!/spanbr\n;
}
else
{
  $sql = UPDATE badges
  SET staff = '$staff'
  ttlpst ='$ttlpst'
  mnthpst = '$mnthpst'
  ttlicon = '$ttlicon'
  mnthicon = '$mnthicon'
  WHERE fid = $fid;
  echo Update query = $sql;
  mysql_query($sql) or die(Query3 failed: .mysql_error());
  $form_status = span class=\msgUpdated\Description
Updated!/spanbr\n;
}
 }

The echos will at least show the SQL being executed which could give a clue
to the problem.

You could even just set the $sql within the if...else... and use the same
mysql_query($sql) for both instances:

if (condition1)
{
$sql = query statement 1;
}else{
$sql = query statement 2;
}
mysql_query($sql);

HTH

Graham

 -Original Message-
 From: Matthew Kiehne [mailto:[EMAIL PROTECTED]
 Sent: 12 October 2004 21:09
 To: [EMAIL PROTECTED]
 Subject: [PHP-DB] DB will INSERT wont UPDATE..error in code?


 forgive the poor structure of my code, im pretty new at this and havent
 figured out exactly what it should be formed like to look its best, anyway
 whenever i run this code it works on inserting new information into the
 database, however when i want to update the SQL query returns an
 output like
 this 'SQL statement = UPDATE badges
 (staff,ttlpst,mnthpst,ttlicon,mnthicon)
 VALUES ('1','1','1','/ribbons','/ribbons') WHERE fid=2' but when i try to
 pull the information from the database it hasnt updated, can
 someone help me
 out with this...im not sure why it wouldnt update even though the
 statement
 looks correct.

[snip]

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] DB will INSERT wont UPDATE..error in code?

2004-10-12 Thread Jason Wong
On Wednesday 13 October 2004 04:08, Matthew Kiehne wrote:

 database, however when i want to update the SQL query returns an output
 like this 'SQL statement = UPDATE badges
 (staff,ttlpst,mnthpst,ttlicon,mnthicon) VALUES
 ('1','1','1','/ribbons','/ribbons') WHERE fid=2' but when i try to pull the
 information from the database it hasnt updated, can someone help me out
 with this...im not sure why it wouldnt update even though the statement
 looks correct.

I don't see how you get the above output when $sql is defined like so:

  $sql = UPDATE badges SET staff = '.$HTTP_POST_VARS[staff].' ttlpst =
 '.$HTTP_POST_VARS[ttlpst].' mnthpst = '.$HTTP_POST_VARS[mnthpst].'
 ttlicon = '.$HTTP_POST_VARS[ttlicon].' mnthicon =
 '.$HTTP_POST_VARS[mnthicon].' WHERE fid = $fid;

echo $sql;

Make use of mysql_error().

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
There are three things I always forget.  Names, faces -- the third I
can't remember.
-- Italo Svevo
*/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] DB will INSERT wont UPDATE..error in code?

2004-10-12 Thread Matthew Kiehne
sorry this is the output i meant to post
SQL statement = UPDATE badges SET staff = '1' ttlpst = '1' mnthpst = '1'
ttlicon = '/trophies' mnthicon = '/ribbons' WHERE fid = 61

and this is the error i getyet i still cant for the life of me find a
problem

Update query = UPDATE badges SET staff = '1' ttlpst ='1' mnthpst = '1'
ttlicon = 'trophies' mnthicon = 'medals' WHERE fid = 61Query3 failed: You
have an error in your SQL syntax near 'ttlpst ='1' mnthpst = '1' ttlicon =
'trophie' at line 3

thanks for your help

--
Advanced Forums, For Free! - Speak EZ forums (
http://www.speakezforums.com )
Jason Wong [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Wednesday 13 October 2004 04:08, Matthew Kiehne wrote:

  database, however when i want to update the SQL query returns an output
  like this 'SQL statement = UPDATE badges
  (staff,ttlpst,mnthpst,ttlicon,mnthicon) VALUES
  ('1','1','1','/ribbons','/ribbons') WHERE fid=2' but when i try to pull
the
  information from the database it hasnt updated, can someone help me out
  with this...im not sure why it wouldnt update even though the statement
  looks correct.

 I don't see how you get the above output when $sql is defined like so:

   $sql = UPDATE badges SET staff = '.$HTTP_POST_VARS[staff].' ttlpst
=
  '.$HTTP_POST_VARS[ttlpst].' mnthpst =
'.$HTTP_POST_VARS[mnthpst].'
  ttlicon = '.$HTTP_POST_VARS[ttlicon].' mnthicon =
  '.$HTTP_POST_VARS[mnthicon].' WHERE fid = $fid;

 echo $sql;

 Make use of mysql_error().

 --
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-db
 --
 /*
 There are three things I always forget.  Names, faces -- the third I
 can't remember.
 -- Italo Svevo
 */


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] DB will INSERT wont UPDATE..error in code?

2004-10-12 Thread Jason Wong
Please do not top-post.

On Wednesday 13 October 2004 10:26, Matthew Kiehne wrote:
 sorry this is the output i meant to post
 SQL statement = UPDATE badges SET staff = '1' ttlpst = '1' mnthpst = '1'
 ttlicon = '/trophies' mnthicon = '/ribbons' WHERE fid = 61

 and this is the error i getyet i still cant for the life of me find a
 problem

 Update query = UPDATE badges SET staff = '1' ttlpst ='1' mnthpst = '1'
 ttlicon = 'trophies' mnthicon = 'medals' WHERE fid = 61Query3 failed: You
 have an error in your SQL syntax near 'ttlpst ='1' mnthpst = '1' ttlicon =
 'trophie' at line 3

If you look up the manual entry for UPDATE, you'll find that you're missing 
the commas separating the columns.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
I'm free -- and freedom tastes of reality.
-- The Who
*/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] DB will INSERT wont UPDATE..error in code?

2004-10-12 Thread Matthew Kiehne
Jason Wong [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 If you look up the manual entry for UPDATE, you'll find that you're
missing
 the commas separating the columns.

 --
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-db
 --
 /*
 I'm free -- and freedom tastes of reality.
 -- The Who
 */

Thanks I dont know how i missed that! Gave it a go and it works perfectly,
thanks again

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php