Jump to content

[SOLVED] Form processing


Lambneck

Recommended Posts

I am having trouble with my form processing script.

When my forms are submitted i just get a blank page.

 

form processor:

<?php
ini_set('error_reporting', E_ALL);

function check_input($data, $problem='')
{
    $data = mysql_real_escape_string(trim(strip_tags(htmlspecialchars($data)));
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError) {
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}

if (isset($_POST['submit'])){

//Code for processing the form:

$db_host = 'xxxx';
$db_user = 'xxxx';
$db_pwd = 'xxxx';
$database = 'xxxx';
$table = 'xxxx';

$connect = mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($database);


$country = check_input($_POST['country'],"Select a country.");
$compname = check_input($_POST['company_name'],"Enter your company name.");
$email = htmlspecialchars($_POST['email']);

if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)){
	show_error('E-mail address not valid.');
}
$subject = check_input($_POST['subject'],"Enter a subject");
$message = check_input($_POST['message'],"Enter your advertisement.");
$submission_date = date("l M dS, Y, H:i:s");
$ip = getenv ('REMOTE_ADDR');

$insert = mysql_query("INSERT INTO $table (col_1, col_2, col_3, col_4, col_5, submission_date, ip_address) VALUES ('$country', '$compname', '$email', '$subject','$message', '$submission_date','$ip')")or show_error(mysql_error());
}

header('Location: thankYou.html');
exit();

?>




Link to comment
https://forums.phpfreaks.com/topic/125558-solved-form-processing/
Share on other sites

since my code is fairly perfect,

i figure the problem must be in the database... no?

again im new at this.

 

 



Field 	Type 	Collation 	Attributes 	Null 	Default 	Extra 	Action
submission_id 	mediumint( 		UNSIGNED 	No 		auto_increment 	Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
col_1 	varchar(50) 	latin1_swedish_ci 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
col_2 	varchar(50) 	latin1_swedish_ci 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
col_3 	varchar(50) 	latin1_swedish_ci 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
col_4 	varchar(150) 	latin1_swedish_ci 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
col_5 	mediumblob 		BINARY 	No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
submission_date 	varchar(50) 	latin1_swedish_ci 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
ip_address 	varchar(50) 	latin1_swedish_ci 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext
is_finalized 	enum('yes', 'no') 	latin1_swedish_ci 		No 			Browse distinct values 	Change 	Drop 	Primary 	Unique 	Index 	Fulltext

since my code is fairly perfect,

you forgot a ")" on line 6:

<?php
ini_set('error_reporting', E_ALL);

function check_input($data, $problem='')
{
$data = mysql_real_escape_string(trim(strip_tags(htmlspecialchars($data))));
if ($problem && strlen($data) == 0)
{
	show_error($problem);
}
return $data;
}
function show_error($myError) {
?>
<html>
<body>
	<b>Please correct the following error:</b><br />
	<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
if (isset($_POST['submit'])){
//Code for processing the form:
$db_host = 'xxxx';
$db_user = 'xxxx';
$db_pwd = 'xxxx';
$database = 'xxxx';
$table = 'xxxx';
$connect = mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($database);
$country = check_input($_POST['country'],"Select a country.");
$compname = check_input($_POST['company_name'],"Enter your company name.");
$email = htmlspecialchars($_POST['email']);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)){
	show_error('E-mail address not valid.');
}
$subject = check_input($_POST['subject'],"Enter a subject");
$message = check_input($_POST['message'],"Enter your advertisement.");
$submission_date = date("l M dS, Y, H:i:s");
$ip = getenv ('REMOTE_ADDR');
$insert = mysql_query("INSERT INTO $table (col_1, col_2, col_3, col_4, col_5, submission_date, ip_address) VALUES ('$country', '$compname', '$email', '$subject','$message', '$submission_date','$ip')")or show_error(mysql_error());
}
header('Location: thankYou.html');
exit();
?>

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.