SQL ISSUE

I have a program that received data from a string and using that data updated a mysql table. Should be simple but for some reason its not working. It is also not returning any errors. I hope someone here can see something I cant.

[php]

<?php mysql_connect("#####", "#####_#####", "#####") or die(mysql_error()); mysql_select_db("#####_#####") or die(mysql_error()); $data = $_GET['data']; $uid = $_GET['uid']; $query = "SELECT * FROM phpbb_users WHERE `key` = '".$uid."'" or die('Query failed: ' . mysql_error( )); $result = mysql_query($query) or die('Status failed: ' . mysql_error( )); $line = mysql_fetch_array($result, MYSQL_ASSOC); echo $line['`key`']; if ($line['`key`'] != $uid) { echo "no match"; exit; } if ($line['`key`'] == $uid) { echo "match"; $insert = 'UPDATE `phpbb_users` SET `iwstatus`= "'.($data).'" WHERE `key`="'.mysql_escape_string($uid).'"'; $add_member = mysql_query($insert) or die('Update failed: ' . mysql_error( )); } ?>

[/php]

The URL Im using is it is a dead link on purpose, i dont use mysite.com :)
http://www.mysite.com/status.php?data=2 … dc3869906a
Im trying to change the iwstatus field on the line that has the key of 241affc6-98dc-4cbc-bddd-8fdc3869906a to 2
The problem, no matter what the prog echos no match. when I echo $line[’key’] it says its nothing but when I check the db it is there

should be simple but I cant figure it out. Thanks for any help

the keys returned by mysql_fech_assoc are just the fieldname without backquotes.

$line[‘key’]

btw:

$query = “SELECT * FROM phpbb_users WHERE key = '”.$uid."’" or die('Query failed: ’ . mysql_error( ));
woun’t bring up anny error but sill is kind of wrong, as ur not using any mysql-function mysql_error() will always be empty, and wount return anny mysql-syntac errors.

