Application form with phpMyAdmin database - php

So now I'm trying to make a application form for a trial drive lesson. I'm new at PHP, so I tried to take some code from my registration form that is working fully.
But nothing happens when i click submit(aanvraag_btn)
Here is the code:
<form class ="myform" action="index.php" method="post" >
<h3 class="center"> Vraag een proefrit aan! </h3>
<br></br>
<input name="naam" type="text" class="inputvalues" placeholder="Naam" required />
<br></br>
<input name="email" type="text" class="inputvalues" placeholder="Email"/>
<br></br>
<input name="Telefoonnummer" type="text" class="inputvalues" placeholder="Telefoonnummer" required />
<br></br>
<input name="aanvraag" type="button" id="aanvraag_btn" value="Aanvragen" required/> <br>
This is the PHP:
<?php
if(isset($_POST['aanvraag']))
{
$naam = $_POST['naam'];
$email = $_POST['email'];
$telefoonnummer = $_POST['telefoonnummer'];
$query= "insert into user values('$naam','$email','telefoonnummer')";
$query_run = mysqli_query($con,$query);
if($query_run)
{
echo '<script type="text/javascript"> alert ("Bedankt voor de aanvraag, we nemen zo snel mogelijk contact op.") </script>';
}
else {
echo '<script type="text/javascript"> alert ("Error>';
}
}
?>

Use type="submit"
<input name="aanvraag" type="submit" id="aanvraag_btn" value="Aanvragen" required/>

Try with this:
<form class ="myform" action="index.php" method="post" >
<h3 class="center"> Vraag een proefrit aan! </h3>
<br></br>
<input name="naam" type="text" class="inputvalues" placeholder="Naam" required />
<br></br>
<input name="email" type="text" class="inputvalues" placeholder="Email"/>
<br></br>
<input name="Telefoonnummer" type="text" class="inputvalues" placeholder="Telefoonnummer" required />
<br></br>
<input name="aanvraag" type="submit" id="aanvraag_btn" value="Aanvragen"/> <br>
</form>

1)Missing form close
2)missing type ="submit"
3)typo in element attribute near name="telefoonnummer"
<?php
if(isset($_POST['aanvraag']))
{
$naam = $_POST['naam'];
$email = $_POST['email'];
$telefoonnummer = $_POST['telefoonnummer'];
$query= "insert into user values('$naam','$email','telefoonnummer')";
$query_run = mysqli_query($con,$query);
if($query_run)
{
echo '<script type="text/javascript"> alert ("Bedankt voor de aanvraag, we nemen zo snel mogelijk contact op.") </script>';
}
else {
echo '<script type="text/javascript"> alert ("Error");</script>';
}
}
?>
<form class ="myform" action="index.php" method="post" >
<h3 class="center"> Vraag een proefrit aan! </h3>
<br></br>
<input name="naam" type="text" class="inputvalues" placeholder="Naam" required />
<br></br>
<input name="email" type="text" class="inputvalues" placeholder="Email"/>
<br></br>
<input name="Telefoonnummer" type="text" class="inputvalues" placeholder="Telefoonnummer" required />
<br></br>
<input name="aanvraag" type="submit" id="aanvraag_btn" value="Aanvragen"/> <br>
</form>

Related

Saving contact form data in a file by pressing a submit button doesn't seem to work

