This question already has answers here:
Apache is downloading php files instead of displaying them
(27 answers)
Closed 7 years ago.
I am trying to save form data to mysql database for last 2 days, however, the form data doesn't gets saved to mysql database, instead it downloads the User Info.php code file to my computer every time I press submit button. Need assistance!
This is html form;
<form class="form-horizontal" role="form" action="User Info.php" method="post"/>
<div class="form-group">
<label class="control-label col-sm-2" for="First Name">First Name:</label>
<div class="col-sm-10">
<input type="text" name="FirstName" class="form-control" id="First Name" placeholder="First Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Last Name">Last Name:</label>
<div class="col-sm-10">
<input type="Last Name" name="LastName" class="form-control" id="Last Name" placeholder="Last Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Company Name">Company Name:</label>
<div class="col-sm-10">
<input type="Company Name" name="CompanyName" class="form-control" id="Company Name" placeholder="Company Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-10">
<input type="Email" name="Email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Message">Message</label>
<div class="col-sm-10">
<textarea type="Message" name="Message" class="form-control" rows="3" columns="50" id="Message" placeholder="Message"></textarea></div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button name="submit" class="submit-btn" type="submit">Submit</button>
This is php code db.php;
<?php
$conn = mysql_connect('localhost','root','....', 'testforlivesite') or die("error while connecting to the database");
$db = mysql_select_db('testforlivesite', $conn) or die("error while connecting to the database");
?>
User Info.php
<?php
include_once('db.php');
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$CompanyName = $_POST['CompanyName'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];
if(mysql_query("INSERT INTO ContactUs (FirstName, LastName, CompanyName, Email, Message) VALUES ('$FirstName', '$LastName', '$CompanyName', '$Email', '$Message')"))
echo "Thanks for contacting!";
else
echo "Please rewrite the message.";
?>
change your file name from User Info.php to UserInfo.php remove the space and also rename your file from User Info.php to UserInfo.php.
<form class="form-horizontal" role="form" action="UserInfo.php" method="post"/>
<div class="form-group">
<label class="control-label col-sm-2" for="First Name">First Name:</label>
<div class="col-sm-10">
<input type="text" name="FirstName" class="form-control" id="First Name" placeholder="First Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Last Name">Last Name:</label>
<div class="col-sm-10">
<input type="Last Name" name="LastName" class="form-control" id="Last Name" placeholder="Last Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Company Name">Company Name:</label>
<div class="col-sm-10">
<input type="Company Name" name="CompanyName" class="form-control" id="Company Name" placeholder="Company Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-10">
<input type="Email" name="Email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Message">Message</label>
<div class="col-sm-10">
<textarea type="Message" name="Message" class="form-control" rows="3" columns="50" id="Message" placeholder="Message"></textarea></div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button name="submit" class="submit-btn" type="submit">Submit</button>
Related
This question already has answers here:
How can I get useful error messages in PHP?
(41 answers)
Closed 2 years ago.
I have this assignment I am trying to solve, I have a piece of code I am trying to run to save my class details on a textfile but the form doesnt write to the text file .. below is the code, i'm a beginner please try enlighten me thank you..
<?php
if(isset($_POST['submit']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$age = $_POST['age'];
$sex = $_POST['sex'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$grade = $_POST['grade'];
$email = $_POST['email'];
$file = fopen("schooldetails.txt","a") or die("file not open");
$s = $fname.",".$lname.$age.$sex.$address.$city.$zip.$grade.$email."\n";
fputs($file,$s) or die ("cannot write data");
fclose($file);
}
?>
This above is the php code, while this below is the html code, please help me out on what I might be missing, thank you..
<form action="success.php" method="post">
<fieldset>
<!-- Form Name -->
<legend>Form Name</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="fname">First Name </label>
<div class="col-md-4">
<input id="fname" name="fname" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="lname">Last Name</label>
<div class="col-md-4">
<input id="lname" name="lname" type="text" placeholder="" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="age">Age</label>
<div class="col-md-4">
<input id="age" name="age" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="sex">Sex</label>
<div class="col-md-4">
<input id="sex" name="sex" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="address">Address</label>
<div class="col-md-4">
<input id="address" name="address" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="city">City</label>
<div class="col-md-4">
<input id="city" name="city" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">Email Address</label>
<div class="col-md-4">
<input id="email" name="email" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="zip">Zip</label>
<div class="col-md-4">
<input id="zip" name="zip" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="grade">Grade</label>
<div class="col-md-4">
<input id="grade" name="grade" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button id="submit" name="submit" class="btn btn-primary">submit</button>
</div>
</div>
</fieldset>
</form>
Your POST data probably doesn't contain POST[submit'], try changing
if(isset($_POST['submit']))
to
if(isset($_POST))
For my website, when this particular page is clicked I want the form to be populated with data from the database. Here is the code for the form:
<form class="form-horizontal" role="form" method="post" action="{{url('/company-profile/update')}}">
{{ csrf_field() }}
#foreach($getAllDetails as $list)
<div class="form-group">
<div class="col-sm-10">
<label for="companyname" class="control-label">Company Name</label>
<input type="text" class="form-control" id="companyname" name="companyname" placeholder="Enter Company Name" value={{$list->companyName}}>
</div>
</div>
<div class="form-group">
<div class="col-xs-5 col-sm-4 col-md-3">
<label for="shortCode" class="control-label">Short Code</label>
<input class="form-control" id="shortCode" name="shortCode" placeholder="Short Code" value={{$list->shortCode}}>
</div>
<div class="col-xs-7 col-sm-6 col-md-7">
<label for="telnum" class="control-label">Telephone Number</label>
<input type="tel" class="form-control" id="telnum" name="telnum" placeholder="Tel. number" value={{$list->phoneNo}}>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<label for="emailid" class="control-label">Email</label>
<input type="email" class="form-control" id="emailid" name="emailid" placeholder="Email" value={{$list->emailAddress}}>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<label for="logoPath" class="control-label">Logo Path</label>
<input type="" class="form-control" id="logoPath" name="logoPath" placeholder="Enter Logo Path" value={{$list->logoPath}}>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<label for="feedback" class="control-label">Contact Address</label>
<textarea class="form-control" id="address" name="address" rows="2" value={{$list->contactAddress}}></textarea>
</div>
</div>
#endforeach
<div class="form-group">
<div class="col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
This issue is:
For example, if I want to fetch the company name {{$list->companyName}} only the first word gets displayed. For example, If the company's name is National Film Institute, only National gets displayed.
Here is code the for my index function in the controller:
public function index()
{
$data['getAllDetails']= DB::table('tblcompany')->get();
return view('companyProfile.companyProfile', $data);
}
Change
value={{$list->your_field}}
to
value="{{$list->your_field}}"
I am new to html & php and I appreciate your help. I am trying to accept user input into a webpage and then after the user clicks the submit button, write a new record out to MySQL. I am using Wordpress so the tags are not exactly textbook.
So my first problem is that the submit button does not appear to execute the php code. I also would appreciate it if someone could check how I am passing my html field names to the php variables to make sure that I am on the right track. Thanks for your help!
<form
action="employee_list.php" method="post"
<input type="submit"
name="passport" id="passport" action="uraction" method="post" enctype="multipart/form-data"
<label for="upload" >Select Employee Passport</label><input type="file" id="upload" name="upload" accept="image/*">
<p/>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="name">Employee Full Name</label>
<input type="text" class="form-control" id="exampleInputName" aria-describedby="nameHelp" placeholder="Enter Full Name">
</div>
<div class="col-md-6">
<label for="gender">Gender</label>
<select type="text" class="form-control" id="exampleInputLastName" aria-describedby="nameHelp">
</select>
</div>
<div class="col-md-6">
<label for="maritalstatus">Marital Status</label>
<select type="text" class="form-control" id="exampleInputLastName" aria-describedby="nameHelp">
</select>
</div>
<div class="col-md-6">
<label for="department">Department</label>
<input type="text" class="form-control" id="Position" aria-describedby="nameHelp" placeholder="Enter The Department">
</div>
<div class="col-md-6">
<label for="salary">Salary</label>
<input type="number" class="form-control" id="salary" aria-describedby="nameHelp" placeholder="">
</div>
<div class="col-md-6">
<label for="certificate"> Highest Certificate Acquired</label>
<input type="text" class="form-control" id="salary" aria-describedby="nameHelp" placeholder="Enter Highest Certificate Acquired">
</div>
</div>
</div>
<div class="form-group">
<label for="Email">Email Address</label>
<input type="emai" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="address">House Address</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter House Address">
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="phonenumber">Phone Number</label>
<input type="number" class="form-control" id="phonenumber">
</div>
</form>
</div>
<!-- /.content-wrapper -->
PHP script:
<?php
if(isset($_POST['submit'])) {
$SQL = "INSERT INTO tbl_employee (name, gender,
marital_status,department,salary,certificate, email,address,phone_number)
VALUES ('$_POST[name]', '$_POST[gender]',
'$_POST[marital_status],'$_POST[department]','$_POST[salary]
','$_POST[certificat
e]','$_POST[email]','$_POST[address]','$_POST[phone_numer]')"; $result =
mysql_query($SQL);
}
?>
<html>
<head>
<title>Check</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?php include('dbconnect.php');
if($_POST['submit']){
$fullname = $_POST['exampleInputName'];
$gender = $_POST['gender'];
$status = $_POST['status'];
$position = $_POST['position'];
$salary = $_POST['salary'];
$certificate = $_POST['certificate'];
$exampleInputEmail1 = $_POST['exampleInputEmail1'];
$phonenumber = $_POST['phonenumber'];
}
$data = "INSERT INTO test (`id`, `fullname`, `gender`, `matrial_status`, `department`, `salary`, `certificate`, `email`, `address`)VALUES ('', '$fullname', '$gender', '$status', '$position', '$salary', '$certificate', '$exampleInputEmail1', '$phonenumber')";
mysqli_query($con,$data);
?>
<form action="checkbox.php" method="POST" >
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="name">Employee Full Name</label>
<input type="text" class="form-control" id="exampleInputName" name="exampleInputName" aria-describedby="nameHelp" placeholder="Enter Full Name">
</div>
<div class="col-md-6">
<label for="gender">Gender</label>
<select type="text" name="gender" class="form-control" id="gender" aria-describedby="nameHelp">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div class="col-md-6">
<label for="maritalstatus">Marital Status</label>
<select type="text" name="status" class="form-control" id="status" aria-describedby="nameHelp">
<option value="Married">Married</option>
<option value="Unmarried">Unmarried</option>
</select>
</div>
<div class="col-md-6">
<label for="department">Department</label>
<input type="text" class="form-control" name="position" id="position" aria-describedby="nameHelp" placeholder="Enter The Department">
</div>
<div class="col-md-6">
<label for="salary">Salary</label>
<input type="number" class="form-control" name="salary" id="salary" aria-describedby="nameHelp" placeholder="">
</div>
<div class="col-md-6">
<label for="certificate"> Highest Certificate Acquired</label>
<input type="text" class="form-control" id="certificate" name="certificate" aria-describedby="nameHelp" placeholder="Enter Highest Certificate Acquired">
</div>
</div>
</div>
<div class="form-group">
<label for="Email">Email Address</label>
<input type="emai" class="form-control" id="exampleInputEmail1" name="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="address">House Address</label>
<input type="text" class="form-control" id="exampleInputEmail1" name="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter House Address">
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="phonenumber">Phone Number</label>
<input type="text" class="form-control" name="phonenumber" id="phonenumber">
</div>
</div>
</div>
<input type="submit" name="submit" id="passport">
</form>
</body>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a problem that might be a syntax problem but I can't seem to figure out what I am doing wrong.
I have created a form and when I click on submit, the data in the form is not sent to my mysql database.
Here is my html code
<div class="content-wrapper">
<div class="container">
<div class="row">
<div class="col-md-10">
<h1 class="page-head-line">Forms </h1>
</div>
</div>
<div class="row">
<div class="col-md-10">
<div class="panel panel-default">
<div class="panel-heading">
BASIC FORM ELEMENTS
</div>
<div class="panel-body">
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name' type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num' type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="name' type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista' type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency' type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description' type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date' type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
</div>
</div>
and here is my php
<?php
echo $POST;
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("../includes/config.php");
if (isset($_POST['submit'])) {
echo $_POST['submit'];
$name = $_POST['name'];
$projectnum = $_POST['project_num'];
$projectname = $_POST['project_name'];
$easyvista = $_POST['easyvista'];
$agency = $_POST['agency'];
$description = $_POST['description'];
$startDate = $_POST['input-date'];
$sql="INSERT INTO statusreport(name, project_num, project_name, easyvista, agency, description)
VALUES
('$name','$projectnum', '$projectname', '$easyvista', '$agency', '$description')";
if (!mysqli_query($conn, $sql))
{
die('Error: ' . mysqli_connect_error($conn));
}
echo "Entry is recored <br/>";
echo "Name:", $name, "<br/>";
echo "test..................<br/>", $name;
/*header("location: http://10.1.7.129//gisadmin/admin/forms.php");*/
//echo "<script>setTimeout(\"location.href = 'http://10.1.7.129//gisadmin/admin/forms.php';\",700);</script>";
mysqli_query($conn, $sql);
}
else {
echo "No data";
}
?>
Any help would be greatly appreciated.
Thanks
You have a mixing of single and double quotes here, the name attributes are opening the value with double quotes and closing with single quotes, should be as follows:
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num" type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="project_name" type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista" type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency" type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description" type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date" type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
And then, as #Fred -ii stated in his comment, the php script is wrong:
echo $POST;
That line is wrong, there is no variable with name $POST before that code.
Are you getting success message but database is not getting updated OR Getting Total Error...???
1) Check for double quotes and single quotes..
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
2) Also check for path... for
include("../includes/config.php");
Is it correct or not...?
3)
<label for="project_name">Project Name</label>
<input name="name' type="text"
SHOULD BE
<label for="project_name">Project Name</label>
<input name="project_name" type="text"
I have the following Bootstrap Modal, which I am just submitting and eventually it will send an email. For right now I am just trying to echo Signing Up.
<div class="modal-body">
<form class="form-horizontal" name="commentform" method="post" action="signup.php">
<div class="form-group">
<label class="control-label col-md-4" for="first_name">First Name</label>
<div class="col-md-6">
<input type="text" class="form-control" id="first_name" name="first_name" placeholder="First Name"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" for="last_name">Last Name</label>
<div class="col-md-6">
<input type="text" class="form-control" id="last_name" name="last_name" placeholder="Last Name"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" for="email">Email Address</label>
<div class="col-md-6 input-group">
<span class="input-group-addon">#</span>
<input type="email" class="form-control" id="email" name="email" placeholder="Email Address"/>
</div>
</div>
</form>
</div>
Here Is my signup.php code:
<?php
echo "Signing Up";
?>
However, when I run this on my dreamhost server and press the Sign Up button, nothing happens at all. My console provides me with this error: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Your code works fine for me as is (after adding a Submit button). See demo
Check your permissions on your files, make sure php files are 644 (-rw-r--r--)