[php]$query = “SELECT * FROM phpbb_users WHERE key = '”.$uid."’";
$result = mysql_query($query) or die('Query failed: ’ . mysql_error( ));[/php]

Try putting an echo in front of you query statement.

Example:
echo $insert = ‘UPDATE phpbb_users SET iwstatus= "’.($data).’" WHERE key="’.mysql_escape_string($uid).’"’;

See what the output of that is. Also, do you have gotten errors before? If have never gotten errors make sure error_reporting(“E_ALL”) is turned on by adding it to the top of you page. Once you are done and everything is working, you can take it out.

Otherwise, just begin ytoecho out stuff to make sure you are getting the correct values and data needed.

P.S: some debugging tips:

use error_reporting(E_ALL)
that would have shown something like:
Notice: array-key not defined, $line[’key’], at line …

use print_r or var_dump to look at an array:
print_r($line) would have shown something like:
Array (
[key] => 241affc6-98dc-4cbc-bddd-8fdc3869906a
)

it’s error_reporting(E_ALL)
“E_ALL” will be converted to the integer 0.
and error_reporting(0) will turn off all errors.

THANKS these are the 2 errors it returns

Notice: Undefined index: `key` in /home/bizcards/public_html/sltrinkets.com/status.php on line 10

Notice: Undefined index: `key` in /home/bizcards/public_html/sltrinkets.com/status.php on line 11

Here is the sql info as you can see key is defined so wy would it be telling me its not?

-- 
-- Table structure for table `phpbb_users`
-- 

CREATE TABLE `phpbb_users` (
  `user_id` mediumint(8) NOT NULL default '0',
  `user_active` tinyint(1) default '1',
  `username` varchar(25) NOT NULL default '',
  `slverify` tinyint(1) default '0',
  `rlverify` tinyint(1) default '0',
  `iwstatus` tinyint(1) default '3',
  `key` varchar(60) default NULL,
  `refer` varchar(25) default NULL,
  `user_password` varchar(32) NOT NULL default '',
  `user_session_time` int(11) NOT NULL default '0',
  `user_session_page` smallint(5) NOT NULL default '0',
  `user_lastvisit` int(11) NOT NULL default '0',
  `user_regdate` int(11) NOT NULL default '0',
  `user_level` tinyint(4) default '0',
  `user_posts` mediumint(8) unsigned NOT NULL default '0',
  `user_timezone` decimal(5,2) NOT NULL default '0.00',
  `user_style` tinyint(4) default NULL,
  `user_lang` varchar(255) default NULL,
  `user_dateformat` varchar(14) NOT NULL default 'd M Y H:i',
  `user_new_privmsg` smallint(5) unsigned NOT NULL default '0',
  `user_unread_privmsg` smallint(5) unsigned NOT NULL default '0',
  `user_last_privmsg` int(11) NOT NULL default '0',
  `user_login_tries` smallint(5) unsigned NOT NULL default '0',
  `user_last_login_try` int(11) NOT NULL default '0',
  `user_emailtime` int(11) default NULL,
  `user_viewemail` tinyint(1) default NULL,
  `user_attachsig` tinyint(1) default NULL,
  `user_allowhtml` tinyint(1) default '1',
  `user_allowbbcode` tinyint(1) default '1',
  `user_allowsmile` tinyint(1) default '1',
  `user_allowavatar` tinyint(1) NOT NULL default '1',
  `user_allow_pm` tinyint(1) NOT NULL default '1',
  `user_allow_viewonline` tinyint(1) NOT NULL default '1',
  `user_notify` tinyint(1) NOT NULL default '1',
  `user_notify_pm` tinyint(1) NOT NULL default '0',
  `user_popup_pm` tinyint(1) NOT NULL default '0',
  `user_rank` int(11) default '0',
  `user_avatar` varchar(100) default NULL,
  `user_avatar_type` tinyint(4) NOT NULL default '0',
  `user_email` varchar(255) default NULL,
  `user_icq` varchar(15) default NULL,
  `user_website` varchar(100) default NULL,
  `user_from` varchar(100) default NULL,
  `user_sig` text,
  `user_sig_bbcode_uid` varchar(10) default NULL,
  `user_aim` varchar(255) default NULL,
  `user_yim` varchar(255) default NULL,
  `user_msnm` varchar(255) default NULL,
  `user_occ` varchar(100) default NULL,
  `user_interests` varchar(255) default NULL,
  `user_actkey` varchar(32) default NULL,
  `user_newpasswd` varchar(32) default NULL,
  `php121_user_chatting` int(11) NOT NULL default '0',
  `php121_smilies` tinyint(1) NOT NULL default '1',
  `php121_level` tinyint(1) NOT NULL default '1',
  `php121_showrequest` tinyint(1) NOT NULL default '1',
  `php121_beep_newmsg` tinyint(1) NOT NULL default '1',
  `php121_focus_newmsg` tinyint(1) NOT NULL default '1',
  `php121_auto_email_transcript` tinyint(1) NOT NULL default '0',
  `php121_banned` tinyint(1) NOT NULL default '0',
  `php121_timezone` tinyint(3) NOT NULL default '0',
  `php121_timestamp` tinyint(1) NOT NULL default '1',
  `php121_language` varchar(30) NOT NULL default 'English',
  `php121_cl_update_key` int(11) NOT NULL default '0',
  `imbl_appear_offline` int(1) NOT NULL default '0',
  `imbl_away_message` varchar(255) NOT NULL default '',
  `imbl_usertheme` varchar(64) NOT NULL default '',
  `imbl_profileshowsbuddies` int(1) NOT NULL default '1',
  `imbl_general_info` text NOT NULL,
  `imbl_profile_timestamp` varchar(255) NOT NULL default '',
  `imbl_profiletheme` varchar(64) NOT NULL default '',
  `imbl_profile_gender` varchar(35) NOT NULL default '',
  `imbl_profile_age` int(2) NOT NULL default '0',
  `imbl_profile_location` varchar(35) NOT NULL default '',
  `imbl_profile_status` varchar(35) NOT NULL default '',
  `imbl_profile_orientation` varchar(35) NOT NULL default '',
  `imbl_profile_occupation` varchar(35) NOT NULL default '',
  `imbl_profile_avataruploaded` int(1) NOT NULL default '0',
  `imbl_profile_avatarhide` int(1) NOT NULL default '0',
  PRIMARY KEY  (`user_id`),
  KEY `user_session_time` (`user_session_time`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- 
-- Dumping data for table `phpbb_users`
-- 

INSERT INTO `phpbb_users` VALUES (-1, 0, 'Anonymous', 0, 0, 3, 'NULL', 'NULL', '', 0, 0, 0, 1187441639, 0, 0, 0.00, NULL, 'english', '', 0, 0, 0, 0, 0, NULL, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, NULL, '', 0, '', '', '', '', '', NULL, '', '', '', '', '', '', '', 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 'English', 0, 0, '', '', 1, '', '', '', '', 0, '', '', '', '', 0, 0);
INSERT INTO `phpbb_users` VALUES (2, 1, '###', 1, 1, 3, 'key', '### ###', '##########', 1187441639, 0, 1187441639, 1187441639, 1, 1, 0.00, 1, 'english', 'd M Y h:i a', 0, 0, 0, 2, 1187444782, NULL, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, '', 0, '#####@yahoo.com', '', '', '', '', NULL, '', '', '', '', '', '', '', 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 'English', 0, 0, '', '', 1, '', '', '', '', 0, '', '', '', '', 0, 0);
INSERT INTO `phpbb_users` VALUES (0, 1, '### ###', 1, 1, 3, '241affc6-98dc-4cbc-bddd-8fdc3869906a', '', '##########', 1188246687, -4, 1188245662, 0, 1, 0, -6.00, 1, 'english', 'D M d, Y g:i a', 0, 0, 0, 2, 1188250232, NULL, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, NULL, 0, '######_#####@#####.com', '', 'www.sltrinkets.com', 'United States', 'Thank you for visiting www.sltrinkets.com', NULL, '', '', '', 'Computers', 'Computers, Programing, Secondife', NULL, NULL, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 'English', 0, 0, '', '', 1, '', '', '', '', 0, '', '', '', '', 0, 0);

-- --------------------------------------------------------

And dumping the array using print_r($line); returns this

[key] => 241affc6-98dc-4cbc-bddd-8fdc3869906a

Passwords and such were ommited but thats the key section

… instead of $line[’key’]

ok that fixed it, I thought since I had to use
[php]
$insert = ‘UPDATE phpbb_users SET iwstatus= "’.($data).’" WHERE key="’.mysql_escape_string($uid).’"’;
[/php]
that I should use the ` in the other fields as well. Thanks for your help!

Sponsor our Newsletter | Privacy Policy | Terms of Service