For this code below, I need to add the form information to mysql when I click on submit, at the same time when I click on submit I need to move to another page like Welcome.php WITH NOTE THAT THE ENTERED INFORMATION NOW ALREADY IN DATABASE how can I male that with my code below? THANKS
................................................................................................................................................
<form method="POST">
<div class="container">
<label for="fname"><b>First
Name</b></label>
<input type="text" placeholder="Enter First Name" name="fname"
required>
<label for="lname"><b>Last
Name</b></label>
<input type="text" placeholder="Enter Last Name" name="lname"
required>
<label for="address"><b>Stree
Address</b></label>
<input type="text" placeholder="Enter Stree Adress"
name="address" required>
<label
for="city"><b>City</b></label>
<input type="text" placeholder="Enter City" name="city"
required>
<label
for="state"><b>State</b></label>
<input type="text" placeholder="Enter Stae" name="state"
required>
<label for="zipcode"><b>Zip
Code</b></label>
<input type="text" placeholder="Enter Zip Code" name="zipcode"
required>
<label
for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email"
required>
<label for="phn"><b>Phone
Number</b></label>
<input type="text" placeholder="Enter Phone Number" name="phn"
required>
<label
for="phn"><b>Password</b></label>
<input type="text" placeholder="Enter Your Password" name="pss"
required>
<div class="clearfix">
<input type="submit" value=" Submit " name="submit"/>
</div>
</div>
</form>
<?php
//Attempt server connection with default settings
if(isset($_POST["submit"]))
{
$hostname='localhost';
$username='root';
$password='password';
$fname = $_POST ['fname'];
$lname = $_POST ['lname'];
$address=$_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$email = $_POST['email'];
$phn = $_POST['phn'];
$pss = $_POST['pss'];
try {
//conects to the database
$dbh = new
PDO("mysql:host=$hostname;dbname=DB",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
// adds info to the database
$sql = "INSERT INTO Info (FirstName, LastName,Address ,City ,State
,Zip ,Email ,Phone ,Pssword)
VALUES ('$fname', '$lname','$address' ,'$city' ,'$state'
,'$zipcode' ,'$email' ,'$phn' ,'$pss')";
if ($dbh->query($sql)) {
echo "<script type= 'Your Account Created
Successfully');</script>";
}
else{
echo "Data not Inserted.";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
This demonstration is using WAMP server.
Here a new web page with name "demo.php" is created, which contains following code.
demo.php :
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<form method="POST">
<div class="container">
<label for="fname"><b>First Name</b></label>
<input type="text" placeholder="Enter First Name" name="fname" required>
<label for="lname"><b>Last Name</b></label>
<input type="text" placeholder="Enter Last Name" name="lname" required>
<label for="address"><b>Stree Address</b></label>
<input type="text" placeholder="Enter Stree Adress" name="address" required>
<label for="city"><b>City</b></label>
<input type="text" placeholder="Enter City" name="city" required>
<label for="state"><b>State</b></label>
<input type="text" placeholder="Enter Stae" name="state" required>
<label for="zipcode"><b>Zip Code</b></label>
<input type="text" placeholder="Enter Zip Code" name="zipcode" required>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="phn"><b>Phone Number</b></label>
<input type="text" placeholder="Enter Phone Number" name="phn" required>
<label for="phn"><b>Password</b></label>
<input type="text" placeholder="Enter Your Password" name="pss" required>
<div class="clearfix">
<input type="submit" value=" Submit " name="submit"/>
</div>
</div>
</form>
<?php
//Attempt server connection with default settings
if(isset($_POST["submit"]))
{
$hostname='localhost';
$username='root';
$password="";
$fname = $_POST ['fname'];
$lname = $_POST ['lname'];
$address=$_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$email = $_POST['email'];
$phn = $_POST['phn'];
$pss = $_POST['pss'];
try {
//conects to the database
$dbh = new PDO("mysql:host=$hostname;dbname=DB",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// adds info to the database
$sql = "INSERT INTO Info (FirstName, LastName,Address ,City ,State ,Zip ,Email ,Phone ,Pssword)
VALUES ('$fname', '$lname','$address' ,'$city' ,'$state' ,'$zipcode' ,'$email' ,'$phn' ,'$pss')";
if ($dbh->query($sql)) {
echo "<script type= 'Your Account Created Successfully');</script>";
header("Location: welcome.php");//navigate to welcome.php
}
else{
echo "Data not Inserted.";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
</body>
</html>
======================================================
Output : Open web page demo.php in the browser and will get the screen as shown below
Screen 1 :demo.php
Screen 2 :Enter data and will get the screen as shown below
Screen 3:Welcome.php
Screen 4:Values in database table info
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
For this code below, I need to add the form information to mysql when I click...
How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow user to add his name and email to my database, all I need to print my final database when the user click on submit. <form action="" method="post"> <label>Name :</label> <input type="text" name="name" required="required" placeholder="Please Enter Name"/><br /><br /> <label>Email :</label> <input type="email" name="email" required="required" /><br/><br /> <input type="submit" value=" Submit " name="submit"/><br /> </form>...
PHP code that is given : <?php // Here is where your preprocessing code goes // An example is already given to you for the First Name $fname = $_GET['fname']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Exercise 2 - GET Echo</title> <style> body { margin:0; padding:0; font-family: Arial; } form { margin:20px; } input[type="text"], input[type="password"] { width:150px; padding:3px; font-size:1em; } input[type="submit"] { padding:3px; font-size:1em; } label { display:inline-block; width:150px; } .input-container { padding:5px; } </style> </head> <body> <form...
I need help please to add function for clean up any inputs form that we receive from the users for this code below : <?php session_start(); // initializing variables $fname = ""; $lname = ""; $address = ""; $city = ""; $state = ""; $zip = ""; $email = ""; $phone = ""; $errors = array(); // connect to the database $db = mysqli_connect("localhost","root","password","db"); // REGISTER USER if (isset($_POST['reg_user1'])) { // receive all input values from the form $fname =...
Hey Guys I am doing a project and need some help with code in HTML and PHP. I need a form made in HTML that can be sent to a specific email through PHP. For some reason the info is not getting sent to my email, even though it says that it was sent. I have some source code here: <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $email = mail('MY_EMAIL', $subject, $message,...
Modify this code to store the form elements as variables and display them on the page in an HTML table. <!DOCTYPE html> <html> <head> <script> function getValues() { var result = ""; result += "First Name: " + document.forms["myForm"]["fname"].value + "<br>"; result += "Last Name: " + document.forms["myForm"]["lname"].value + "<br>"; result += "Address: " + document.forms["myForm"]["address"].value + "<br>"; result += "City: " + document.forms["myForm"]["city"].value + "<br>"; result += "State: " + document.forms["myForm"]["state"].value + "<br>"; document.getElementById("output").innerHTML = result; } </script>...
HTML Coding <html> <head> <title> Contact -- Charles Robertson </title> </head> <body bgcolor="white"> <table width="700" height="500" border="10"> <!-----row---1----logo---> <tr><td> <img src="20150516_084745" width="700" height="200"> </td></tr> <!-----row-2-navigation-----> <tr><td> <!----start-navigation-table----> <table width="700" height="100" border="5" bgcolor="lightgreen" > <tr><td><a href="HerbFarm.html"> <center> HOME </center></a></td> <td><a href="about3.html"> <center> ABOUT </center></a></td> <td><a href="contact3.html"> <center> CONTACT </center></a></td> <td><a href="gallery3.html"> <center> GALLERY </center></a></td> </tr> </table> <!------end-navigation-table----> </td></tr> <tr><td> <h1>Contact </h1> <form action="thankyou.html"> </form> <div class="row"> <div class="col-75"> <div class="container"> <form action="/action_page.php"> <div class="row"> <div class="col-50"> <h3>Billing Address</h3> <label for="fname"><i...
LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES login.html <!DOCTYPE html> <html> <head> <title>login popup</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> body { background-color: white; } </style> </head> <body> <center> <h1 style="text-align: center;"> Login </h1> <form> Login ID:...
<html> <head> <title>Sign Up page</title> <form name="validationForm" method="post" onsubmit="return checkvalidation()"> <!--div class--> <div class="formvalidation"> <label>Your first Name</label> <span id="showname"></span> <!--label for firstname--> <input type="text" name="firstname" class="formsignup" id ="firstn" placeholder="Enter your Name"> <br><br> <!--lastname--> <label>Your last Name</label> <span id="showlname"></span> <input type="text" name="lastname" class="formsignup" id="lastn" placeholder="Enter your last Name"> <br><br> <!--email--> <label>Your Email</label> <span id="showemail"></span> <input type="email" name="emailid" class="formsignup" size="45" id="emailn" placeholder="Enter your Email"> <br><br> <input type="submit" value="send"> </div> </form> <script> function checkvalidation(){ var name = document.forms["validationForm"]["firstname"].value; var lname...
I need help, I have my page set up, I just need help with some aesthetics, and getting the clear button to work, and get a popup when they click submit that says success along as all fields are filled out correctly. Any help would be fantastic. <html lang="en"> <head> <meta charset="utf-8"> <link rel="stylesheet" href="styleSheet.css" /> <title>2020-2021 Student-Athlete Registration Form - Weber State University</title> </head> <body> <header> <h1>WEBER STATE UNIVERSITY</h1> </header> <div class="link"> <ul> <li><a href="page 1.html"><span class="text">Home</span></a></li> </ul> </div>...
NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...