I created the following HTML and PHP documents. When I fill in the information and click submit, I don't receive any errors, but I get a blank page and also don't receive an email with the form information. I'm fairly new at this, but could use the help on why I'm not getting the email and how to get rid of the blank page. Thank you.
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<div id="title">
<div id="titlecontact">
<h1>Excelerate Growth, LLC</h1>
<h4><em>Consulting to Help Small Businesses Excel</em></h4>
</div>
</div>
<header id="header">
<nav class="links" style="--items: 5;">
Home
About
Services
Results
Contact
<span class="line"></span>
</nav>
</header>
<?=$thankYou ?>
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" value="Send"><input class="reset" type="reset" value="Clear">
</form>
<div id="social">
<img class="linkedin" src="linkedin.png">
<img class="email2" src="email.png">
<img class="facebook" src="facebook.png">
<br/>
<br/>
</div>
<br/>
<br/>
<?php
if($_POST["submit"]) {
$recipient="jscotty78#gmail.com";
$subject="Form to email message";
$sender=$_POST["sender"];
$senderEmail=$_POST["senderEmail"];
$senderPhone=$_POST["senderPhone"];
$type=$_POST["type"];
$message=$_POST["message"];
$mailBody="Name: $sender\nEmail: $senderEmail\nPhone: $senderPhone\nType: $type\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou="<p>Thank you! Your message has been sent.</p>";
}
?>
Try This Code Below with name="submit"
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" name="submit" value="Send"><input class="reset" type="reset" value="Clear">
</form>
POST form data is sent using name => value. Here:
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" value="Send"><input class="reset" type="reset" value="Clear">
</form>
you have no input with name="submit". This is why $_POST['submit'] is equal to "", which is considered false in PHP. So mail() is not running.
Instead, try this:
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" value="Send"><input class="reset" type="reset" value="Clear">
<input type="hidden" name="submit" value="a" />
</form>
Notice name="submit". This gets sent along with the form data.
I am beginner in codeignitor.I want to post an image through a post method. All data is being posted but the image is not posting in controller.
Here is my view code.
<form action="<?php echo site_url('adminpanel/add_event');?>" method="post" name="addform" enctype="multipart/form-data">
<fieldset>
<p>
<label style="width:20%;float:left;">Event Title<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<input class="text-input small-input" type="text" name="event_title" id="event_title" placeholder="Event Title" value="<?php if(isset($teenzstore_edit_data['product_name'])) echo $teenzstore_edit_data['product_name'];?>" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Select Age<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<select name="age" id="age" class="form-control" class="form-control" onChange="return get_product_filter('<?php echo base_url();?>',this.value);">
<option value="0">Select Age</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
</select>
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Image</label>
<label style="width:1%;float:left;">:</label>
<input type="file" name="event_image" id="event_image" onchange="checkExtension(this.value)" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Date<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<input class="text-input small-input" type="text" name="event_date" id="event_date" placeholder="Event Date" value="<?php if(isset($teenzstore_edit_data['product_points'])) echo $teenzstore_edit_data['product_points'];?>" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Time<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<input class="text-input small-input" type="text" name="event_time" id="event_time" placeholder="Event Time" value="<?php if(isset($teenzstore_edit_data['product_points'])) echo $teenzstore_edit_data['product_points'];?>" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Venue <span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<label style="width:20%;float:left;">
<textarea cols="80" id="event_venue" style="width:77% !important;" name="event_venue" rows="10">
<?php if(isset($restaurant_edit_data[ 'rest_description'])) echo $restaurant_edit_data[ 'rest_description'];?>
</textarea>
</p>
<script type="text/javascript">
CKEDITOR.replace('event_venue', {
width: "630",
});
</script>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Description <span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<label style="width:20%;float:left;">
<textarea cols="80" id="event_desc" style="width:77% !important;" name="event_desc" rows="10">
<?php if(isset($restaurant_edit_data[ 'rest_description'])) echo $restaurant_edit_data[ 'rest_description'];?>
</textarea>
</p>
<script type="text/javascript">
CKEDITOR.replace('event_desc', {
width: "630",
});
</script>
</fieldset>
<div class="clear"></div>
<p>
<label style="width:20%;float:left;"> </label>
<label style="width:1%;float:left;"> </label>
<input class="button" type="submit" name="submit" value="Submit" />
<input class="button" type="button" value="Cancel" name="cancel" onclick="javascript:history.go(-1);" />
</p>
</form>
I can't find problem, because in my computer everything works fine, but can explain you method debug:
1) Remove from your code any fragment that is not connected with problem:
I created index.html with this:
<html>
<head>
<meta lang="en">
</head>
<body>
<form action="test.php" method="post" name="addform" enctype="multipart/form-data">
<fieldset>
<hr>
<p>
<label style="width:20%;float:left;">Event Image</label>
<label style="width:1%;float:left;">:</label>
<input type="file" name="event_image" id="event_image" onchange="checkExtension(this.value)" />
</p>
<p style="clear:both;"></p>
<hr>
</fieldset>
<div class="clear"></div>
<p>
<label style="width:20%;float:left;"> </label>
<label style="width:1%;float:left;"> </label>
<input class="button" type="submit" name="submit" value="Submit" />
<input class="button" type="button" value="Cancel" name="cancel" onclick="javascript:history.go(-1);" />
</p>
</form>
</body>
</html>
Next I created file test.php in the same directory with content:
<?php
var_dump($_POST);
var_dump($_FILES);
After connecting file in form I obtained the following content:
array(1) { ["submit"]=> string(6) "Submit" } array(1) { ["event_image"]=> array(5) { ["name"]=> string(38) "image.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(14) "/tmp/phpBQAZXv" ["error"]=> int(0) ["size"]=> int(124622) } }
Show me your result of this test. Probably problem is in processing, not in form.
Create a function in Your Controller by the name of add_event because your are posting your form data to this action. your code may like below
class adminpanel extands CI_Controller{
function add_event(){
echo $_FILES['event_image']['name'];
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to insert data to my database from a form and when i select a type (doctor or patient) to send the data to the appropriate table.
HERE IS THE CODE
<?php
include_once 'header.php';
if (isset($_SESSION['username'])) destroySession();
if(isset($_POST['register']))
{
if (isset($_POST['username']))
{
$fname = sanitizeString($_POST['fname']);
$lname = sanitizeString($_POST['lname']);
$username = sanitizeString($_POST['username']);
$email = sanitizeString($_POST['email']);
$password = sanitizeString($_POST['password']);
if($_POST["answer" === "Doctor"])
{
$DoctorG = sanitizeString($_POST['DoctorG']);
$DoctorAge = ($_POST['DoctorAge']);
$specialty = sanitizeString($_POST['specialty']);
$Doctor_ID = ($_POST['Doctor_ID']);
if (mysql_num_rows(queryMysql("SELECT * FROM doctor
WHERE username='$username'")))
$error = "That username already exists<br /><br />";
else
{
queryMysql("INSERT INTO doctor (fname,lname,username,email,password,gender,age,specialty,doctorID) VALUES('$fname','$lname','$username','$email', '$password','$DoctorG','$DoctorAge','$specialty','$DoctorID')");
die("<h4>Account created</h4>Please Log in.<br /><br />");
}
}
}
}
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<form method="post" action="signup.php">
<fieldset>
<legend>Registration Form</legend>
<label>First Name
<input type="text" name="fname" required="required" />
</label>
<br/>
<br/>
<label>Last Name
<input type="text" name="lname" required="required" />
</label>
<br />
<br />
<label>Username
<input type="text" name="username" required="required" />
</label>
<br />
<br />
<label>Email
<input type="text" name="email" required="required" />
</label>
<br />
<br />
<label>Password
<input type="text" name="password" required="required" />
</label>
<br/><br/>
User Type:
<br/>Doctor
<input type="radio" name="answer" value="Doctor" />
Patient
<input type="radio" name="answer" value="Patient" />
<!--DOCTOR OPTIONS -->
<div id="expandDoctor" style="display:none;">
<label id="Male">Male</label>
<input type="radio" name="DoctorG" value="male" id="DoctorG">
<label id="Female">Female</label>
<input type="radio" name="DoctorG" value="female" id="DoctorG">
<br/>
<br/>
<label id="Age">Age:</label>
<input type="text" name="DoctorAge" id="DoctorAge" />
<br/>
<br/>
<label id="Specialty">Specialty:</label>
<select id="SelectSpecialty" name="specialty">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<br/>
<br/>
<label id="ID">Doctor ID:</label>
<input type="text" name="Doctor_ID" id="Doctor_ID" />
</div>
<!--PATIENT OPTIONS -->
<div id="expandPatient" style="display:none;">
<label id="Male">Male</label>
<input type="radio" name="PatientG" value="male" id="PatientGM">
<label id="Female">Female</label>
<input type="radio" name="PatientG" value="female" id="PatientGF">
<br/>
<br/>
<label id="Age">Age:</label>
<input type="text" name="PatientAge" id="PatientAge" />
<br/>
<br/>
<label id="Disease">Disease:</label>
<select id="SelectDisease" name="specialty">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<br/>
<br/>
<label id="SPID">SPID:</label>
<input type="text" name="PatientSPID" id="PatientSPID" />
</div>
</fieldset>
<input type="submit" value="Register" name="register"/>
</form>
</body>
<script>
$("input[type='radio'][name='answer']").change(function() {
$("[id^=expand]").hide();
$("#expand" + $(this).val()).show();
});</script>
</body>
</html>
I get this error Notice: Undefined offset: 0 in E:\xampp\htdocs\ptixiaki\signup.php on line 21
PS: I dont have all the needed inserts , I just want to test it for the Doctor and if it works for them I will do for the patient also
The error was that i should have if( $_POST["answer"] === "Doctor" ) instead of if($_POST["answer" === "Doctor"]) and then it shows a second error in the INSERT INTO which was an underscore in the Doctor_ID
HERE IS THE NEW CODE....
<?php
/**
* #author Nick Bourlai
* #copyright 2014
*/
include_once 'header.php';
if (isset($_SESSION['username'])) destroySession();
if(isset($_POST['register']))
{
if (isset($_POST['username']))
{
$fname = sanitizeString($_POST['fname']);
$lname = sanitizeString($_POST['lname']);
$username = sanitizeString($_POST['username']);
$email = sanitizeString($_POST['email']);
$password = sanitizeString($_POST['password']);
if( $_POST["answer"] === "Doctor" )
{
$DoctorG = sanitizeString($_POST['DoctorG']);
$DoctorAge = ($_POST['DoctorAge']);
$specialty = sanitizeString($_POST['specialty']);
$Doctor_ID = ($_POST['Doctor_ID']);
if (mysql_num_rows(queryMysql("SELECT * FROM doctor
WHERE username='$username'")))
$error = "That username already exists<br /><br />";
else
{
queryMysql("INSERT INTO doctor (fname,lname,username,email,password,gender,age,specialty,doctorID) VALUES('$fname','$lname','$username','$email', '$password','$DoctorG','$DoctorAge','$specialty','$Doctor_ID')");
die("<h4>Account created</h4>Please Log in.<br /><br />");
}
}
}
}
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<form method="post" action="signup.php">
<fieldset>
<legend>Registration Form</legend>
<label>First Name
<input type="text" name="fname" required="required" />
</label>
<br/>
<br/>
<label>Last Name
<input type="text" name="lname" required="required" />
</label>
<br />
<br />
<label>Username
<input type="text" name="username" required="required" />
</label>
<br />
<br />
<label>Email
<input type="text" name="email" required="required" />
</label>
<br />
<br />
<label>Password
<input type="text" name="password" required="required" />
</label>
<br/><br/>
User Type:
<br/>Doctor
<input type="radio" name="answer" value="Doctor" />
Patient
<input type="radio" name="answer" value="Patient" />
<!--DOCTOR OPTIONS -->
<div id="expandDoctor" style="display:none;">
<label id="Male">Male</label>
<input type="radio" name="DoctorG" value="male" id="DoctorG">
<label id="Female">Female</label>
<input type="radio" name="DoctorG" value="female" id="DoctorG">
<br/>
<br/>
<label id="Age">Age:</label>
<input type="text" name="DoctorAge" id="DoctorAge" />
<br/>
<br/>
<label id="Specialty">Specialty:</label>
<select id="SelectSpecialty" name="specialty">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<br/>
<br/>
<label id="ID">Doctor ID:</label>
<input type="text" name="Doctor_ID" id="Doctor_ID" />
</div>
<!--PATIENT OPTIONS -->
<div id="expandPatient" style="display:none;">
<label id="Male">Male</label>
<input type="radio" name="PatientG" value="male" id="PatientGM">
<label id="Female">Female</label>
<input type="radio" name="PatientG" value="female" id="PatientGF">
<br/>
<br/>
<label id="Age">Age:</label>
<input type="text" name="PatientAge" id="PatientAge" />
<br/>
<br/>
<label id="Disease">Disease:</label>
<select id="SelectDisease" name="specialty">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<br/>
<br/>
<label id="SPID">SPID:</label>
<input type="text" name="PatientSPID" id="PatientSPID" />
</div>
</fieldset>
<input type="submit" value="Register" name="register"/>
</form>
</body>
<script>
$("input[type='radio'][name='answer']").change(function() {
$("[id^=expand]").hide();
$("#expand" + $(this).val()).show();
});</script>
</body>
</html>
I'm totally new to php and I am trying to dynamically change the form displayed when the user makes a choice on a drop down list. I can get the drop down list to show but it does not display anything when I submit.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Forms</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
If (!isset($_GET['userChoice']))
{ //open the if block to write the html to the screen
?>
<h1>Show your html option form</h1>
<form method="GET" action="thirdtry.php" name="userChoice">
<select size="1" id="choice" name="choice">
<option selected="selected">Choose which form you would like</option>
<option value="feedback">Feedback Form </option>
<option value="help">Help Request Form</option>
</select>
<input type="submit">
</form>
<?php
}//close the if block
else{ //show feedback
if($_GET['userChoice']=="feedback")
{
?>
<h1>Show the feedback form</h1>
<form id="fb" name="fb" method="post" >
<fieldset>
<label>First Name:
<br />
<input type="text" name="fName" id="fName" />
</label>
<br />
<label>Last Name:
<br />
<input type="text" name="lName" id="lName" />
</label>
<br />
<label>Street Address:
<br />
<input type="text" name="address" id="address" />
</label>
<br />
<label>City
<br />
<input type="text" name="city" id="city" />
</label>
<br />
<label>State
<br />
<input type="text" name="state" id="state" />
</label>
<br />
<label>Postcode
<br />
<input type="text" name="postcode" id="postcode" />
</label>
<br />
<label>Country
<br />
<input type="text" name="country" id="country" />
</label>
<br />
<label>Email Address:
<br />
<input type="text" name="FromAddress" id="FromAddress" />
</label>
<br />
<label>Your message:
<br />
<textarea name="message" rows="7" cols="30"></textarea> <br />
</label>
<div>How many stars would you give this site? <br />
(We love 5 stars!)<br />
<input type="radio" name="rating" value="1" />1<br />
<input type="radio" name="rating" value="2" />2<br />
<input type="radio" name="rating" value="3" />3<br />
<input type="radio" name="rating" value="4" />4<br />
<input type="radio" name="rating" value="5" />5<br />
</div>
<br />
<input type="submit" />
<input type="reset" />
</fieldset>
</form>
<?php
}
else
{//must be help form
?>
<h1>Show the help form</h1>
<form id="help" method="post" >
<fieldset>
<label>First Name:
<br />
<input type="text" name="fNameHelp" id="fNameHelp" />
</label>
<br />
<label>Last Name:
<br />
<input type="text" name="lNameHelp" id="lNameHelp" />
</label>
<br />
<label>Street Address:
<br />
<input type="text" name="addressHelp" id="addressHelp" />
</label>
<br />
<label>City
<br />
<input type="text" name="cityHelp" id="cityHelp" />
</label>
<br />
<label>State
<br />
<input type="text" name="stateHelp" id="stateHelp" />
</label>
<br />
<label>Postcode
<br />
<input type="text" name="postcodeHelp" id="postcodeHelp" />
</label>
<br />
<label>Country
<br />
<input type="text" name="countryHelp" id="countryHelp" />
</label>
<br />
<label>Email Address:
<br />
<input type="text" name="FromAddress" />
</label>
<br />
<label>Your message:
<br />
<textarea name="messageHelp" rows="7" cols="30"> </textarea> <br />
</label>
<div>How Would you like to be contacted?<br />
(Choose all that apply) <br />
<input type="checkbox" name="ckemail" id="ckemail" value="email" onclick="return validateHelpForm()"/>email<br />
<input type="checkbox" name="cktelephone" id="cktelephone" value="telephone" onclick="return validateHelpForm()"/>telephone<br />
</div>
<br />
<input type="submit" />
<input type="reset" />
</fieldset>
</form>
<?php
}//close the if block
}
?>
</body>
</html>
You're checking for the wrong variable:
If (!isset($_GET['userChoice']))
should be
If (!isset($_GET['choice']))
Also, why are you capitalizing If? (That won't cause an issue - it's just weird ;)
Well first off, do you want the page to refresh, or would you like it to change dynamically without a refresh, using Javascript. From your brief description, I am thinking you want the change to happen without a refresh.
And being a "novice", I would advise you use Jquery as your Framework as opposed to full blown javascript. Here is what I think you're trying to accomplish.
Since PHP is a server-side programming language, you can't dynamically change a webpage without a refresh. Javascript and Jquery are client-side, so many things can happen in your browser without the need or a refresh.
LINK: Here is the example I just created.
////////jquery/javascript///////
$('#changeme').change(function(){
var value = $('#changeme').val();
if(value == 1){
$('#dis1').show();
$('#dis2').hide();
}
else if(value == 2){
$('#dis1').hide();
$('#dis2').show();
}
else{
$('#dis1').hide();
$('#dis2').hide();
}
});
////////HTML///////
<select id="changeme">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<div style="display:none;" id="dis1">Displaying 1</div>
<div style="display:none;" id="dis2">Displaying 2</div>
This is the code for the form:
<div id="regform">
<div id="regform-top">
<h2>User Registration</h2>
<p>Please complete this form</p>
</div>
<form id="register-form" name="register-form" action="submit.php" method="post"
class="validation">
<fieldset>
<table>
<tr>
<td>
<div class="fieldgroup">
<label for="user-name">User name*: </label>
<input type="text" id="name" name="name" value="" size="12" class="inpt" /><br
class="clear" />
</div>
<div class="fieldgroup">
<label for="password">Password*: </label>
<input type="password" id="password" name="password" value="" size="12" class="inpt"
/><br class="clear" />
</div>
</td>
<td id="form-note">
<br />
<p><strong>Form Instructions</strong></p>
<p>*Required Field</p>
</td>
</tr>
</table>
<table id="bottom-reg">
<tr>
<td><br />
<div class="fieldgroup">
<label for="firstname">First name*</label>
<input type="text" id="firstname" name="firstname" value="" size="12" class="inpt" />
<br class="clear" />
</div>
<div class="fieldgroup">
<label for="email">Email Address* </label>
<input type="text" id="email" name="email" value="" size="12" class="inpt" /><br
class="clear" />
</div>
<div class="fieldgroup">
<label for="address1">Address 1* </label>
<input type="text" id="address1" name="address1" value="" size="12" class="inpt" />
<br class="clear" />
</div>
<label for="address2">Address 2</label>
<input type="text" id="address2" name="address2" value="" size="12" class="inpt" />
<br class="clear" />
<label for="address2">Address 3</label>
<input type="text" id="address3" name="address3" value="" size="12" class="inpt" />
<br class="clear" />
<div class="fieldgroup">
<label for="country">Country*</label>
<input type="text" id="country" name="country" value="" size="12" class="inpt" /><br
class="clear" />
</div>
</td>
<td><br />
<div class="fieldgroup">
<label for="lastname">Last name*</label>
<input type="text" id="lastname" name="lastname" value="" size="12" class="inpt" />
<br class="clear" />
</div>
<div class="fieldgroup">
<label for="group">Group* </label>
<input type="text" id="name" name="group" value="" size="12" class="inpt" />
<br class="clear" />
</div>
<div class="fieldgroup">
<label for="city">City* </label>
<input type="text" id="city" name="city" value="" size="12" class="inpt" /><br
class="clear" />
</div>
<div class="fieldgroup">
<label for="city">State* </label>
<input type="text" id="state" name="state" value="" size="12" class="inpt" /><br
class="clear" />
</div>
<div class="fieldgroup">
<label for="zip">Zip*</label>
<input type="text" id="zip" name="zip" value="" size="12" class="inpt" /><br
class="clear" />
</div>
</td>
</tr>
</table>
<input type="submit" value="Register" class="submit-btn" />
</fieldset>
</form>
This is the code for submit.php:
<?php
$con = mysql_connect("localhost","viatechp_invacar","storefront72");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("viatechp_invacare", $con);
$sql="INSERT INTO registration(username,password,fname,lname,group,
address1,address2,address3, email,city,state,zip,country )
VALUES
('$_POST[name]','$_POST[password]', '$_POST[firstname]','$_POST[lastname]','
$_POST[group]','$_POST[address1]','$_POST[address2]','$_POST[address3]',
'$_POST[email]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[country]'
)" ;
$query = mysql_query($sql) or die(mysql_error());
$results = mysql_fetch_assoc($query);
if ($results) {
echo 'The query returned ' . $results[ 'registration' ];
} else {
echo 'The query did not return any results';
} ?>
echo $sql;
?>
It is showing an error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group,address1,address2,address3,email,city,state,zip,country ) VALUES ( 'sdfdsf' at line 1
group is an SQL keyword. If this is the name of one of your fields you must enclose it with ` like so:
`group`,`address1`,...
This tells mySQL that it is a field name and not the keyword. It would be good practice to enclose all your fields within ` to prevent any errors like this you may not have noticed.
Spot on by pburgess. GROUP, ORDER are some common field names that we use while programming. Make sure to enclose these using backticks group, always a good practice.
$sql="INSERT INTO registration(username,password,fname,lname,`group`,
address1,address2,address3, email,city,state,zip,country )
VALUES
('$_POST[name]','$_POST[password]', '$_POST[firstname]','$_POST[lastname]','
$_POST[group]','$_POST[address1]','$_POST[address2]','$_POST[address3]',
'$_POST[email]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[country]'
)" ;
Try this
$sql="INSERT INTO registration(`username`,`password`,`fname`,`lname`,`group`,
`address1`,`address2`,`address3`, `email`,`city`,`state`,`zip`,`country` )
VALUES
('$_POST[name]','$_POST[password]', '$_POST[firstname]','$_POST[lastname]',
'$_POST[group]','$_POST[address1]','$_POST[address2]','$_POST[address3]',
'$_POST[email]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[country]')" ;
Because you got some field names which is reserved keywords like for example you have group
Your $_POST values is missing quotes, Try updating them
$sql="INSERT INTO registration
(`username`,`password`,`fname`,`lname`,`group`,`address1`,`address2`,`address3`, `email`,`city`,`state`,`zip`,`country`)
VALUES
('$_POST[\"name\"]','$_POST[\"password\"]',$_POST[\"firstname\"]','$_POST[\"lastname\"]','
$_POST[\"group\"]','$_POST[\"address1\"]','$_POST[\"address2\"]','$_POST[\"address3\"]',
'$_POST[\"email\"]','$_POST[\"city\"]','$_POST[\"state\"]','$_POST[\"zip\"]','$_POST[\"country\"]'
)" ;
Well it is too late but this might help someone. Whenever you want to check why your query doesnt' work.. Always try to echo your query and paste it to the phpmyadmin and it will throw the mySQL error which are more easy to understand that what's the issue in query