I made a contact form with a submit button. I want all the information saved which got typed into the contact form. Somehow the submit button does nothing.
In the past it seemed to work but as a php/html newbie I just cant seem to find the problem
HTML
<form method="post">
<div class="contact-form" action="contact-form.php" method="post">
<div class="contentLeft">
<h4>Ihre Daten</h4>
<br>
<h3>Vorname</h3>
<input class="inputText" type="text" name="firstName" required="required">
<br>
<h3>Nachname</h3>
<input class="inputText" type="text" name="lastName" required="required">
<br>
<h3>E-Mail</h3>
<input class="inputText" type="text" name="mail" required="required">
<br>
<h3>Straße</h3>
<input class="inputText" type="text" name="street" required="required">
<br>
<h3>Postleitzahl</h3>
<input class="inputText" type="text" name="postal" required="required">
<br>
<h3>Stadt</h3>
<input class="inputText" type="text" name="city" required="required">
<br>
<h3>Telefonnummer</h3>
<input class="inputText" type="number" name="phone" required="required">
<br>
</div>
<div class="contentRight">
<h4>Ihre Nachricht</h4>
<br>
<h3>Betreff</h3>
<input class="inputTextRight" type="text" name="subject" required="required">
<br>
<h3>Buchungscode</h3>
<input class="inputTextRight" type="text" name="bookingCode" required="required">
<br>
<br><
<textarea></textarea>
</div>
<br>
<button class="button" type="submit" name="submit">Absenden</button>
</div>
</form>
PHP
if (isset($_POST['submit'])) {
$firstName = $_POST['firstname'];
$lastName = $_POST['lastname'];
$mail = $_POST['mail'];
$street = $_POST['street'];
$postal = $_POST['postal'];
$city = $_POST['city'];
$phone = $_POST['phone'];
$subject = $_POST["subject"];
$bookingCode = $_POST['bookingCode'];
$message = $_POST['message'];
$data=$_POST["firstName"] ."\n".$_POST["firstName"] ."\n".$_POST["lastName"] ."\n".$_POST["mail"] ."\n".$_POST["street"] ."\n". $_POST["postal"] ."\n".$_POST["city"] ."\n".$_POST["phone"] ."\n". $_POST["subject"] ."\n".$_POST["bookingCode"] ."\n". $_POST["message"];
$fp = fopen("data.txt", "a");
fwrite($fp, $data);
fclose($fp);
header ("Location: NewTest.html?mailsent");
}
?>
You added action of form in div, move that from div to form.
<form action="contact-form.php" method="post">
<div class="contact-form">
<div class="contentLeft">
<h4>Ihre Daten</h4>
<br>
<h3>Vorname</h3>
<input class="inputText" type="text" name="firstName" required="required">
<br>
<h3>Nachname</h3>
<input class="inputText" type="text" name="lastName" required="required">
<br>
<h3>E-Mail</h3>
<input class="inputText" type="text" name="mail" required="required">
<br>
<h3>Straße</h3>
<input class="inputText" type="text" name="street" required="required">
<br>
<h3>Postleitzahl</h3>
<input class="inputText" type="text" name="postal" required="required">
<br>
<h3>Stadt</h3>
<input class="inputText" type="text" name="city" required="required">
<br>
<h3>Telefonnummer</h3>
<input class="inputText" type="number" name="phone" required="required">
<br>
</div>
<div class="contentRight">
<h4>Ihre Nachricht</h4>
<br>
<h3>Betreff</h3>
<input class="inputTextRight" type="text" name="subject" required="required">
<br>
<h3>Buchungscode</h3>
<input class="inputTextRight" type="text" name="bookingCode" required="required">
<br>
<br><
<textarea></textarea>
</div>
<br>
<button class="button" type="submit" name="submit">Absenden</button>
</div>
</form>

Multi-fields form with image input

