HTML FORM
<form class="form" method="post" action="process.php">
<h4 class="form-heading">Please New Enter Customer Information</h4>
<label for="inital">Inital:</label>
<select id="inital" name="inital" required="required">
<option value="mr">Mr</option>
<option value="ms">Ms</option>
<option value="mrs">Mrs</option>
<option value="prof">Prof</option>
<option value="dr">Dr</option>
</select>
<label for="firstname">First Name:</label>
<input type="text" placeholder="First Name" name="firstname" required="required" >
<label for="lastname">last Name:</label>
<input type="text" placeholder="Last Name" name="lastname" required="required">
<label for="mobile">Mobile:</label>
<input type="tel" placeholder="Mobile" name="mobile" required="required">
<label for="landline">Landline:</label>
<input type="tel" placeholder="Landline" name="landline">
<label for="email">Email:</label>
<input type="email" placeholder="Email" name="email" required="required">
<label for="address">Address:</label>
<input type="text" placeholder="Address" name="address" required="required">
<label for="postocde">Postal Code:</label>
<input type="text" placeholder="Post Code" name="postcode">
<label for="accessibility">Accessibility:</label>
<input type="text" placeholder="Accessibility Needs" name="accessibility" value="">
<button class="btn btn-large btn-primary" type="submit">Enter</button>
process.php
<? php
require( '../connect_db.php' ) ;
$inital = $sql->real_escape_string($_POST[inital]);
$firstname = $sql->real_escape_string($_POST[firstname]);
$lastname = $sql->real_escape_string($_POST[lastname]);
$mobile = $sql->real_escape_string($_POST[mobile]);
$landline = $sql->real_escape_string($_POST[landline]);
$email = $sql->real_escape_string($_POST[email]);
$address = $sql->real_escape_string($_POST[address]);
$postcode = $sql->real_escape_string($_POST[postcode]);
$accessibility = $sql->real_escape_string($_POST[accessibility]);
$query = "INSERT INTO `customer` (inital, firstname, lastname, mobile, landline, email, address, postcode, accessibility) VALUES ('$inital','$firstname', '$lastname','$mobile','$landline','$email','$address','$postcode','$accessibility')";
/* execute the query, nice and simple */
$sql->query($query) or die($query.'<br />'.$sql->error);
?>
I have tried alternatives too but to no satisfaction like not including $inital =($_POST[inital]); Instead putting right into INSERT INTO section but that still does not help either.
It either prints out the whole code on screen or blank. I've looked at similar problems on here and on forums all them seem to present the issue differently and when i change it suit the so called answer it still does not work!
My other page that lists all the tables using the following connection required statment works works fine so there is no problem with connection to the database but at this moment just cannot insert content. Grr
Two problems:
change <? php to <?php
and then add quotes to your post data values. $_POST[inital] to $_POST['inital']
and for your information i would do isset($_POST['value']) ? $_POST['value'] : '';
you still need to check post value before using it.
Check the <? php tag. it should be <?php
Related
I am building a simple client management system that allows users to input client data into a form populated in a modal. The idea is that when the user completes the form in the modal by clicking Create New Client, new client information will be stored into the predefined mysql table named client. I am using a nearly identical php script throughout the site to create new users which works fine.
The primary difference with this script is that is called from a form that is enclosed within a modal that is enclosed within divs. Could that possibly be inhibiting my scripting from following through on the query?
There are no error messages other than my own defined if else calls. The data will echo on Submit but information will not actually insert into the data in mysql. I'm still new to anything beyond html and css, so any help will be greatly appreciated and reciprocated as I continue to get a handle on this journey. Reference code below
newclient.php
<?php
session_start();
include 'dbh.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
$comname = $_POST['comname'];
$primcon = $_POST['primcon'];
$addr = $_POST['addr'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phn = $_POST['phn'];
$websi = $_POST['websi'];
$email = $_POST['email'];
$activ = $_POST['activ'];
$sql = "INSERT INTO client (comname, primcon, addr, city, state, zip, phn,
websi, email, activ )
VALUES ('$comname', '$primcon', '$addr', '$city', '$state', '$zip', '$phn',
'$websi', '$email', '$activ')";
$result = mysqli_query($conn, $sql);
echo $comname;
echo $primcon;
echo $addr;
echo $city;
echo $state;
echo $zip;
echo $phn;
echo $websi;
echo $email;
echo $activ;
//header("Location: login.html");
admin.html - where users actually create new clients (modal content only)
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>New Client Registration</h2>
</div>
<div class="modal-body">
<form align="center"
action="http://localhost:1234/housenotes/newclient.php" method="POST">
<input type="text" placeholder="Company Name" name="comname"
required>
<input type="text" placeholder="Primary Contact" name="primcon"
required>
<input type="text" placeholder="Street Address" name="addr"
required> <br>
<input type="text" placeholder="City" name="city" required>
<input type="text" placeholder="State" name="state" required>
<input type="text" placeholder="Zip" name="zip" required> <br>
<input type="text" placeholder="Phone Number" name="phn"
required>
<input type="text" placeholder="Website" name="websi" required>
<input type="text" placeholder="Email" name="email" required>
<br>
<input type="radio" name="activ" value="Potential" checked>
Potential
<input type="radio" name="activ" value="Engaged"> Engaged
<input type="radio" name="activ" value="Active"> Active<br>
<button type="submit" class="button" style="width:15%;">Create
New Client</button>
</form>
</div>
<div class="modal-footer">
<h3>housenotes</h3>
</div>
Again, any help would be greatly appreciated! Thanks in advance!
I'm attempting to insert the data collected on the form into a mysql database. I'm able to make a successful connection but the data is not inserted. I've read many similar questions but have been unsuccessful so far.
sqldatabase.php
<?php
$servername = "localhost";
$username = "USER";
$password = "PASS";
$dbname = "DATABASE";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$first_spouse = $_POST['first_spouse'];
$last_spouse = $_POST['last_spouse'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phonehome = $_POST['phonehome'];
$phonecell = $_POST['phonecell'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$occupation = $_POST['occupation'];
$shirt_size = $_POST['shirt_size'];
$cap_size = $_POST['cap_size'];
$shirtnum1 = $_POST['shirtnum1'];
$shirtnum2 = $_POST['shirtnum2'];
$desc = $_POST['desc'];
$bylaws_rules = $_POST['bylaws_rules'];
$umpires = $_POST['umpires'];
$alcohol = $_POST['alcohol'];
$waiver = $_POST['waiver'];
$sql="INSERT INTO 'softball_reg_2016' (first_name, last_name, first_spouse, last_spouse,
address, city, state, zip, phonehome, phonecell, email, dob, occupation, shirt_size,
cap_size, shirtnum1, shirtnum2, desc, bylaws_rules, umpires, alcohol, waiver)
VALUES ('$_POST[first_name]', '$_POST[last_name]', '$_POST[first_spouse]', '$_POST[last_spouse]',
'$_POST[address]', '$_POST[city]', '$_POST[city]', '$_POST[state]', '$_POST[zip]',
'$_POST[phonehome]', '$_POST[phonecell]', '$_POST[email]', '$_POST[dob]', '$_POST[occupation]',
'$_POST[shirt_size]', '$_POST[cap_size]', '$_POST[shirtnum1]', '$_POST[shirtnum2]',
'$_POST[desc]', '$_POST[bylaws_rules]', '$_POST[umpires]', '$_POST[alcohol]', '$_POST[waiver]')";
echo "Connected successfully";
mysqli_close($conn);
?>
My html
<form action="/php/sqldatabase.php" method="POST" id="registration">
<h2>Registration for 2016 Summer Season (April-September)</h2>
<p>
<label for="name">Name:</label>
<input type="text" id="first_name" name="first_name" placeholder="First Name" autofocus="" />
<input type="text" id="last_name" name="last_name" placeholder="Last Name" />
</p>
<p>
<label for="spouse">Name of Spouse<i>(Optional)</i>:</label>
<input type="text" id="first_spouse" name="first_spouse" placeholder="First Name" />
<input type="text" id="last_spouse" name="last_spouse" placeholder="Last Name" />
</p>
<p>
<label for="address1">Address:</label>
<input type="text" id="address" name="address" placeholder="Street Address" />
<input type="text" id="city" name="city" placeholder="City" />
</p>
<p>
<label for="address2"></label>
<input type="text" id="state" name="state" placeholder="State" />
<input type="number" id="zip" name="zip" placeholder="Zip Code" />
</p>
<p>
<label for="phone">Phone:</label>
<input type="tel" id="phonehome" name="phone" placeholder="Home Phone" />
<input type="tel" id="phonecell" name="phone" placeholder="Work/Cell Phone" />
</p>
<p>
<label for="phone">Email:</label>
<input type="email" id="email" name="email" />
</p>
<p>
<label for="dob">Date of Birth:</label>
<input type="date" id="dob" name="dob" />
</p>
<p>
<label for="occupation">Occupation (Former, if retired):</label>
<input type="text" id="occupation" name="occupation" />
</p>
<div id="shirt">
<p>
<label for="size">Uniform:</label>
<select name="shirt_size" id="shirt_size">
<option value="">Shirt Size</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="XL">XL</option>
<option value="2XL">2XL</option>
<option value="3XL">3XL</option>
</select>
<select name"cap_size" id="cap_size">
<option value="">Cap Size</option>
<option value="XS/S">XS/S</option>
<option value="S/M">S/M</option>
<option value="M/L">M/L</option>
<option value="L/XL">L/XL</option>
</select>
</p>
<p>
<label for="shirtnum">Shirt Number:</label>
<input type="number" id="shirtnum1" name="shirtnum1" placeholder="1st Choice" min="0" max="99" />
<input type="number" id="shirtnum2" name="shirtnum2" placeholder="2nd Choice" min="0" max="99" />
</p>
</div>
<div id="describe">
<p>
<span class="describe1">
<b>Describe any information you deem important regarding your ability and/or availability or any other information you deem important to the season.</b>
<textarea name="description" id="desc" cols="30" rows="10"></textarea>
</span>
</p>
</div>
<div id="ethics">
<h2>Code of Ethics</h2>
<p>
<span class="ethics1">
<input type="checkbox" id="bylaws_rules" name="bylaws_rules" />
I agree to abide by the Bylaws and decisions of the Club and Club Officials.
</span>
</p>
<p>
<span class="ethics1">
<input type="checkbox" id="umpires" name="umpires" />
I agree to accept the decisions of the Umpires and Team Managers.
</span>
</p>
<p>
<span class="ethics1">
<input type="checkbox" id="alcohol" name="alcohol" />
I agree to abstain from alcoholic beverages prior to a game.
</span>
</p>
</div>
<div id="waiver">
<h2>Release of Liability</h2>
<p>
<b>I agree to hold harmless the club.</b>
</p>
<input type="checkbox" id="waiver" name="waiver" />
</div>
<ol class="requires">
<li>Dues are $95 and should be received by April 6, 2016</li>
<li>If you decline to play after being drafted, your registration fee will not be refunded.</li>
<li>All members must be at least 50 years old by December 31, 2016</li>
<li>The deadline for receipt of registrations is April 6, 2016. Registrations received after this date will
not be processed for the player drat. Assignments to teams will then be made according to League guidelines
regarding late registering players.</li>
<li>Registrations received without the correct fee will not be considered as received and will not be valid until the correct fee is received.</li>
</ol>
<p> </p>
<p> </p>
<p> </p>
<p>
<button type="submit" id="register">Register!</button>
</p>
</form>
Thank you for any help!
Posting as a community wiki.
There are a few things wrong here.
First, you never executed the query.
You never check for empty() fields, which might insert empty rows on the table.
Consult the manual:
http://php.net/manual/en/mysqli.query.php
Object oriented style
mixed mysqli::query ( string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )
Procedural style
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )
Then you're using the wrong identifier qualifiers for your table:
INSERT INTO 'softball_reg_2016'
^ ^
being regular single quotes, where it should be ticks or no quotes at all:
INSERT INTO `softball_reg_2016`
and that alone would have thrown you a syntax error.
Read up on identifier qualifiers:
http://dev.mysql.com/doc/en/identifier-qualifiers.html
Then you're using desc as a column name which is a MySQL reserved word. That also would have thrown you an error about it. So, either you rename it to something else, or wrap it in ticks.
`desc`
Reference:
https://dev.mysql.com/doc/refman/5.5/en/keywords.html
Also check for errors:
http://php.net/manual/en/mysqli.error.php
http://php.net/manual/en/function.error-reporting.php
Plus, your present code is open to SQL injection. Use mysqli_* with prepared statements, or PDO with prepared statements.
Also, since you already declared variables to your POST arrays, why put the POST arrays in the query? Just used the variables. You're using more code for nothing really.
And as noted in comments:
"You also have two input fields with same name: phone. Is that intended or just the copy/paste usual problem? – FirstOne"
You need to execute the query. You have just taken the string.
Here is what you are missing. Put
mysqli_query($conn,$sql);
before the success message.
You didn't excute the query
you have to do
mysqli_query($conn,$query);
before closing the connection
I want to be able to send form data from my website to my email with php. However, I tried all of the examples online and none of them worked for me. I don't know why. Am I missing a plugin?
<form class="formmargin" id="email-form" action="send_form_email.php" method="post" target="iframe_dbcpmgmy" onsubmit="sent_dbcpmgmy = true" enctype="multipart/form-data">
<div style="float:left; width:50%; padding-right:2.5%">
<label for="name">Name:</label>
<input class="w-input" type="text" name="name" placeholder="Enter your name" id="name" required="required" data-name="Name">
<label for="company_name">Company Name:</label>
<input class="w-input" type="text" name="company_name" placeholder="Enter your company name" id="company_name" required="required" data-name="Company Name">
</div>
<div style="float:left; width:50%; padding-left:2.5%">
<label for="email_address">Email Address:</label>
<input class="w-input" type="email" name="email_address" placeholder="Enter your email address" id="email_address" required="required" data-name="Email Address">
<label for="phone_number">Phone Number:</label>
<input class="w-input" type="text" name="phone_number" placeholder="Enter your phone number" id="phone_number" required="required" data-name="Phone Number">
<label for="uploaded_file">Upload a file (Optional)</label>
<input type="file" name="uploaded_file" id="uploaded_file">
</div>
<input style="clear:both" type="submit" name="submit" value="Submit" class="submitbutton">
</form>
can someone tell me what i should put in the send_form_email.php file?
You will want to create a second page getting all of the post information then you will want to use the php mail function.
If you haven't already created the post variables they will look like this
$name = $_POST['name'];
$company = $_POST['company_name'];
$to = $_POST['email_address'];
If you want to format it to have new lines in the message, because by default it will be one huge line use \n as no html/css formatting will work easily
mail ($to , $subject , $message );
Array count is not working properly in my form .. I cloned the input values
please check whole code in this link Click Here
Here is php code
if(isset($_POST['Submit'])) {
echo $cnt = count($_POST['task_description']); //die();
for($i=0;$i<$cnt; $i++ ){
mysqli_query($con,"INSERT INTO ts_task(project,task_title,task_description,minutes,created_date,status)VALUES('".$_POST['project'][$i]."','".$_POST['task_title'][$i]."','".$_POST['task_description'][$i]."','".$_POST['minutes'][$i]."','".date('Y-m-d')."','".$_POST['status'][$i]."')");
}
header("Location:tasklist.php");
die();
}
Here is my HTML code
First Array
<input name="task_title[]" class="form-control" type="text" style="width:150px;">
<input class="form-control" type="text" name="task_description[]" style="width:150px;">
<input class="form-control" type="text" name="project[]" style="width:150px;">
<input class="form-control" type="text" name="minutes[]" style="width:150px;">
Second Array
<input name="task_title[]" class="form-control" type="text" style="width:150px;">
<input class="form-control" type="text" name="task_description[]" style="width:150px;">
<input class="form-control" type="text" name="project[]" style="width:150px;">
<input class="form-control" type="text" name="minutes[]" style="width:150px;">
i print the count of POST value but it return only 1..
please verify :
both textbox contains at least some value.
both are in same forms.
So I have this form. I would like to store the data into my database. However, it's not and there is no error log. I would really appreciate help, as it's due in 2 days and I've been trying for the past week or so.
<form enctype="multipart/form-data" action="preview.php" method="post" class="f">
<p>
<p>
<p><label for="name">Teacher's Name:</label>
<input type="text" style="font-family:Gloria Hallelujah" size="35" name="name" id="name" autofocus required></p>
<p><label for="name">Title:</label>
<input type="text" style="font-family:Gloria Hallelujah" size="35" name="title" id="title" autofocus required></p>
<p><label for="done">Done By:</label>
<input type="text" style="font-family:Gloria Hallelujah" size="35" name="done" id="done" required></p>
<p><label for="no">Class:</label>
<input type="text" style="font-family:Gloria Hallelujah" size="15" name="class" id="no" required></p>
<p><label for="sch">School:</label>
<select name="sch">
<option value="seg">School of Engineering (SEG)</option>
<option value="sit">School of Information Technology (SIT)</option>
<option value="sdn">School of Design (SDN)</option>
<option value="sbm">School of Business Management (SBM)</option>
<option value="shs">School of Health Sciences (SHS)</option>
<option value="scl">School of Chemical & Life Sciences (SCL)</option>
<option value="sidm">School of Interactive and Digital Media (SIDM)</option>
</select>
<p><label for="msg">Show your Gratitude! :</label>
<textarea class="tarea" maxlength="3000" cols="38.5" rows="6" name="comments" placeholder="Enter Message here..." required></textarea>
<p class="limit">Char limit: 3000 chars.</p>
</p>
And it goes to preview.php where it is supposed to store the data.
<?php
include "mysqli.connect.php";
include "fbmain.php";
$sql = "INSERT INTO table(teacherName, title, doneBy, studentClass, school, message)VALUES ('$_POST[name]','$_POST[title]','$_POST[done]','$_POST[class]','$_POST[comments]') where facebookId = '".$me['id']."'";
INSERT command does not need WHERE clause .
P.S : You are wide open to SQL Injection.
('$_POST[name]','$_POST[title]','...
Change to:
('{$_POST[name]}','{$_POST[title]}','...
this is better
see http://ir1.php.net/mysqli_query
And check Database And check WHERE structs
You can Display Errors And Fix them By Put this code After Query
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
}
$_POST[name] isn't the same as $_POST['name'], $_POST[title] isn't the same as $_POST['title'] etc.
Instead of:
$sql = "INSERT INTO table(teacherName, title, doneBy, studentClass, school, message)VALUES ('$_POST[name]','$_POST[title]','$_POST[done]','$_POST[class]','$_POST[comments]') where facebookId = '".$me['id']."'";
try
$name = $_POST['name'];
$title = $_POST['title'];
$done = $_POST['done'];
$class = $_POST['class'];
$comments = $_POST['comments'];
$sql = "INSERT INTO table(teacherName, title, doneBy, studentClass, school, message)VALUES ('{$name}','{$title}','{$done}','{$class}','{comments}') where facebookId = '".$me['id']."'";
But above is just to get it to work!
It isn't the recommended way of doing this. You should do it with parametized queries... http://forum.codecall.net/topic/44392-php-5-mysqli-prepared-statements/