Jump to content

registration code


sraorajath

Recommended Posts

This code is not inserting data into database please help me

<?PHPif(isset($_POST['submit'])){	$error = array();	if(empty($_POST['fullname']))	{		$error[] = 'please enter ur name';	}	else	{		$name = $_POST['fullname'];	}		if(empty($_POST['usn']))	{		$error[]= 'Please enter your USN';	}	else	{		$usn = $_POST['usn'];	}		if(empty($_POST['dob']))	{		$error[]= 'Please enter your date of birth';	}	else	{		$date = $_POST['dob'];	}		if(empty($_POST['gender']))	{		$error[]= 'Please select gender';		}	else	{		$gender = $_POST['gender'];	}		if(empty($_POST['mail']))	{		$error[]= 'Please enter your email-ID';		}	else	{		if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-])+$/", $_POST['mail']))		{			$email = $_POST['mail'];		}		else		{			$error[]='Email is invalid';		}	}		if(empty($_POST['mobile']))	{		$error[]= 'Please enter your mobile number';		}	else	{		$number = $_POST['mobile'];	}		if(empty($_POST['sslc']))	{		$error[]= 'Please enter your sslc marks';		}	else	{		$sslcmarks = $_POST['sslc'];	}		if(empty($_POST['puc']))	{		$error[]= 'Please enter your puc marks';			}	else	{		$pucmarks = $_POST['puc'];	}		if(empty($_POST['branch']))	{		$error='Please select your branch';			}	else	{		$branch = $_POST['branch'];	}		if(empty($_POST['batch']))	{		$error='Please select year of passing';			}	else	{		$year = $_POST['batch'];	}		if(empty($_POST['marks1']))	{		$error= 'Please enter your 1st sem marks';			}	else	{		$one = $_POST['marks1'];	}		if(empty($_POST['marks2']))	{		$error='Please enter your 2nd sem marks';			}	else	{		$two = $_POST['marks2'];	}		if(empty($_POST['marks3']))	{		$error= 'Please enter your 3rd sem marks';			}	else	{		$three = $_POST['marks3'];	}		if(empty($_POST['marks4']))	{		$error= 'Please enter your 4th sem marks';			}	else	{		$four = $_POST['marks4'];	}		if(empty($_POST['marks5']))	{		$error='Please enter your 5th sem marks';			}	else	{		$five = $_POST['marks5'];	}		if(empty($_POST['marks6']))	{		$error='Please enter your 6th sem marks';			}	else	{		$six = $_POST['marks6'];	}		if(empty($_POST['marks7']))	{		$error= 'Please enter your 7th sem marks';			}	else	{		$seven = $_POST['marks7'];	}		if(empty($_POST['marks8']))	{		$error= 'Please enter your 8th sem marks';			}	else	{		$eight = $_POST['marks8'];	}		if(empty($_POST['attempt']))	{		$error='click first attempt or not';			}	else	{		$fattempt = $_POST['attempt'];	}		if(empty($_POST['backlogs']))	{		$error= 'Please enter no.of backlogs';			}	else	{		$backlog = $_POST['backlogs'];	}		if(empty($_POST['internships']))	{		$error= 'Please enter no.of internships';			}	else	{		$internship = $_POST['internships'];	}		if(empty($_POST['softskills']))	{		$error= 'Please enter softskill training';			}	else	{		$softskill = $_POST['softskills'];	}		if(empty($_POST['ethnus']))	{		$error= 'Please enter ethnus training';			}	else	{		$ethnus = $_POST['ethnus'];	}		if(empty($_POST['password']))	{		$error='Please enter your password';			}	else	{		$password = $_POST['password'];	}		if(empty($_POST['rpassword']))	{		$error= 'please retype your password';			}	else	{		$repassword = $_POST['rpassword'];	}	if(empty($error))	{		$result = "INSERT INTO `students`(fullname, usn, birthdate, gender, email, number, sslcmarks, pucmarks, branch, batch, marks1, marks2, marks3, marks4, marks5, marks6, marks7, marks8, firstattempt, currentbacklogs, intership, softskill, ethnus, password, retypepassword) VALUES ('[$name]', '$usn', '$date', '$gender', '$email', '$number', '$sslcmarks', '$pucmarks', '$branch', '$year', '$one', '$two', '$three', '$four', '$five', '$six', '$seven', '$eight', '$fattempt', '$backlog', '$internship', '$softskill', '$ethnus', '$password', '$repassword')";		$result_insert = mysql_query($result, $con);		if(!$result_insert)		{			echo 'query failed';		}		else {			echo '<script> alert("Account created sucessful"); </script>';		}	}	else {		foreach($error as $key => $values){			echo 'failed in<li>' . $values . '</li>';		}	}}}else{	echo 'could not connect to the database';}?>
Link to comment
Share on other sites

You should have error reporting turned on

 

ini_set("display_errors", "1");

 

and as mentioned, be checking for SQL errors.

Link to comment
Share on other sites

after submiting the form query failed is displayed i.e from "echo 'query failed';" code

 

like niche and JSG suggested.. use mysql_error

 

What errors are you getting especially when you use mysql_error()?

 

http://www.w3schools.com/php/func_mysql_error.asp

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...