I have a form like this and I would like to know if there is a way to add an image input and upload it to the server.
I would like to be able to upload images to [ROOT]/upload_img/ but, to be honest I don't know how to do it and most of the code parts I found don't work with mine...
Se here I am.
Here's my code :
<html>
<head></head>
<body>
<div id="main">
<div id="login">
<form action="" method="post">
<label>Titre de l'annonce :</label>
<input type="text" name="i_title" id="name" required="required" placeholder=""/>
<br />
<br />
<label>Adresse : </label>
<input type="text" name="i_adress" id="email" required="required" placeholder=""/>
<br/>
<br />
<label>Ville :</label>
<input type="text" name="i_city" id="city" required="required" placeholder="Please Enter Your City"/>
<br/>
<br />
<label>Surface du logement entier :</label>
<input type="text" name="i_surf_room" id="surf_room" required="required" placeholder=""/> En m2
<br/>
<br />
<label>Surface de la chambre :</label>
<input type="text" name="i_surf_home" id="surf_home" required="required" placeholder=""/>
<br/>
<br />
<label>Description :</label>
<input type="text" name="i_description" id="description" required="required" placeholder=""/>
<br/>
<br />
<label>Date de début de disponibilité :</label>
<input type="month" name="i_start_date" id="start_date" required="required" placeholder=""/>
<br/>
<br />
<label>Date de fin de disponibilité :</label>
<input type="month" name="i_end_date" id="end_date" required="required" placeholder=""/>
<br/>
<br />
<label>Photographies du logement</label>
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="reset"> -
<input type="submit" name="submit"/>
<br />
</form>
</div>
</div>
<?php
if(isset($_POST["submit"])) {
$hostname='xxxx';
$username='xxxx';
$password='xxx';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=xxxx",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql = "INSERT INTO students (title, adress, city, surf_home, surf_room, description, start_date, end_date)
VALUES ('".$_POST["i_title"]."','".$_POST["i_adress"]."','".$_POST["i_city"]."','".$_POST["i_surf_home"]."','".$_POST["i_surf_room"]."','".$_POST["i_description"]."','".$_POST["i_start_date"]."','".$_POST["i_end_date"]."')";
if ($dbh->query($sql)) {
echo "
<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>";
} else {
echo "
<script type= 'text/javascript'>alert('Data not successfully Inserted.');</script>";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
</body>
</html>

Jquery error slow down

I'm having a problem with my Jquery register validation.
I've a problem getting the error message back if you don't fill in a name.
jQuery(document).ready(function () {
$('#register').submit(function () {
var action = $(this).attr('action');
var error = '<div class=\"states\"><li class=\"warning\"><strong>Fout!</strong><br /> U hebt geen naam opgegeven.</li> <br /></ul>';
$(".states li").slideUp(750, function () {
$('.states li').hide();
$('#submit')
.after('<img src="images/ajax-loader.gif" class="loader" />')
.attr('disabled', 'disabled');
$.post(action, {
name: $('#name').val(),
realname: $('#realnam').val(),
pass: $('#pass').val(),
repeatpass: $('#repeatpass').val(),
mail: $('#mail').val(),
mailadres: $('#mailadres').val(),
});
if (name == "") {
$(error).slideDown('slow');
}
});
return false;
});
});
And my HTML code:
<script src="js/aanmelden.js"></script>
<?php
include_once 'include/config.php';
?>
<div class="text-section">
<h1>Aanmelden</h1>
<p>Hier kunt u zich <strong>gratis</strong> aanmelden op <?php echo $sNaam; ?></p>
</div>
<div class="states">
<li class="warning"><strong>Waarschuwing</strong> Deze pagina is (nog) niet af, hier wordt aangewerkt.</li> <br />
</ul>
<form method="POST" action="bin/register.php" id="register">
<fieldset>
<legend>Naam</legend>
<label id="username">Gebruikersnaam:</label>
<input type="text" class="text" name="gebruikersnaam" id="name" placeholder="Uw gebruikersnaam" /> <br />
<label id="realname">Uw echte naam:</label>
<input type="text" class="text" name="echtenaam" id="realnam" placeholder="Uw echte naam" /> <br />
</fieldset>
<fieldset>
<legend>Wachtwoord</legend>
<label id="password">Uw wachtwoord:</label>
<input type="password" class="text" id="pass" name="wachtwoord" placeholder="Uw wachtwoord" /> <br />
<label id="repeatpassword">Uw wachtwoord nogmaals:</label>
<input type="password" class="text" id="repeatpass" name="hwachtwoord" placeholder="Uw wachtwoord nogmaals" /> <br />
</fieldset>
<fieldset>
<legend>Mail</legend>
<label id="mailadres">Uw mail adres:</label>
<input type="text" class="text" name="mail" id="mail" placeholder="Uw mail adres" /> <br />
<label id="repeatmail">Uw mail adres nogmaals:</label>
<input type="text" class="text" name="hmail" id="mailadres" placeholder="Uw mail adres nogmaals" /> <br />``
</fieldset>
<input type="submit" name="submit" value="Registreren" class="orange" id="submit" />
<br />
</form>
My problem(demo at http://mijnrpg.eu and then the second tab). If you click on the button where it says "Registreren", you will see what I mean. It isn't giving an error.
$.post(action, {
name: $('#name').val(),
realname: $('#realnam').val(),
pass: $('#pass').val(),
repeatpass: $('#repeatpass').val(),
mail: $('#mail').val(),
mailadres: $('#mailadres').val(),
});
use serialize
$('#register').serialize();
your post function would be
$.post(action,
$('#register').serialize(),
function(resp)
{
///
}
);
And to answer your question try
$('#name').val()==''
Here i slightly modified your code http://jsfiddle.net/eVA8s/10/
So basically what you want to do is create div tag with id error-message and set it style to hidden,
second watch at your tags you have too many useless tags,
third always use firebug in firefox, or press f12 in chrome.
you need to validate first not last. updated
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
$('.error').hide('fast');
$('.warning').hide('fast');
$('.succes').hide('fast');
$('#register').submit(function () {
if ($('#name').val() == "")
{
$('.error').slideDown('slow'); return false;
}
else
{
var action = $(this).attr('action');
$(".states li").slideUp(750, function () {
$('.states li').hide();
$('#submit')
.after('<img src="images/ajax-loader.gif" class="loader" />')
.attr('disabled', 'disabled');
$.post(action, {
name: $('#name').val(),
realname: $('#realnam').val(),
pass: $('#pass').val(),
repeatpass: $('#repeatpass').val(),
mail: $('#mail').val(),
mailadres: $('#mailadres').val(),
});
});
return false;
}
});
});
</script>
<div class="text-section">
<h1>Aanmelden</h1>
<p>Hier kunt u zich <strong>gratis</strong> aanmelden op <?php echo $sNaam; ?></p>
</div>
<div class="states">
<ul class="states">
<li class="error"><strong>Fout</strong> Dit zullen ze zien wanneer ze iets fout hebben gedaan.</li>
<br />
<li class="warning"><strong>Waarschuwing</strong> Dit zullen ze zien wanneer er een onbekende fout is opgetreden.</li>
<br />
<li class="succes"><strong>Goed</strong> Dit zullen ze zien wanneer iets succesvol gegaan is.</li>
</ul>
</div>
<form method="POST" action="bin/register.php" id="register">
<fieldset>
<legend>Naam</legend>
<label id="username">Gebruikersnaam:</label>
<input type="text" class="text" name="gebruikersnaam" id="name" placeholder="Uw gebruikersnaam" /> <br />
<label id="realname">Uw echte naam:</label>
<input type="text" class="text" name="echtenaam" id="realnam" placeholder="Uw echte naam" /> <br />
</fieldset>
<fieldset>
<legend>Wachtwoord</legend>
<label id="password">Uw wachtwoord:</label>
<input type="password" class="text" id="pass" name="wachtwoord" placeholder="Uw wachtwoord" /> <br />
<label id="repeatpassword">Uw wachtwoord nogmaals:</label>
<input type="password" class="text" id="repeatpass" name="hwachtwoord" placeholder="Uw wachtwoord nogmaals" /> <br />
</fieldset>
<fieldset>
<legend>Mail</legend>
<label id="mailadres">Uw mail adres:</label>
<input type="text" class="text" name="mail" id="mail" placeholder="Uw mail adres" /> <br />
<label id="repeatmail">Uw mail adres nogmaals:</label>
<input type="text" class="text" name="hmail" id="mailadres" placeholder="Uw mail adres nogmaals" /> <br />``
</fieldset>
<input type="submit" name="submit" value="Registreren" class="orange" id="submit" />
<br />
</form>
demo link

Form submit not posting Safari

I've got a registration form setup which works fine on all browsers...except Safari.
I thought it should be a problem that deals with Javascript, as it mostly is. But after I turned Javascript off in Safari, there's still no data being posted.
The form is live on:
http://tpgrf.nl/testserver/alpha/account/registreer/
I've added this text on top of the page, for testing, to make sure if data has been posted or not.
if($_SERVER['REQUEST_METHOD'] == 'POST'){
echo 'post';
}else{
echo 'niets gepost';
}
Any thoughts where to look for the answer?
EDIT: Here's the form (output HTML)
<form name="registerform" id="registerform" action="http://tpgrf.nl/testserver/alpha/account/registreer/" method="post">
<script type="text/javascript">
jQuery(document).ready(function($) {
//Since we want users to login with there email; there's no need to also register a username. Therefore the username field = email field
$("#user_login").live('change', function(){
$('#user_email').val($("#user_login").val());
});
//Display fields, depending on the selected role
$('#role').live('change', function(){
if($('#role').val() === 'docent'){
$('#messageRegisterDocent').show();
$('#pKlas').hide();
}else{
$('#messageRegisterDocent').hide();
$('#pKlas').show();
}
});
//The json call to automcplete School
var ajaxurl = 'http://tpgrf.nl/testserver/alpha/wp-admin/admin-ajax.php';
$("#school").autocomplete({
delay: 0,
minLength: 1,
source: function(req, response){
$.getJSON('http://tpgrf.nl/testserver/alpha/wp-admin/admin-ajax.php?callback=?&action=school_autocomplete', req, response);
},
select: function(event, ui){
$('#school').val(ui.item.label);
$('#school_id').val(ui.item.school_id);
}
});
});
</script>
<p>
<input type="hidden" name="user_email" id="user_email" class="input" value="" size="20" />
<p>
<label for="user_login">E-mail</label>
<input type="email" name="user_login" id="user_login" class="input" value="" size="20" />
</p>
<p>
<label>Voornaam</label>
<input id="first_name" type="text" size="25" value="" name="first_name" />
</p>
<p>
<label>Achternaam</label>
<input id="last_name" type="text" size="25" value="" name="last_name" />
</p>
<p>
<label>Ik ben...</label>
<select name="role" id="role">
<option value="">...selecteer</option>
<option value="leerling" >Leerling</option>
<option value="docent" >Docent</option>
</select>
<p class="message" id="messageRegisterDocent" style="display:none;"><strong>Let op:</strong> registreer met uw e-mailadres van de school waar u werkzaam bent. <br />Voor een aantal functies vindt namelijk handmatige autorisatie plaats; dit is niet mogelijk met een privé e-mailadres.</p>
</p>
<p>
<label>Mijn school</label>
<input type="text" id="school" class="autoComplete" size="25" value="" name="school" />
<input type="hidden" id="school_id" name="school_id" value="">
</p>
<p id="pKlas"style="display:none;">
<label>Mijn klas</label>
<input type="text" id="klas" size="25" value="" name="klas" />
</p>
<p id="reg_passmail">U zult een wachtwoord per e-mail ontvangen.</p>
<p class="submit">
<input type="submit" name="wp-submit" id="wp-submit" value="Registratie" />
of Ik heb al een account...
<input type="hidden" name="redirect_to" value="/testserver/alpha/account/login/?checkemail=registered" />
<input type="hidden" name="instance" value="" />
</p>
</form>
Your problem might be caused by the following line of code:
<input type="submit" name="wp-submit" id="wp-submit" value="Registratie" />
You wrap the submit button tag inside an 'a' tag which is pointing to an empty URL and causes a link to the current page only. It might be that Safari does not parse this wrapped button well, and instead prefers the A link over the submit button.
Unwrapping the 'input' tag and changing the code to:
<input type="submit" name="wp-submit" id="wp-submit" value="Registratie" />
might work.

All is working except if($_POST['submit']=='Update')

I have a working registration and login system. I am trying to create a form where a user can add product registration info (via mysql update). I can't seem to get the db to actually update the fields. What am I missing here?!?
<?php
define('INCLUDE_CHECK',true);
require 'connect.php';
require 'functions.php';
// Those two files can be included only if INCLUDE_CHECK is defined
session_name('tzLogin');
// Starting the session
session_set_cookie_params(2*7*24*60*60);
// Making the cookie live for 2 weeks
session_start();
if($_SESSION['id'] && !isset($_COOKIE['tzRemember']) && !$_SESSION['rememberMe'])
{
// If you are logged in, but you don't have the tzRemember cookie (browser restart)
// and you have not checked the rememberMe checkbox:
$_SESSION = array();
session_destroy();
// Destroy the session
}
if(isset($_GET['logoff']))
{
$_SESSION = array();
session_destroy();
header("Location: index_login3.php");
exit;
}
if($_POST['submit']=='Login')
{
// Checking whether the Login form has been submitted
$err = array();
// Will hold our errors
if(!$_POST['username'] || !$_POST['password'])
$err[] = 'All the fields must be filled in!';
if(!count($err))
{
$_POST['username'] = mysql_real_escape_string($_POST['username']);
$_POST['password'] = mysql_real_escape_string($_POST['password']);
$_POST['rememberMe'] = (int)$_POST['rememberMe'];
// Escaping all input data
$row = mysql_fetch_assoc(mysql_query("SELECT * FROM electrix_users WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));
if($row['usr'])
{
// If everything is OK login
$_SESSION['usr']=$row['usr'];
$_SESSION['id'] = $row['id'];
$_SESSION['email'] = $row['email'];
$_SESSION['first'] = $row['first'];
$_SESSION['last'] = $row['last'];
$_SESSION['address1'] = $row['address1'];
$_SESSION['address2'] = $row['address2'];
$_SESSION['city'] = $row['city'];
$_SESSION['state'] = $row['state'];
$_SESSION['zip'] = $row['zip'];
$_SESSION['country'] = $row['country'];
$_SESSION['product1'] = $row['product1'];
$_SESSION['serial1'] = $row['serial1'];
$_SESSION['product2'] = $row['product2'];
$_SESSION['serial2'] = $row['serial2'];
$_SESSION['product3'] = $row['product3'];
$_SESSION['serial3'] = $row['serial3'];
$_SESSION['rememberMe'] = $_POST['rememberMe'];
// Store some data in the session
setcookie('tzRemember',$_POST['rememberMe']);
}
else $err[]='Wrong username and/or password!';
}
if($err)
$_SESSION['msg']['login-err'] = implode('<br />',$err);
// Save the error messages in the session
header("Location: index_login3.php");
exit;
}
else if($_POST['submit']=='Register')
{
// If the Register form has been submitted
$err = array();
if(strlen($_POST['username'])<4 || strlen($_POST['username'])>32)
{
$err[]='Your username must be between 3 and 32 characters!';
}
if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['username']))
{
$err[]='Your username contains invalid characters!';
}
if(!checkEmail($_POST['email']))
{
$err[]='Your email is not valid!';
}
if(!count($err))
{
// If there are no errors
$pass = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
// Generate a random password
$_POST['email'] = mysql_real_escape_string($_POST['email']);
$_POST['username'] = mysql_real_escape_string($_POST['username']);
$_POST['first'] = mysql_real_escape_string($_POST['first']);
$_POST['last'] = mysql_real_escape_string($_POST['last']);
$_POST['address1'] = mysql_real_escape_string($_POST['address1']);
$_POST['address2'] = mysql_real_escape_string($_POST['address2']);
$_POST['city'] = mysql_real_escape_string($_POST['city']);
$_POST['state'] = mysql_real_escape_string($_POST['state']);
$_POST['zip'] = mysql_real_escape_string($_POST['zip']);
$_POST['country'] = mysql_real_escape_string($_POST['country']);
// Escape the input data
mysql_query(" INSERT INTO electrix_users(usr,pass,email,first,last,address1,address2,city,state,zip,country,regIP,dt)
VALUES(
'".$_POST['username']."',
'".md5($pass)."',
'".$_POST['email']."',
'".$_POST['first']."',
'".$_POST['last']."',
'".$_POST['address1']."',
'".$_POST['address2']."',
'".$_POST['city']."',
'".$_POST['state']."',
'".$_POST['zip']."',
'".$_POST['country']."',
'".$_SERVER['REMOTE_ADDR']."',
NOW()
)");
if(mysql_affected_rows($link)==1)
{
send_mail( 'noreply#electrixpro.com',
$_POST['email'],
'Your New Electrix User Password',
'Thank you for registering at www.electrixpro.com. Your password is: '.$pass);
$_SESSION['msg']['reg-success']='We sent you an email with your new password!';
}
else $err[]='This username is already taken!';
}
if(count($err))
{
$_SESSION['msg']['reg-err'] = implode('<br />',$err);
}
header("Location: index_login3.php");
exit;
}
if($_POST['submit']=='Update')
{
{
mysql_query(" UPDATE electrix_users(product1,serial1,product2,serial2,product3,serial3) WHERE usr='{$_POST['username']}'
VALUES(
'".$_POST['product1']."',
'".$_POST['serial1']."',
'".$_POST['product2']."',
'".$_POST['serial2']."',
'".$_POST['product3']."',
'".$_POST['serial3']."',
)");
if(mysql_affected_rows($link)==1)
{
$_SESSION['msg']['upd-success']='Thank you for registering your Electrix product';
}
else $err[]='So Sad!';
}
if(count($err))
{
$_SESSION['msg']['upd-err'] = implode('<br />',$err);
}
header("Location: index_login3.php");
exit;
}
if($_SESSION['msg'])
{
// The script below shows the sliding panel on page load
$script = '
<script type="text/javascript">
$(function(){
$("div#panel").show();
$("#toggle a").toggle();
});
</script>';
}
?>
Here are the forms:
<!-- Panel -->
<div id="toppanel">
<div id="panel">
<div class="content clearfix">
<div class="left">
<h1>My Electrix Account </h1>
<p class="grey">View and edit your contact information and product registrations</p>
</div>
<?php
if(!$_SESSION['id']):
?>
<div class="left">
<!-- Login Form -->
<form class="clearfix" action="" method="post">
<h1>Member Login</h1>
<?php
if($_SESSION['msg']['login-err'])
{
echo '<div class="err">'.$_SESSION['msg']['login-err'].'</div>';
unset($_SESSION['msg']['login-err']);
}
?>
<label class="grey" for="username">Username:</label>
<input class="field" type="text" name="username" id="username" value="" size="23" />
<label class="grey" for="password">Password:</label>
<input class="field" type="password" name="password" id="password" size="23" />
<label><input name="rememberMe" id="rememberMe" type="checkbox" checked="checked" value="1" /> Remember me</label>
<div class="clear"></div>
<input type="submit" name="submit" value="Login" class="bt_login" />
</form>
</div>
<div class="left right">
<!-- Register Form -->
<form action="" method="post">
<h1>Not a member yet? Sign Up!</h1>
<?php
if($_SESSION['msg']['reg-err'])
{
echo '<div class="err">'.$_SESSION['msg']['reg-err'].'</div>';
unset($_SESSION['msg']['reg-err']);
}
if($_SESSION['msg']['reg-success'])
{
echo '<div class="success">'.$_SESSION['msg']['reg-success'].'</div>';
unset($_SESSION['msg']['reg-success']);
}
?>
<label class="grey" for="username">Username*:</label>
<input class="field" type="text" name="username" id="username" value="" size="23" />
<label class="grey" for="email">Email*:</label>
<input class="field" type="text" name="email" id="email" size="23" />
<label class="grey" for="first">First Name:</label>
<input class="field" type="text" name="first" id="first" size="23" />
<label class="grey" for="last">Last Name:</label>
<input class="field" type="text" name="last" id="last" size="23" />
<label class="grey" for="address1">Address line 1:</label>
<input class="field" type="text" name="address1" id="address1" size="23" />
<label class="grey" for="address2">Address line 2:</label>
<input class="field" type="text" name="address2" id="address2" size="23" />
<label class="grey" for="city">City:</label>
<input class="field" type="text" name="city" id="city" size="23" />
<label class="grey" for="state">State/Province:</label>
<input class="field" type="text" name="state" id="state" size="23" />
<label class="grey" for="zip">Zip/Postal Code:</label>
<input class="field" type="text" name="zip" id="zip" size="23" />
<label class="grey" for="country">Country:</label>
<input class="field" type="text" name="country" id="country" size="23" />
<p>
<label>A password will be e-mailed to you.</label>
<input type="submit" name="submit" value="Register" class="bt_register" />
</p>
</form>
</div>
<?php
else:
?>
<div class="left">
<h1>User Information</h1>
<p>
<?php echo $_SESSION['first']; ?>
<?php echo $_SESSION['last']; ?><br />
<?php echo $_SESSION['address1']; ?>
<?php echo $_SESSION['address2']; ?><br />
<?php echo $_SESSION['city']; ?>,
<?php echo $_SESSION['state']; ?>
<?php echo $_SESSION['zip']; ?><br />
<?php echo $_SESSION['country']; ?>
</p>
<p>Email: <?php echo $_SESSION['email']; ?></p>
<p>Downloads</p>
Log off
</div>
<div class="left right">
<!-- Product Registration Form -->
<form class="clearfix" action="" method="post">
<h1>Product Registration</h1>
<?php
if($_SESSION['msg']['upd-err'])
{
echo '<div class="err">'.$_SESSION['msg']['upd-err'].'</div>';
unset($_SESSION['msg']['upd-err']);
}
if($_SESSION['msg']['upd-success'])
{
echo '<div class="success">'.$_SESSION['msg']['upd-success'].'</div>';
unset($_SESSION['msg']['upd-success']);
}
?>
<label class="grey" for="product1">Product 1:</label>
<input class="field" type="text" name="product1" id="product1" value="<?php echo $_SESSION['product1']; ?>" size="23" />
<label class="grey" for="serial1">Serial 1:</label>
<input class="field" type="text" name="serial1" id="serial1" value="<?php echo $_SESSION['serial1']; ?>" size="23" />
<label class="grey" for="product2">Product 2:</label>
<input class="field" type="text" name="product2" id="product2" value="<?php echo $_SESSION['product2']; ?>" size="23" />
<label class="grey" for="serial2">Serial 2:</label>
<input class="field" type="text" name="serial2" id="serial2" value="<?php echo $_SESSION['serial2']; ?>" size="23" />
<label class="grey" for="product3">Product 3:</label>
<input class="field" type="text" name="product3" id="product3" value="<?php echo $_SESSION['product3']; ?>" size="23" />
<label class="grey" for="serial3">Serial 3:</label>
<input class="field" type="text" name="serial3" id="serial3" value="<?php echo $_SESSION['serial3']; ?>" size="23" />
<div class="clear"></div>
<input type="submit" name="submit" value="Update" class="bt_login" />
</form>
</div>
<?php
endif;
?>
</div>
</div> <!-- /login -->
<!-- The tab on top -->
<div class="tab">
<ul class="login">
<li class="left"> </li>
<li>Hello <?php echo $_SESSION['usr'] ? $_SESSION['usr'] : 'Guest';?>!</li>
<li class="sep">|</li>
<li id="toggle">
<a id="open" class="open" href="#"><?php echo $_SESSION['id']?'Open Panel':'Log In | Register';?></a>
<a id="close" style="display: none;" class="close" href="#">Close Panel</a>
</li>
<li class="right"> </li>
</ul>
</div> <!-- / top -->
</div> <!--panel -->
Your update query is way off. You need to do it in the form of
UPDATE `tablename`
SET col1=`value`,col2=`val2`
WHERE wherecol=`whereval`
change your query and see if that helps.
your query should be
UPDATE electrix_users
SET
product1= $_POST['product1'],
serial1 = $_POST['serial1'],
product2 = $_POST['product2'],
serial2 = $_POST['serial2'],
product3 = $_POST['product3'],
serial3 = $_POST['serial3']
WHERE usr=$_POST['username']
However you should always clean for sql injection on any user entered data. I did not do this in the example as this is something you should do in your own way. This example is given to you as an example and does not prevent any kind of sql injection as it stands now.
ALWAYS DO WHAT YOU CAN TO PREVENT SQL INJECTION!

Categories