user1257518
user1257518

Reputation: 147

PHP form clears on submit and just refreshes the page (doesn't send data to Mysql)

I hope someone can help. When I submit this script the form just refreshes and doesnt display the thankyou.php page. Thanks for any help

include 'dbc.php';

$err = array();

if(@$_POST['doAcademic'] == 'Academic') 
{ 


// This code filters harmful script code and escapes data of all POST data from the user submitted form.

foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}

// Automatically collects the hostname or domain  like example.com) 

$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$path   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');

These join the date fields together from the HTML

@$degree_date = date("Y-m-d", mktime(0,0,0,$dt,$mo,$yr));
@$other_degree_date = date("Y-m-d", mktime(0,0,0,$dty,$moy,$yry));
@$expd_degree_date = date("Y-m-d", mktime(0,0,0,$dti,$moi,$yri));
if(empty($err)) {

// inserts data into mysql table

$sql_insert = "INSERT into `acadmic`
(`otherapply`,`otherinstitute`,`institute`,`institute_city`,
`degree_country`, `degree_date`,`degree`,`grade`,    `other_degree_institute`,
`other_degree_city`,`other_degree`, `other_degree_date`,`other_degree_grade`,
`expd_degree_institute`,`expd_degree_city`, 
`expd_degree_country`, `expd_degree`,
`expd_degree_date`,`current_docyear_prog`,`current_docyear_funded`,
`prevfields`,`profexperience`
)
VALUES
('$data[otherapply]','$data[otherinstitute]','$data[institute]',
'$data[institute_city]',
'$data[degree_country]', '$degree_date', '$data[degree]', '$data[grade]',
'$data[other_degree_institute]' ,'$data[other_degree_city]', '$data[other_degree]',           
'$other_degree_date', '$data[other_degree_grade]', '$data[expd_degree_institute]',
'$data[expd_degree_city]','$data[expd_degree_country]',
'$data[expd_degree]','$expd_degree_date','$data[current_docyear_prog]',      
'$data[current_docyear_funded]',
'$data[prevfields]','$data[profexperience]'
)
";

mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());

This code returns the user to the thankyou page.

header("Location: thankyou.php");  
exit();
}
}

thanks in advance

Upvotes: 0

Views: 318

Answers (2)

GabiDi
GabiDi

Reputation: 96

I dont see any mention / loading / redirection to the thank you page in your code.

Also i would suggest your print_r your $sql_insert :

print_r($sql_insert);

on the line after the $sql_insert assignment.

You might also want to check your Database to see if the row is being inserted, if it isn't then you know what your problem is (your sql) , if it is being inserted then your problem is else where and you need to post the rest of your script.

I'm not sure if it's an error , but i see your table is spelled 'acadmic' in your sql request:

  INSERT  into `acadmic`

You also have a trailing , after profexperience field:

 ,`profexperience`,)
  VALUES

Post some more details :)

Upvotes: 2

Explosion Pills
Explosion Pills

Reputation: 191729

After submission I think you just want to header('Location: thankyou.php'); exit;

Upvotes: 0

Related Questions