FormvalidationIFishan fernando12yAsked Jul 1, 2014, 11:57 PM EDT5 answersShareLinkedInXCopy linkSave How to validate form (created using html) and include it data to database? I want validate using jscript and insert data using php.
FormvalidationIFishan fernando12yAsked Jul 1, 2014, 11:57 PM EDT5 answersShareLinkedInXCopy linkSave How to validate form (created using html) and include it data to database? I want validate using jscript and insert data using php.
Shashank SrivastavaRank #1,097 · 1.7K reputation12y agoPosted Jul 2, 2014, 3:26 AM EDT+1index.html insert.php$user = $_POST['user'];$pass = $_POST['pass'];$email = $_POST['email'];$host = "localhost";$username = "root";$password = "";$db = "database_name";$connect = mysqli_connect($host, $username, $password, $db);if(!$connect) echo "could not connect";else{ $query = "INSERT INTO table_name (username_column, password_column, email_column) VALUES ($user, $pass, $email)"; $result = mysqli_query($connect, $query); if(!$result) echo "could not insert"; else echo "record inserted";}mysqli_close($connect);?>I hope it helps.+1
Sachin Mukherjee21 reputation12y agoPosted Jul 31, 2014, 6:08 AM EDT+1include("config.php");if($_SESSION['user_type'] != "admin"){header("location:index.php");}if($_POST['hd_add']=="yes"){$insert_query = mysql_query("insert into user setname='".$_POST['name']."',address='".$_POST['address']."',email='".$_POST['email']."',phone='".$_POST['phone']."',sex='".$_POST['sex']."',country_id='".$_POST['country_id']."'") or die(mysql_error()); header("location:index.php");}?>function validation(){var x= document.getElementById("name").value;if(x == ""){alert("Name is mandatory."); document.getElementById("name").focus(); document.getElementById("name").style.backgroundColor='red';return false;}else if(document.getElementById("address").value == ""){alert("Address is mandatory."); document.getElementById("address").focus(); document.getElementById("address").style.backgroundColor='red';return false;}else if(document.getElementById("email").value == ""){alert("Email is mandatory."); document.getElementById("email").focus(); document.getElementById("email").style.backgroundColor='red';return false;}else if(document.getElementById("email").value != ""){var email = document.getElementById('email');var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;if (!filter.test(email.value)) {alert('Please provide a valid email address'); document.getElementById("email").style.backgroundColor='red';return false;}}else{return true;}}NameAddressEmailPhoneSexcountry_idimage+1Srikanth Reddy142 reputation12y agoPosted Jul 2, 2014, 12:39 AM EDT0http://www.w3resource.com/javascript/form/javascript-sample-registration-form-validation.phphttp://stackoverflow.com/questions/8192355/javascript-validation-with-php-sample-10IFishan fernando4 reputation12y agoPosted Jul 2, 2014, 12:57 AM EDT0After validation, How insert correct data to database0Srikanth Reddy142 reputation12y agoPosted Jul 2, 2014, 1:45 AM EDT0write code to clear textboxes which is having false data in the form 0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Srikanth Reddy142 reputation12y agoPosted Jul 2, 2014, 12:39 AM EDT0http://www.w3resource.com/javascript/form/javascript-sample-registration-form-validation.phphttp://stackoverflow.com/questions/8192355/javascript-validation-with-php-sample-10
IFishan fernando4 reputation12y agoPosted Jul 2, 2014, 12:57 AM EDT0After validation, How insert correct data to database0
Srikanth Reddy142 reputation12y agoPosted Jul 2, 2014, 1:45 AM EDT0write code to clear textboxes which is having false data in the form 0
Shashank SrivastavaRank #1,097 · 1.7K reputationPosted Jul 2, 2014, 3:26 AM EDT
insert.php
$user = $_POST['user'];
$pass = $_POST['pass'];
$email = $_POST['email'];
$host = "localhost";
$username = "root";
$password = "";
$db = "database_name";
$connect = mysqli_connect($host, $username, $password, $db);
if(!$connect) echo "could not connect";
else
{
$query = "INSERT INTO table_name (username_column, password_column, email_column) VALUES ($user, $pass, $email)";
$result = mysqli_query($connect, $query);
if(!$result) echo "could not insert";
else echo "record inserted";
}
mysqli_close($connect);
?>
I hope it helps.
Sachin Mukherjee21 reputationPosted Jul 31, 2014, 6:08 AM EDT
Srikanth Reddy142 reputationPosted Jul 2, 2014, 12:39 AM EDT
http://stackoverflow.com/questions/8192355/javascript-validation-with-php-sample-1
ishan fernando4 reputationPosted Jul 2, 2014, 12:57 AM EDT
Srikanth Reddy142 reputationPosted Jul 2, 2014, 1:45 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts