Jump to content

[SOLVED] Insert VALUE problems


Simsonite

Recommended Posts

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>');

}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/132716-solved-insert-value-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.