jobs1109 Posted July 20, 2011 Share Posted July 20, 2011 Hi, I am try to insert the following data into a database but I keep getting the following error Here is the code <?php mysql_query="INSERT INTO table (JobTitle, Company, Salary,Description,CompanyURL,PhoneNumber,Requirements,JobCategory,JobType,Address) VALUES ('$Job-Title', '$Company','$Salary','$Description','$Company-URL', '$Phone-Number','$Requirements','$Job-Category','$Job-Type','$Address')"); ?> Here is the error message Parse error: syntax error, unexpected '=' in /home/content/h/Database.php on line 60 Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/ Share on other sites More sharing options...
JonnoTheDev Posted July 20, 2011 Share Posted July 20, 2011 Your syntax is incorrect. <?php $res = mysql_query("INSERT INTO table (JobTitle, Company, Salary,Description,CompanyURL,PhoneNumber,Requirements,JobCategory,JobType,Address) VALUES ( '".mysql_real_escape_string($Job-Title)."', '".mysql_real_escape_string($Company)."', '".mysql_real_escape_string($Salary)."', '".mysql_real_escape_string($Description)."', '".mysql_real_escape_string($Company-URL)."', '".mysql_real_escape_string($Phone-Number)."', '".mysql_real_escape_string($Requirements)."', '".mysql_real_escape_string($Job-Category)."', '".mysql_real_escape_string($Job-Type)."', '".mysql_real_escape_string($Address)."')"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245040 Share on other sites More sharing options...
jobs1109 Posted July 20, 2011 Author Share Posted July 20, 2011 Hi I tried the codes but still getting the same error message. Thanks here is a link to the page http://www.hiringinhilo.com/Hilo-Jobs/Post-Jobs-to-Database/Post-Jobs-to-Database.php Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245042 Share on other sites More sharing options...
jobs1109 Posted July 20, 2011 Author Share Posted July 20, 2011 Hi, Here is a little more of the code if it helps. <?php echo $_SESSION['Job-Title'];?><br> <?php echo $_SESSION['Company'];?><br> <?php echo $_SESSION['Salary'];?><br> <?php echo $_SESSION['Description'];?><br> <?php echo $_SESSION['Company-URL'];?><br> <?php echo $_SESSION['Phone-Number'];?><br> <?php echo $_SESSION['Address'];?><br> <?php echo $_SESSION['Requirements'];?><br> <?php echo $_SESSION['Job-Type'];?><br> <?php echo $_SESSION['Job-Category'];?><br> <br><br> <br><br> <?php // assigning variables the session variables $Job-Title =$_SESSION['Job-Title']; $Company =$_SESSION['Company']; $Salary =$_SESSION['Salary']; $Description =$_SESSION['Description']; $Company-URL =$_SESSION['Company-URL']; $Phone-Number =$_SESSION['Phone-Number']; $Requirements =$_SESSION['Requirements']; $Job-Category =$_SESSION['Job-Category']; $Job-Type =$_SESSION['Job-Type']; $Address =$_SESSION['Address']; ?> <?php include'../DB-Connect.php'; // Insert a row of information into the table "Table" $res = mysql_query("INSERT INTO Table (JobTitle, Company, Salary,Description,CompanyURL,PhoneNumber,Requirements,JobCategory,JobType,Address) VALUES ('".mysql_real_escape_string($Job-Title)."', '".mysql_real_escape_string($Company)."', '".mysql_real_escape_string($Salary)."', '".mysql_real_escape_string($Description)."', '".mysql_real_escape_string($Company-URL)."', '".mysql_real_escape_string($Phone-Number)."', '".mysql_real_escape_string($Requirements)."', '".mysql_real_escape_string($Job-Category)."', '".mysql_real_escape_string($Job-Type)."', '".mysql_real_escape_string($Address)."')"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245045 Share on other sites More sharing options...
JonnoTheDev Posted July 20, 2011 Share Posted July 20, 2011 Please add code tags around your code when you submit a post (the code button is in the editor window). I cannot read it clearly as plain text. What exactly is on line 60? The code I posted is correct. Are you sure that it has been uploaded if you are getting the same error? I can see that your original code would have given that error so that's why I am suspect. Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245049 Share on other sites More sharing options...
jobs1109 Posted July 20, 2011 Author Share Posted July 20, 2011 Hi here is some more of the code <?php echo $_SESSION['Job-Title'];?><br> <?php echo $_SESSION['Company'];?><br> <?php echo $_SESSION['Salary'];?><br> <?php echo $_SESSION['Description'];?><br> <?php echo $_SESSION['Company-URL'];?><br> <?php echo $_SESSION['Phone-Number'];?><br> <?php echo $_SESSION['Address'];?><br> <?php echo $_SESSION['Requirements'];?><br> <?php echo $_SESSION['Job-Type'];?><br> <?php echo $_SESSION['Job-Category'];?><br> <br><br> <br><br> <?php // assigning variables the session variables $Job-Title =$_SESSION['Job-Title']; $Company =$_SESSION['Company']; $Salary =$_SESSION['Salary']; $Description =$_SESSION['Description']; $Company-URL =$_SESSION['Company-URL']; $Phone-Number =$_SESSION['Phone-Number']; $Requirements =$_SESSION['Requirements']; $Job-Category =$_SESSION['Job-Category']; $Job-Type =$_SESSION['Job-Type']; $Address =$_SESSION['Address']; ?> <?php include'../DB-Connect.php'; // Insert a row of information into the table "Table" $res = mysql_query("INSERT INTO Table (JobTitle, Company, Salary,Description,CompanyURL,PhoneNumber,Requirements,JobCategory,JobType,Address) VALUES ('".mysql_real_escape_string($Job-Title)."', '".mysql_real_escape_string($Company)."', '".mysql_real_escape_string($Salary)."', '".mysql_real_escape_string($Description)."', '".mysql_real_escape_string($Company-URL)."', '".mysql_real_escape_string($Phone-Number)."', '".mysql_real_escape_string($Requirements)."', '".mysql_real_escape_string($Job-Category)."', '".mysql_real_escape_string($Job-Type)."', '".mysql_real_escape_string($Address)."')"); ?> Posted by: jobs1109 « on: Today at 06:04:29 AM »Insert Quote Posted by: jobs1109 « on: Today at 06:04:29 AM »Insert Quote Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245052 Share on other sites More sharing options...
JonnoTheDev Posted July 20, 2011 Share Posted July 20, 2011 I want to SEE line 60! The error is on line 60. You must read the errors! Parse error: syntax error, unexpected '=' in /home/content/h/i/l/hilo101/html/Hilo-Jobs/Post-Jobs-to-Database/Post-Jobs-to-Database.php on line 60 Post DB-Connect.php also. However make sure you remove the username & password details for your database connection before posting. Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245055 Share on other sites More sharing options...
jobs1109 Posted July 20, 2011 Author Share Posted July 20, 2011 Hi Here is the code at line 60 $Job-Title =$_SESSION['Job-Title']; Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245056 Share on other sites More sharing options...
JonnoTheDev Posted July 20, 2011 Share Posted July 20, 2011 Ah, my god can't beleive I missed this! Variable names cannot contain hyphens! <?php /* BAD, causes error*/ $Job-Title = $_SESSION['Job-Title']; /* GOOD */ $Job_Title = $_SESSION['Job-Title']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245061 Share on other sites More sharing options...
jobs1109 Posted July 20, 2011 Author Share Posted July 20, 2011 Ok Thank you, I will try it again Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245062 Share on other sites More sharing options...
jobs1109 Posted July 20, 2011 Author Share Posted July 20, 2011 Hi Neil, Thanks for your help. It's working now and data is being added to the database. I will work on extracting data from the database tomorrow, might need some more help. regards, DS Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245070 Share on other sites More sharing options...
JonnoTheDev Posted July 20, 2011 Share Posted July 20, 2011 Ok, post a new topic. Don't forget to mark as solved when your done. I'll do this one. Quote Link to comment https://forums.phpfreaks.com/topic/242416-problems-inserting-data-into-database/#findComment-1245076 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.