I've done tests and it's definitely not a problem with the database, it connects fine and variables input if specified, (the integers work). Note that the {} brackets around the variables in the sql statement, for some reason need to be there for it to work, if someone could tell me why that'd be great.
The main problem is the POST for receiving from the form, nothing echoes, nor inputs to the database. Can anyone help? Thanks in advance.
PHP:
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$username = $_POST['username'];
$pw = $_POST['pw'];
$email = $_POST['email'];
$wins = 0;
$losses = 0;
$played = 0;
$earnings = 0;
$sql = "
INSERT INTO users (first_name, last_name, username, password, email, last_login, date_joined, wins, losses, played, earnings) VALUES
('{$firstName}','{$lastName}','{$username}','{$pw}','{$email}','1111','2222','{$wins}','{$losses}','{$played}','{$earnings}')
";
if(!mysql_query($sql, $con)){
echo 'Worked';
} else {echo 'Failed';}
HTML:
<form id="registration_form" action="http://valhq.com/register/" method="POST">
<div class="signup_form_content_names">
<div class="signup_form_input_fn">
<input type="text" class="signup_input_style_fn" id="firstName" placeholder="First Name" maxlength="20">
</div>
<div class="signup_form_input_ln">
<input type="text" class="signup_input_style_ln" id="lastName" placeholder="Last Name" maxlength="20">
</div>
</div>
<div class="signup_form_content">
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="E-Mail" id="email" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Confirm E-Mail" id="emailconf" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Desired Username" id="username" maxlength="20">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Password" id="pw" maxlength="64">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Confirm Password" id="pwconf" maxlength="64">
</div>
<div class="signup_tc">
<p>
<input type="checkbox" id="terms" value="terms_true" style="vertical-align:middle;">
I agree to the Terms and Conditions
<span class="signup_tc_required">*</span>
</p>
</div>
<input type="submit" id="submit" class="signup_submit" value="Create Account">
<div class="signup_alreadyMember">
Already a member? Login.
</div>
<div class="signup_error">
<span class="signup_error" id="fn_error_message"></span>
<span class="signup_error" id="ln_error_message"></span>
<span class="signup_error" id="email_error_message"></span>
<span class="signup_error" id="emailconf_error_message"></span>
<span class="signup_error" id="username_error_message"></span>
<span class="signup_error" id="pw_error_message"></span>
<span class="signup_error" id="pwconf_error_message"></span>
<span class="signup_error" id="tos_error_message"></span>
</div>
</div>
</form>
if you want to get your values using $_POST your inputs name attributes must be set
example add name="firstName"
<input type="text" class="signup_input_style_fn" name="firstName" id="firstName" placeholder="First Name" maxlength="20">
So now you can access it using
$firstName = $_POST['firstName'];
Change your "Id" to "name",and you will succeed.
You are missing name attribute from input , if you are not using ajax then you require name attribute
Use This
<form id="registration_form" action="http://valhq.com/register/" method="POST">
<div class="signup_form_content_names">
<div class="signup_form_input_fn">
<input type="text" class="signup_input_style_fn" id="firstName" name="firstName" placeholder="First Name" maxlength="20">
</div>
<div class="signup_form_input_ln">
<input type="text" class="signup_input_style_ln" id="lastName" name="lastName" placeholder="Last Name" maxlength="20">
</div>
</div>
<div class="signup_form_content">
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="E-Mail" id="email" name="email" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Confirm E-Mail" id="emailconf" name="emailconf" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Desired Username" id="username" name="username" maxlength="20">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Password" id="pw" name="pw" maxlength="64">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Confirm Password" id="pwconf" name="pwconf" maxlength="64">
</div>
<div class="signup_tc">
<p>
<input type="checkbox" id="terms" name="terms" value="terms_true" style="vertical-align:middle;">
I agree to the Terms and Conditions
<span class="signup_tc_required">*</span>
</p>
</div>
<input type="submit" id="submit" name="submit" class="signup_submit" value="Create Account">
<div class="signup_alreadyMember">
Already a member? Login.
</div>
<div class="signup_error">
<span class="signup_error" id="fn_error_message"></span>
<span class="signup_error" id="ln_error_message"></span>
<span class="signup_error" id="email_error_message"></span>
<span class="signup_error" id="emailconf_error_message"></span>
<span class="signup_error" id="username_error_message"></span>
<span class="signup_error" id="pw_error_message"></span>
<span class="signup_error" id="pwconf_error_message"></span>
<span class="signup_error" id="tos_error_message"></span>
</div>
</div>
</form>
Can you try echoing the variables in your php file to check if the variables are being set to the correct values from the form.
for example
echo "first name: $firstName";
echo "email: $email";
And I would also advise if you can try directly putting the actual php file in the action of your form. Just like below:
<form id="registration_form" action="<your php file here>" method="POST">
This is the form on whic i'm working. i want it to send the data to 1.php but when i click on the create account button. please tell what is wrong with this code.
<div class="logmod__form">
<form accept-charset="utf-8" action="1.php" class="simform" method="post">
<div class="sminputs">
<div class="input full">
<label class="string optional" for="user-name">Email*</label>
<input class="string optional" maxlength="255" id="user-email" placeholder="Email" type="email" size="50" />
</div>
</div>
<div class="sminputs">
<div class="input string optional">
<label class="string optional" for="user-pw">Password *</label>
<input class="string optional" maxlength="255" id="user-pw" placeholder="Password" type="text" size="50" />
</div>
<div class="input string optional">
<label class="string optional" for="user-pw-repeat">Repeat password *</label>
<input class="string optional" maxlength="255" id="user-pw-repeat" placeholder="Repeat password" type="text" size="50" />
</div>
</div>
<div class="simform__actions">
<input class="sumbit" name="commit" type="sumbit" value="Create Account" />
<span class="simform__actions-sidetext">By creating an account you agree to our <a class="special" href="#" target="_blank" role="link">Terms & Privacy</a></span> </div>
</form>
</div>
Correct it in your button
type="submit"
You missed name Attribute in your fields without it nothing is submitted
<input class="string optional" maxlength="255" id="user-pw-repeat" placeholder="Repeat password" type="text" size="50" name="user-pw-repeat"/>
Simply I want another code to be added to the webpage when the url is
index.php?action=feed&type=member
for example the code that is on the page when the url is index.php?action=feed is
<form method="post" name="contactform" class="form" id="form1" action="l.php">
<p class="name">
<input name="first_name" type="text" placeholder="Name" id="name" />
</p>
<p class="email">
<input name="email" type="text" id="email" placeholder="Email" />
</p>
<p class="text">
<textarea name="comments" placeholder="Message"></textarea>
</p>
<div class="submit">
<input type="submit" value="SEND" id="button-blue"/>
<div class="ease"></div>
</div>
</form>
and the code I want to be added when the url is index.php?action=feed&type=member is
<form method="post" name="contactform" class="form" id="form1" action="l.php">
<p class="name">
<input name="first_name" type="text" placeholder="Name" id="name" />
</p>
<p class="email">
<input name="email" type="text" id="email" placeholder="Email" />
</p>
<p class="text">
<textarea name="comments" placeholder="Message"></textarea>
</p>
<p class="username">
<input name="user" type="text" id="user" placeholder="Username" />
</p>
<div class="submit">
<input type="submit" value="SEND" id="button-blue"/>
<div class="ease"></div>
</div>
</form>
I know that it may be easy , but I am a beginner . so how can this be done in PHP ?
Sorry for my English .
Thanks in advance
If you want such output, you could put an if statement along the html form. Consider this example:
url: index.php?action=feed&type=member
<form method="post" name="contactform" class="form" id="form1" action="l.php">
<p class="name">
<input name="first_name" type="text" placeholder="Name" id="name"/>
</p>
<p class="email">
<input name="email" type="text" id="email" placeholder="Email"/>
</p>
<p class="text">
<textarea name="comments" placeholder="Message"></textarea>
</p>
<?php if(isset($_GET['type']) && $_GET['type'] == 'member'): ?>
<p class="username">
<input name="user" type="text" id="user" placeholder="Username"/>
</p>
<?php endif; ?>
<div class="submit">
<input type="submit" value="SEND" id="button-blue"/>
<div class="ease">
</div>
</div>
</form>
That particular markup should appear is those conditions are met.
if ($_GET["type"] == 'member') {
echo '<p class="username">
<input name="user" type="text" id="user" placeholder="Username" />
</p>';
}
I am a beginner and I am trying to use this tutoriel http://untame.net/2013/05/how-to-build-a-modal-contact-form-in-twitter-bootstrap-with-php-ajax for creating my contact form. Email not sending ! Do you have an idea, why ? Thanks for your help !
After clicking on Send I have this on adresse web : http://viktorius.fr/?question=&email=&save=contact
Here the HTML code :
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_012_heart.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
</div>
<h5 id="Email" align="left" color="#000"<span style="color:black">For the answer, let us your email :</h5>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_290_skull.png"></span></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="Email">
</div>
<!-- Form itself -->
<div class="form-actions">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-primary pull-right">Send</button><br />
Here the PHP code :
<?php
ini_set(“SMTP”,”smtp.viktorius.fr”);
ini_set(“smtp_port”,”25″);
$myemail = 'postmaster#viktorius.fr';
if (isset($_POST['question'])) {
$email = strip_tags($_POST['email']);
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks! Here is what you submitted:</span><br><br>";
echo "<stong>Question:</strong> ".$question."<br>";
echo "<stong>Email:</strong> ".$email."<br>";
if (isset($_POST['name']))
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
Check the name of your inputs, php cant read your post data.
There is not a single form here...
the ajax expects to serialize
<form class="contact">...
$('form.contact').serialize(),
And you don't have a form
You should put all your inputs and button inside a form tag with class contact like this:
<form action="" class="contact">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_012_heart.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
</div>
<div style="margin-bottom: 25px;" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_290_skull.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" color="#000000"placeholder="For the answer, let us your email adress here :">
</div>
<div class="form-actions">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-primary pull-right">Send</button><br>
</div>
</form>
I'm working through some legacy code from a previous developer and I'm very new to php. Here is my challenge, the registration form works as is.
The problem is the drop down menu that allows a user to self select their usertype does not appear on the form/page. I need it to.
Currently this bit of code stores all new users in the db as user1.
How can I get the drop down to show? And alter it from auto saving as user1?
index.html.php
<body id="page-login" onload="document.registerForm.name.focus();">
'. getMsg() .'
<div class="login-container">
<div class="logo_login"><img src="'. $mainframe->cfg->site_url .'/images/logo.gif"></div>
<div class="login-box">
<form method="post" action="" name="registerForm" id="registerForm" autocomplete="off">
<div class="login-form">
<h2>'. LANG::_('register') .'</h2>
<div class="input-box input-left"><label for="name">'. LANG::_('name') .':</label><br/>
<input type="text" class="txt" id="name" name="name" value="" class="required-entry input-text" style="width:130px;"/>
</div>
<div class="input-box input-left"><label for="link">'. LANG::_('Add your profile link') .':</label><br/>
<input type="text" class="txt" id="link" name="link" value="" class="required-entry input-text" style="width:130px;"/>
</div>
<div class="input-box input-left"><label for="username">'. LANG::_('user_name') .':</label><br/>
<input type="text" class="txt" id="username" name="username" value="" class="required-entry input-text" style="width:130px;"/>
</div>
<div class="input-box input-left"><label for="email">'. LANG::_('email_address') .':</label><br/>
<input type="text" class="txt" id="email" name="email" value="" class="required-entry input-text" style="width:130px;"/>
</div>
<div class="input-box input-left"><label for="password">'. LANG::_('password') .':</label><br />
<input type="password" class="txt" id="password" name="password" class="required-entry input-text" value="" style="width:130px;"/>
</div>
'. ($mainframe->cfg->allow_only_coach_or_player ? '<div class="input-box input-left"><label for="usertype">'. LANG::_('register_me_as') .':</label><br />
<select name="usertype" class="required-entry select">
<option value="">--'. LANG::_('choose_one') .'--</option>
<option value="Coach">'. LANG::_('contest_holder') .'</option>
<option value="Player">'. LANG::_('contest_participant') .'</option>
</select>
</div>'
: '<input name="usertype" value="user1" />') .'
<div class="input-box input-left"><label for="password2">'. LANG::_('r_password') .':</label><br />
<input type="password" class="txt" id="password2" name="password2" class="required-entry input-text" value="" style="width:130px;"/>
</div>`