5 Replies - 564 Views - Last Post: 08 September 2011 - 12:53 PM Rate Topic: -----

#1 thomasubc   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-September 11

Added table and now it does not work

Posted 08 September 2011 - 12:20 PM

I added the table Link and now am recieving the error

Query:
INSERT INTO partsx(`Description`, `Part_Number`, `Document', `Link`) VALUES('SAS Type I','a','b', 'c')

Failed with error:
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 'Link`) VALUES('SAS Type I','a','b', 'c')' at line 1.

I do not see the problem.


Code is below
<?php
include 'inputdata.php';
//connecting to databse;
if (!mysql_connect('localhost:3306', $username, $password)) {
   die('Failed to connect to database');
}
if (!mysql_select_db($database)) {
    die("Failed to select database $database". mysql_error());
}
//
//collecting data from index.php;
$Description = mysql_real_escape_string($_POST["Description"]);
$Part_Number = $_POST["Part_Number"];
$Document = mysql_real_escape_string($_POST["Document"]);
$Link = mysql_real_escape_string($_POST["Link"]);
//inserting data into table partsx;
$create = "INSERT INTO partsx(`Description`, `Part_Number`, `Document', `Link`) VALUES('$Description','$Part_Number','$Document', '$Link')";
mysql_query($create) or die("Query $create failed: " .mysql_error());
?>

This post has been edited by RudiVisser: 08 September 2011 - 12:26 PM
Reason for edit:: use [CODE] tags (correctly)!


Is This A Good Question/Topic? 0
  • +

Replies To: Added table and now it does not work

#2 RudiVisser   User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,566
  • Joined: 05-June 09

Re: Added table and now it does not work

Posted 08 September 2011 - 12:26 PM

Ah the good old simple-but-annoying errors :D

You have an apostrophe instead of a backtick, right here: `Document', `Link`.

EDIT: Happy 3000th post to me! :bananaman:

This post has been edited by RudiVisser: 08 September 2011 - 12:47 PM

Was This Post Helpful? 1
  • +
  • -

#3 lrk89   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 104
  • Joined: 20-May 09

Re: Added table and now it does not work

Posted 08 September 2011 - 12:27 PM

I have basic php and mysql experience as im still learning but shouldn't you try sending information to the database after you make the query and declare it to a variable? Code line 16 looks like it should come after... shoot me if i'm wrong and explain why :-)
Was This Post Helpful? 0
  • +
  • -

#4 thomasubc   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-September 11

Re: Added table and now it does not work

Posted 08 September 2011 - 12:44 PM

I can see where you were mislead. The "//" means that the following line is a comment. I find it useful because I can get lost in writing code and forget what things mean. I pass it on you. Let me know if you find it helpful.
Was This Post Helpful? 0
  • +
  • -

#5 RudiVisser   User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,566
  • Joined: 05-June 09

Re: Added table and now it does not work

Posted 08 September 2011 - 12:47 PM

View Postthomasubc, on 08 September 2011 - 08:44 PM, said:

I can see where you were mislead. The "//" means that the following line is a comment. I find it useful because I can get lost in writing code and forget what things mean. I pass it on you. Let me know if you find it helpful.

Did you resolve your problem by fixing the quote?
Was This Post Helpful? 0
  • +
  • -

#6 thomasubc   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 02-September 11

Re: Added table and now it does not work

Posted 08 September 2011 - 12:53 PM

Thank you, it took some searching but I found it. I thought they were the same key. Thank you for setting me straight!



View PostRudiVisser, on 08 September 2011 - 12:26 PM, said:

Ah the good old simple-but-annoying errors :D

You have an apostrophe instead of a backtick, right here: `Document', `Link`.

EDIT: Happy 3000th post to me! :bananaman:


That fixed the problem!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1