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
Related
I'm trying to create registration form using Codeigniter 3. This problem comes when I try to add value in each input like this:
value="<?php echo set_value('name'); ?>"
Here's my view content_register.php:
<form class="usr-input" action="/users" method="post">
<div>
<label for="name">Nama Lengkap<span style="padding-left: 90px;">:</span></label>
<input id="name" name="name" size="40" type="text" value="<?php echo set_value('name'); ?>"/>
<br>
<label for="username">Username<span style="padding-left: 124px;">:</span></label>
<input id="username" name="username" size="40" type="text" value="<?php echo set_value('username'); ?>"/>
<br>
<label for="password">Password<span style="padding-left: 125px;">:</span></label>
<input id="password" name="password" size="40" type="password" value="<?php echo set_value('password'); ?>"/>
<br>
<label for="email">Email<span style="padding-left: 155px;">:</span></label>
<input id="email" name="email" size="40" type="text" value="<?php echo set_value('email'); ?>"/>
<br>
<label for="telepon">No. Telepon<span style="padding-left: 111px;">:</span></label>
<input id="telepon" name="telepon" size="40" type="text" value="<?php echo set_value('phone'); ?>"/>
<br>
<label for="sex">Jenis Kelamin<span style="padding-left: 96px;">:</span></label>
<select>
<option value="male">Laki-laki</option>
<option value="female">Perempuan</option>
</select>
<br>
<label for="alamat">Alamat<span style="padding-left: 146px;">:</span></label>
<textarea id="alamat" name="alamat" rows="5" cols="71" type="text" value="<?php echo set_value('name'); ?>"/></textarea>
<br>
<input type="checkbox" name="vehicle" value="Bike"> Saya telah membaca dan menerima Syarat dan Peraturan dari .</input>
</div>
</form>
And the whole page messed up. It becomes like this:
Before I add value (which the code like this:)
<form class="usr-input" action="/users" method="post">
<div>
<label for="name">Nama Lengkap<span style="padding-left: 90px;">:</span></label>
<input id="name" name="name" size="40" type="text" />
<br>
<label for="username">Username<span style="padding-left: 124px;">:</span></label>
<input id="username" name="username" size="40" type="text" />
<br>
<label for="password">Password<span style="padding-left: 125px;">:</span></label>
<input id="password" name="password" size="40" type="password" />
<br>
<label for="email">Email<span style="padding-left: 155px;">:</span></label>
<input id="email" name="email" size="40" type="text" />
<br>
<label for="telepon">No. Telepon<span style="padding-left: 111px;">:</span></label>
<input id="telepon" name="telepon" size="40" type="text" />
<br>
<label for="sex">Jenis Kelamin<span style="padding-left: 96px;">:</span></label>
<select>
<option value="male">Laki-laki</option>
<option value="female">Perempuan</option>
</select>
<br>
<label for="alamat">Alamat<span style="padding-left: 146px;">:</span></label>
<textarea id="alamat" name="alamat" rows="5" cols="71" type="text" /></textarea>
<br>
<input type="checkbox" name="vehicle" value="Bike"> Saya telah membaca dan menerima Syarat dan Peraturan dari .</input>
</div>
</form>
It works well. The page should be like this:
UPDATE
Here's the controller:
<?php
class page extends CI_Controller {
function __construct() {
parent::__construct();
// path to simple_html_dom
}
function index() {
$this->load->view('page_header');
$this->load->view('content_front');
$this->load->view('page_footer');
}
function login() {
$this->load->view('page_header');
$this->load->view('content_login');
$this->load->view('page_footer');
}
function register() {
$this->load->view('page_header');
$this->load->view('content_register');
$this->load->view('page_footer');
}
}
?>
Can you help me what's wrong with this code? Or any information that I miss?
Thank you.
Change your URL into
action="/users"
to
action="<?php echo base_url()/controller/method?"
Because action="/users" is not a valid URL
I am using X7 Chat and trying to install it on my localhost. I got an error on the install.php Here's what I have:
I'm not sure how to fix this. Any help please?
And here's the code on the install.php:
<?php if(empty($fail)): ?>
<form id="dbform">
<?php if(!$config): ?>
<h2>Database Connection Details</h2>
<b><label for="host">Database Host</label></b>
<input type="text" name="host" value="localhost" />
<hr />
<b><label for="user">Database Username</label></b>
<input type="text" name="user" value="" />
<hr />
<b><label for="pass">Database Password</label></b>
<input type="password" name="pass" value="" />
<hr />
<b><label for="dbname">Database Name</label></b>
<input type="text" name="dbname" value="" />
<hr />
<b><label for="prefix">Table Prefix</label></b>
<input type="text" name="prefix" value="x7chat_" />
<hr />
<?php endif; ?>
<h2>Admin Account Details</h2>
<b><label for="admin_username">Admin Username</label></b>
<input type="text" name="admin_username" value="" />
<hr />
<b><label for="admin_username">Admin Password</label></b>
<input type="password" name="admin_password" value="" />
<hr />
<b><label for="retype_admin_password">Retype Admin Password</label></b>
<input type="password" name="retype_admin_password" value="" />
<hr />
<b><label for="admin_email">Admin E-Mail</label></b>
<input type="text" name="admin_email" value="" />
<hr />
<h2>Chatroom Details</h2>
<b><label for="title">Chatroom Name</label></b>
<input type="text" name="title" value="" />
<hr />
<input id="continue" type="submit" value="Continue" />
</form>
<?php else: ?>
<p>One or more critical checks failed. Please correct them before installing X7 Chat.</p>
<?php endif; ?>
I have the following sets of data inside the form that are dynamically added by JavaScript so the user can add unlimited number of data rows:
<div class="row">
<input type="text" value="" name="title[]" />
<input type="text" value="" name="label[]" />
<input type="text" value="" name="value[]" />
<input type="text" value="" name="label[]" />
<input type="text" value="" name="value[]" />
<input type="text" value="" name="label[]" />
<input type="text" value="" name="value[]" />
</div>
<div class="row">
<input type="text" value="" name="title[]" />
<input type="text" value="" name="label[]" />
<input type="text" value="" name="value[]" />
<input type="text" value="" name="label[]" />
<input type="text" value="" name="value[]" />
</div>
<div class="row">
<input type="text" value="" name="title[]" />
<input type="text" value="" name="label[]" />
<input type="text" value="" name="value[]" />
</div>
My objective is then be able to print/post it in the same order so it would look like:
<h2>Title</h2>
<div class="label">Label</div>
<div class="value">Value</div>
<h2>Title</h2>
<div class="label">Label</div>
<div class="value">Value</div>
<h2>Title</h2>
<div class="label">Label</div>
<div class="value">Value</div>
My problem is that I can not figure out how to loop through sets of data and print one by one in the same order. Here is my current code but it just does not make sense what it prints and I know I am doing this the wrong way.
foreach ($_POST['title'] as $title) {
echo $title;
foreach ($_POST['label'] as $label) {
echo $label;
}
}
I would appreciate any help.
Thank you.
EDIT: Just wanted to note that rows may have different number of inputs.
If the labels and values always come in same-sized groups with each title, you can use a for loop nested in your foreach loop.
$group_size = 3;
foreach ($_POST['title'] as $i => $title) {
echo $title;
for ($j = $i*$group_size; $j < ($i+1)*$group_size; $j++) {
echo $_POST['label'][$j];
echo $_POST['value'][$j];
}
}
Try something like this:
<form method="post">
<div class="row">
title 1:
<input type="text" value="" name="title[]" />
label 1:
<input type="text" value="" name="label[]" />
value 1:
<input type="text" value="" name="value[]" />
</div>
<div class="row">
title 2:
<input type="text" value="" name="title[]" />
label 2:
<input type="text" value="" name="label[]" />
value 2:
<input type="text" value="" name="value[]" />
</div>
<div class="row">
title 3:
<input type="text" value="" name="title[]" />
label 3:
<input type="text" value="" name="label[]" />
value 3:
<input type="text" value="" name="value[]" />
</div>
<input type="submit">
</form>
<?php
foreach ($_POST['title'] as $i => $title) {
echo"
<ul>
<li>{$_POST['title'][$i]}</li>
<li>{$_POST['label'][$i]}</li>
<li>{$_POST['value'][$i]}</li>
</ul>
";
}
See demo here. Good luck!
Hey guys I've been trying to do a code where I submit a form from a PHP Order Page so that it can update the MySQL Database with the required information
I've got the Order PHP Code Here:
<form action="http://zim.cs.uow.edu.au/~ga420/order.php" method="post">
<tr>
<th>Shirts</th>
<th>Quantity</th>
</tr>
<tr>
<td>
<br />
<input type="checkbox" name="items" value="SH01" />
<label for="rd1">Obey T-Shirt: $9.99</label>
</div>
<br />
<input type="checkbox" name="items" value="SH02" />
<label for="rd1">Obey Professor: $9.99</label>
</div>
<br />
<input type="checkbox" name="items" value="SH03" />
<label for="rd1">Hustle T-Shirt: $9.99</label>
</div>
<br />
<input type="checkbox" name="items" value="SH04" />
<label for="rd1">Hip-Hop Support: $9.99</label>
</div>
<br />
<input type="checkbox" name="items" value="SH05" />
<label for="rd1">90's Shirt: $9.99</label>
</div>
<br />
<input type="checkbox" name="items" value="SH06" />
<label for="rd1">DOPE Shirt: $9.99</label>
</div>
<br />
<br />
</td>
<td>
<br />
<input type="text" name="qty" size="2" />
<br/>
<input type="text" name="qty" size="2" />
<br/>
<input type="text" name="qty" size="2" />
<br/>
<input type="text" name="qty" size="2" />
<br/>
<input type="text" name="qty" size="2" />
<br/>
<input type="text" name="qty" size="2" />
<br/>
<br />
</td>
</tr>
<tr>
<td>
<br />
<input type="checkbox" name="items[]" value="SO1" />
<label for="rd1">Shoe - Red Lace: $19.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SO2" />
<label for="rd1">Shoe - Red High Top: $19.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SO3" />
<label for="rd1">Shoe - White: $19.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SO4" />
<label for="rd1">Shoe - Black: $19.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SO5" />
<label for="rd1">Shoe - Black High Top: $19.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SO6" />
<label for="rd1">Red Basketball: $19.99</label>
</div>
<br />
<br />
</td>
<td>
<br />
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<br />
</td>
</tr>
<tr>
<td>
<br />
<input type="checkbox" name="items[]" value="SN1" />
<label for="rd1">Snapback Bullets: $29.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SN2" />
<label for="rd1">Snapback: $29.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SN3" />
<label for="rd1">Snapback Bullets: $29.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SN4" />
<label for="rd1">Snapback Bullets: $29.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SN5" />
<label for="rd1">Snapback Bullets: $29.99</label>
</div>
<br />
<input type="checkbox" name="items[]" value="SN6" />
<label for="rd1">Snapback Bullets: $29.99</label>
</div>
<br />
<br />
</td>
<td>
<br />
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<input type="text" name="qty[]" size="2" />
<br/>
<br />
</td>
</tr>
</tr>
</table>
<br />
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])){
$conn = mysql_connect('url','username','password');
if (!$con){
die("Could Not Connect: " . mysql_error());
}
mysql_select_db("db",$conn);
$sql = "INSERT INTO Order_Information(Order_ID,Order_Items,Order_Quantity) VALUES (null,$_POST[items]','$_POST[qty]')";
mysql_query($sql, $con);
mysql_close($con);
}
?>
Obviously my username and password I won't display but when I hit the submit button it says that it cannot connect.
You can try the form yourself on this website:
http://zim.cs.uow.edu.au/~ga420/order.php
How come it is saying that I can't connect when clearly I have been putting the right details in.
Can anyone help? this has been stressing me out :'(
Your help is appreciated greatly!!
You need to serialize all your inputs/quantities if you will have the same name "qty" in all fields. I will update my answer later if you do t get answer about this.
You had also small bugs on your code, notice this:
VALUES (null,'$_POST[items]','$_POST[qty]')"; - you were missing ' before $_POST[items]
$conn = mysql_connect('zim.cs.uow.edu.au','username','password'); - $conn with 2 "n"
So, a corrected version would be:
<?php
if (isset($_POST['submit'])){
$con = mysql_connect('url','username','password');
if (!$con){
die("Could Not Connect: " . mysql_error());
}
mysql_select_db("db",$con);
$sql = "INSERT INTO Order_Information(Order_ID,Order_Items,Order_Quantity) VALUES (null,'$_POST[items]','$_POST[qty]')";
mysql_query($sql, $con);
mysql_close($con);
}
?>
Change to this. You did some mistake on $conn and $con. Then, '$_POST[items]','$_POST[qty]' in query.
if (isset($_POST['submit'])){
$conn = mysql_connect('url','username','password');
if (!$conn){
die("Could Not Connect: " . mysql_error());
}
mysql_select_db("db",$conn);
$sql = "INSERT INTO Order_Information(Order_ID,Order_Items,Order_Quantity) VALUES (null,'$_POST[items]','$_POST[qty]')";
mysql_query($sql, $conn);
mysql_close($conn);
}
Hope this help
i found few similar questions here but from answers i didn't get the whole picture of how should work.
I have a subscription form in a page:
<form method="post" action="index.php/register">
<fieldset>
<input type="text" id="first_name" name="first_name" />
<input type="text" id="last_name" name="last_name" />
<input type="text" id="email" name="email" />
<input type="text" id="address" name="address" />
<input id="submit" type="submit" value=">>" />
</fieldset>
</form>
when a user a user click the submit button is lead to a page with the full registering form, where i need to have few fields populated with the data sent from previous page form. this is a preview of few fields from the form of the second page:
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>*First Name</label>
<input type="text" id="first_name" name="first_name" />
</li>
<li>
<label>*Last Name</label>
<input type="text" id="last_name" name="last_name" />
</li>
<li>
<label>*Email</label>
<input type="text" id="email" name="email" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" id="address" name="address" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
the php is not my strong point, so if you can be more detailed in answer is great for me.
thanks!
I would say for security reasons, do not use Get method "$_GET[]" as people described, keep POST as you have it.
All you need to do on register/ page is get all the values passed on using the POST method and populate them into your HTML. So the second form should look like:
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>First Name</label>
<input type="text" id="first_name" name="first_name" value="<?=$_POST[first_name]?>" />
</li>
<li>
<label>*Last Name</label>
<input type="text" id="last_name" name="last_name" value="<?=$_POST[last_name]?>" />
</li>
<li>
<label>*Email</label>
<input type="text" id="email" name="email" value="<?=$_POST[email]?>" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" id="address" name="address" value="<?=$_POST[address]?>" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
Above, I am using shorthand version of "echo" and php tags, if you do not have that enabled under php.ini, please change "" to "; ?>. Also, script will not populate "confirm" email as I assume you would like the user to retype that.
That should do it.
There are basically two methods
Store the values of the first form in a cookie, and the process code can retrieve the values from the cookie
make the form action 'Get' so that the data is passed on to the next page.
You can use the $_POST values from the first form in the page handling the submit of the first form and print them in the new form as:
<?php
echo '<input type="text" id="email" name="email" value="' . htmlentities($_POST['email']) . '"/>
?>
<form method="post" action="register.php">
<fieldset>
<input type="text" id="first_name" name="first_name" />
<input type="text" id="last_name" name="last_name" />
<input type="text" id="email" name="email" />
<input type="text" id="address" name="address" />
<input id="submit" type="submit" value=">>" />
</fieldset>
</form>
register.php
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>*First Name</label>
<input type="text" value="<?php echo $_POST['first_name'];?>" id="first_name" name="first_name" />
</li>
<li>
<label>*Last Name</label>
<input type="text" value="<?php echo $_POST['last_name'];?>" id="last_name" name="last_name" />
</li>
<li>
<label>*Email</label>
<input type="text" value="<?php echo $_POST['email'];?>" id="email" name="email" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" value="<?php echo $_POST['address'];?>" id="address" name="address" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
Finally service the post in send_contact.php as you wish