954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Error getting forms to send information



";
echo "


You Just Entered This Information Into the Database



";

echo "


Name :

$name E-Mail :


$email Opinion :


$opinion





Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

Glad you were able to help yourself, but remember, don't double post. If you need help with displaying the data, give us a holler.

samaru
a.k.a inscissor
Team Colleague
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
 

What i like to do with form submissions...

First off, you never want to put your SQL login info directly in your script instead make a file like db.cnnt.php
Inside, write something like this...

<?PHP
//  No direct call...
if(ereg('db.cnnt.php', $_SERVER['SCRIPT_NAME']))
{
    die("Access Denied!  No Direct Call!");
}
//  Set DB login vars...
$SQL_Host = 'localhost:3306';
$SQL_Usr = 'Your_Username';
$SQL_Pss = 'Your_Password';
$SQL_DB = 'Database_Name';
//  Now connect to the database server...
if(!$SQL_LNK = @mysql_pconnect($SQL_Host, $SQL_Usr, $SQL_Pss))
{
    die("Couldn't Connect to Database Server...");
}
//  Now select the database...
if(!$SQL_SLT = @mysql_select_db($SQL_DB))
{
    die("Couldn't Connect to database");
}
// Or if you use multiple databases/users you can just set the different login Vars here and call connect function in the script.
?>


Now make a functions file to house the functions you use on many different pages...
functions.inc.php

<?PHP
//functions
function ControlContent($string)
{
 //You can set more vars to this one.  for instance if you want to only strip_tags from certain inputs...You could add $HTML to the function vars.  If $HTML == 0 or $HTML == NULL then strip_tags ELSE dont strip_tags.  But in this example im just gonna fix the strings
 
 $string =  strip_tags(trim(stripslashes(urldecode($string))));
 return $string;
} //End of function

function NoGET($METHOD)
{
 if(eregi('get', $METHOD))
 {
  die("Access denied!  Post method only");
 }
}

//Of course there are many more functions you could make but I'll stop there.
?>


Now finally
ForumHandle.php

<?PHP
require_once("db.cnnt.php");
require("functions.inc.php");
  NoGET($_SERVER['REQUEST_METHOD']);
  //  takes takes all vars out of the $_POST array.  Now $_POST[email] becomes $email 
  extract($_POST);
  //  This function to clean the input string...
  ControlContent($email);

  //  Now that the strings are clean you can insert them into your database.

  //  After inserting the data close Mysql connection and exit script.
mysql_close();
exit();
?>
fEcAlMaTteR
Newbie Poster
6 posts since Jun 2004
Reputation Points: 10
Solved Threads: 0
 
What i like to do with form submissions... First off, you never want to put your SQL login info directly in your script instead make a file like db.cnnt.php

Yeah I agree. I usually set aside a separate php file where I include global variables and settings. Here I include the passwords. However, I think Killer_Typo is doing this now because it's only an example to show how to get data from forms and do stuff with it.

samaru
a.k.a inscissor
Team Colleague
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You