Simsonite Posted November 14, 2008 Share Posted November 14, 2008 Hi I have got a CMS script and i cannot get it to insert a php variable into my script. Here is the code the variable is $id2 <?php $id2 = "105"; // Check whether a form has been submitted. If so, carry on if ($HTTP_POST_VARS){ // Validate the entries $validator = new Validator(); $validator->validateTextOnly($HTTP_POST_VARS['title'],'Article Title'); $validator->validateTextOnly($HTTP_POST_VARS['tagline'],'Tagline'); $validator->validateGeneral($id2); $validator->validateGeneral($HTTP_POST_VARS['thearticle'],'Article'); // Check whether the validator found any problems if ( $validator->foundErrors() ){ echo 'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each }else{ // Create an SQL query (MySQL version) // The 'addslashes' command is used 5 lines below for added security // Remember to use 'stripslashes' later to remove them (they are inserted in front of any // special characters $insertQuery = "INSERT INTO cmsarticles (,id2,title,tagline,thearticle) VALUES (" '$id2',. "'".$HTTP_POST_VARS['title']."', ". "'".$HTTP_POST_VARS['tagline']."', ". "'".addslashes($HTTP_POST_VARS['thearticle'])."')"; // Save the form data into the database if ($result = $connector->query($insertQuery)){ // It worked, give confirmation echo '<center><b>Article added to the database</b></center><br>'; }else{ // It hasn't worked so stop. Better error handling code would be good here! exit('<center>Sorry, there was an error saving to the database</center>'); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/ Share on other sites More sharing options...
revraz Posted November 14, 2008 Share Posted November 14, 2008 Remove the comma before id2 in your INSERT clause. If you use mysql_error after your querries, it will help you troubleshoot errors. Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/#findComment-690186 Share on other sites More sharing options...
Simsonite Posted November 14, 2008 Author Share Posted November 14, 2008 still doesnt work but i will try the error function Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/#findComment-690268 Share on other sites More sharing options...
PFMaBiSmAd Posted November 14, 2008 Share Posted November 14, 2008 $HTTP_POST_VARS were depreciated long ago in 2002, they are turned off by default in php5, and have been completely eliminated in php6. Use $_POST instead. Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/#findComment-690277 Share on other sites More sharing options...
Simsonite Posted November 14, 2008 Author Share Posted November 14, 2008 o... lol great this is what happens when u edit a code of a tutorial Lol thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/#findComment-690289 Share on other sites More sharing options...
Simsonite Posted November 14, 2008 Author Share Posted November 14, 2008 This still isnt helping the problem i had because it isnt sending the data to the database. this was cause after i tried to enter the $id2 variable. Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/#findComment-690306 Share on other sites More sharing options...
revraz Posted November 15, 2008 Share Posted November 15, 2008 And it's not helping if you don't do what was suggested.. Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/#findComment-690517 Share on other sites More sharing options...
Simsonite Posted November 15, 2008 Author Share Posted November 15, 2008 Hi im sorry but im a begginer but if you just tell what i have to do like that i wont know what ure talking about Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/#findComment-690685 Share on other sites More sharing options...
dropfaith Posted November 15, 2008 Share Posted November 15, 2008 your code is really old and outdated for a simple insert theres a bunch of stuff needs to be changed up a bit i suggest this tutorial http://www.tizag.com/mysqlTutorial/mysqlinsert.php inserts Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/#findComment-690687 Share on other sites More sharing options...
Simsonite Posted November 15, 2008 Author Share Posted November 15, 2008 Thanks for all your help and i apologise for being such a beginner. I have decided to ditch the tutorial CMS and create my own using dreamweaver Quote Link to comment https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/#findComment-690699 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.