Jump to content

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

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.