Jump to content

[SOLVED] PHP to MySQL problem :(


tom.hill

Recommended Posts

Hey guys,

 

I'm having a problem sending data to a table in a MySQL db, i have other tables and php pages set up that are almost identical and work perfectly but for some reason this one refuses to work. I wonder if anyone can spot a school boy error?

 

thank you in advance for taking the time to read this.

 

<?php

  // Check if session is not registered , redirect back to login page.

  include('includes/checklogin.php');

  // Connect to server and select database

  include('includes/db_login.php');

 

  // Data sent from form, validated using js on the form itself

  // mysql_real_escape function used to deny sql injection attacks

  $softwareid =strip_tags(mysql_real_escape_string($_POST['softwaretitle']));

  $licencetypeid =strip_tags(mysql_real_escape_string($_POST['licencetype']));

  $key =strip_tags(mysql_real_escape_string($_POST['key']));

  $licences =strip_tags(mysql_real_escape_string($_POST['licences']));

 

  // Insert data into mysql

  $query="INSERT INTO tkeys (softwareid, licencetypeid, key, licences) VALUES('$softwareid', '$licencetypeid', '$key', '$licences')";

  $result=mysql_query($query);

  if (!$result) {

    die ("Could not query the database: <br />". mysql_error());

  }

 

  // If successfully insert data into database, displays message "Successful".

  if($result) {

    echo "Successfuly added <b> key</b> - add another?";

    echo "<br />";

    include('addlicence.php');

  } else {

    die ("Could not query the database: <br />". mysql_error());

  }

?>

 

the error im getting is:

 

Could not query the database:

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 'key, licences) VALUES('92', '1', '9342j-nh923f-2n9f23-24g35', '3')' at line 1

 

 

but i cant find anything wrong with the syntax!! argh!

 

 

and also if this helps:

 

 

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

 

--

-- Table structure for table `tkeys`

--

 

CREATE TABLE IF NOT EXISTS `tkeys` (

  `keyid` int(11) NOT NULL auto_increment,

  `softwareid` int(11) NOT NULL,

  `licencetypeid` int(11) NOT NULL,

  `key` varchar(100) default NULL,

  `licences` int(11) NOT NULL default '1',

  `isdeleted` tinyint(1) NOT NULL default '0',

  PRIMARY KEY  (`keyid`),

  KEY `softwareid` (`softwareid`),

  KEY `licencetypeid` (`licencetypeid`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

 

--

-- Constraints for dumped tables

--

 

--

-- Constraints for table `tkeys`

--

ALTER TABLE `tkeys`

  ADD CONSTRAINT `tkeys_ibfk_1` FOREIGN KEY (`softwareid`) REFERENCES `tsoftware` (`softwareid`),

  ADD CONSTRAINT `tkeys_ibfk_2` FOREIGN KEY (`licencetypeid`) REFERENCES `tlicencetype` (`licencetypeid`);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.