hi i have a script created for me and im attempting to add user_id so it it gets the userid from the users table so far i have done

CREATE TABLE IF NOT EXISTS `checkbox` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(50) NOT NULL,
  `male` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  `female` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  `couple` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  `tvtscd` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=38 ;

and the sql string for it is

$query="INSERT INTO `checkbox`(`id`,`user_id`, `male`, `female`, `couple`, `tvtscd`) 
                         VALUES (NULL,'$Male', '$female','$Couple','$tvt' WHERE user_id = '".$_SESSION['userid']."' ")" or die(mysqli_error($MySQLi_CON));//ERROR LINE
                         $rs=mysql_query($MySQLi_CON,$query);
                         if(!$rs){
                         echo "adsada";
                         }

and i get a error as follows
Parse error: syntax error, unexpected ')' in /home/public_html/deleteaccount/home.php on line 528

i know its a "(" error but no matter which one i remove i still get a error in dreamweaver

what is best way around this

I think your problem is in the part

VALUES (NULL,'$Male', '$female','$Couple','$tvt' WHERE

Try changing it to

VALUES (NULL,'$Male', '$female','$Couple','$tvt') WHERE

ive tried that and its still the same

Hi,

look here user_id = '".$_SESSION['userid']."' ")" remove the second-last quote, so that changes to: )". Then it should work, but consider that an INSERT query does not support the WHERE statement, unless this is into an INSERT ... ON SELECT query:

commented: DOH! Of course it doesn't. +0
Member Avatar for diafol

hi i have a script created for me and im attempting to add user_id so it it gets the userid from the users table so far i have done

So just add the $user_id in the VALUES list IN THE RIGHT ORDER. Your SQL was placing it in a WHERE clause, instead of placing it as the second parameter in the VALUES list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.