I've a website since 2013. I've signed up quite 12k users. From 5 months I have noticed some blank users. They receive a user-code but "name" "surname" and "email" fields are blanks.
This event happen every 50/100 users registrations. Why? I have tried everything, but in all test I can't sign up without data. Also other people that have made tests can't sign up without insert data.
This is the form:
<form action="script/****.php" method="post" onsubmit="return validate()">
<label for="name">Name</label>
<input type="text" id="name" name="name" <?php if($_REQUEST['name'] != "") echo "value='".$_REQUEST['name']."'"; ?> />
<label for="surname">Surname</label>
<input type="text" id="surname" name="surname" <?php if($_REQUEST['surname'] != "") echo "value='".$_REQUEST['surname']."'"; ?> />
<label for="email">Email</label>
<input type="email" id="email" name="email" <?php if($_REQUEST['email'] != "") echo "value='".$_REQUEST['email']."'"; ?> />
<label for="c_email">Retype Email</label>
<input type="email" id="c_email" name="c_email" />
<label for="password">Password</label>
<input type="password" id="password" name="password" />
<label for="c_password">Retype Password</label>
<input type="password" id="c_password" name="c_password" />
<input type="submit" value="registrati" />
</form>
This is the code that stores data on db:
<?php
function mt_rand_str ($length, $available = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123456789') {
for ($string = '', $i = 0; $i < $length; ++$i) {
$string .= $available[mt_rand(0, strlen($available)-1)];
}
return $string;
}
include('connection.php');
$con = connection();
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$password = $_POST['password'];
$bonus = 10;
$today = new DateTime();
$signUpDate = $today->format('Y-m-d');
if(strpos($name,' ') !== false) {
echo "
<script>
alert('Nome non valido!');
window.location.href = '../signup.php';
</script>";
exit;
}
if(strpos($surname,' ') !== false) {
echo "
<script>
alert('Cognome non valido!');
window.location.href = '../signup.php';
</script>";
exit;
}
if(strpos($email,' ') !== false) {
echo "
<script>
alert('Email non valida!');
window.location.href = '../signup.php';
</script>";
exit;
}
if(strpos($password,' ') !== false) {
echo "
<script>
alert('Password non valida!');
window.location.href = '../signup.php';
</script>";
exit;
}
connectionCheck($con);
userDbCheck($con);
$checkEmail = mysqli_query($con,"Select * from Users_DB where email = '$email'");
if(!mysqli_fetch_assoc($checkEmail)) {
do {
$userCode = mt_rand_str(8);
}
while(mysqli_fetch_assoc(mysqli_query($con,"select * from Users_DB where binary UserCode = '$userCode'")));
$value = 20;
mysqli_query($con,"Insert into User_DB (UserCode,Name,Surname,Phone,Email,Password,SignUpDate,bonus)
values ('$userCode','$name','$surname','','$email','$password','$signUpDate','$bonus')");
}
else {
echo "
<script>
alert('Email exists already!');
window.location.href = '../signup.php';
</script>";
}
?>
I hope you can find what I have not. As you can see, I've put in php code some data check too.
So I have
1) HTML5 check: type="email". I'm thinking to put also "pattern match" in all fields
2) JavaScript check
3) PHP check
I'm so desperate...
Thank you before.
Related
I'm trying to submit form data to php script with jQuery .post() method,than to receive php script data back and display it on form page,but it doesnt work.Also I'm using jQuery validate plugin for client side validation as well.Here is my code:
Html:
<div class="contact-form">
<button class="contact-close">X</button>
<form method="post" action="formular.php" id="quote-form">
<div id="returned"></div>
<div class="houndred">
<input type="text" name="name" placeholder="Name*" class="input-half" id="name" min-width="2" autofocus required>
<input type="email" name="email" placeholder="Email*" class="input-half" id="email" required>
<input type="text" name="subject" placeholder="Subject" class="input-half" id="subject" required>
<input type="url" name="url" placeholder="Website" class="input-half" id="website">
</div>
<div class="houndred">
<textarea name="message" class="textarea" id="message" placeholder="message*" required></textarea>
<br><p></p>
</div>
<div class="eightytwo">
<button id="quote-button">Send</button>
</div>
<div id="summary"></div>
</form>
</div><!-- .padding-fix -->
<script src="js/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script src="js/validation.js"></script>
<script src="js/ajaxform.js"></script>
JS for posting:
$(document).ready(function(){
$('form').on('submit', function(event) {
event.preventDefault();
$.post('formular.php', $(this).serialize(), function(data)) {
var dataForm = data;
$("#returned").append(dataForm);
}
});
)};
and PHP:
if(!empty($_POST)) {
$errors = array();
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$url = $_POST['url'];
$message = $_POST['message'];
if(empty($name) || empty($email) || empty($subject) || empty($url) || empty($message)) {
$errors[] = 'All fields are required!';
} else {
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'Please enter a valid email address';
}
if(ctype_alpha($name === false)) {
$errors[] = 'Name can only contain letters';
}
if (ctype_alpha($subject === false)) {
$errors[] = 'Subject can only contain letters';
}
if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) === false) {
$errors[] = 'Please enter a valid url address with http in front';
}
if(empty($message)) {
$errors[] = 'Please enter a message';
}
}
if(!empty($errors)) {
echo '<ul style=\"list-style: circle; color: #f74d4e\">';
foreach($errors as $error) {
echo '<li style=\"color: #f74d4e;\"' . $error . '</li>';
}
echo '</ul>';
}
$send_message = 'From:' . $url . '<br>' . strip_tags(addslashes($message));
if(empty($errors)) {
mail('something#something.com', $subject, $send_message , $email);
echo '<h4 style=\"color: #f74d4e;\">Thank you for contacting me!</h4>';
exit();
}
}
I'm hoping that this makes sense,to me it had,but I'm strugling with it for last couple of hours,still trying to figure out what went wrong,I also tryed posting with $.ajax() and no response.One more thing,form is geting loaded using jquery .load() method to popup box,that is why it is important to me to do it with ajax
From a cursory inspection of your code, it seems that you have added an extra closing parentheses in this line, like so: function(data))
$.post('formular.php', $(this).serialize(), function(data)) {
try
$.post('formular.php', $(this).serialize(), function(data) {
instead
HTH
this form is sending data to database but i need the query should also go to the two other ids someone said use smtp but i don't know how and where to add smtp in this form. please help thanks in advance
<?php
// Attention! Please read the following.
// It is important you do not edit pieces of code that aren't tagged as a configurable options identified by the following:
// Configuration option.
// Each option that is easily editable has a modified example given.
$error = '';
$name = '';
$email = '';
$organisation = '';
$phone = '';
$subject = '';
$comments = '';
//$verify = '';
if(isset($_POST['contactus'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$organisation = $_POST['name'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
//$verify = $_POST['verify'];
$servername = "localhost";
$username = "auweb";
$password = "auw3b";
$dbname = "auweb";
$useragent=$_SERVER['HTTP_USER_AGENT'];
$ip=$_SERVER['REMOTE_ADDR'];
//echo $msg;
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
}
$sql="";
if(empty($name)||empty($phone)||empty($email)||empty($subject)||empty($comments)){
$sql = "INSERT INTO `aki_logs` (`ts`, `name`, `email`, `phone`, `state`, `course`, `useragent`, `ip`, `status`)VALUES (now(), '$name', '$email', '$phone', '$comments', '$subject', '$useragent', '$ip', 'Error');";
//echo 'Please enter all the data';
header('location:index.php');
}
else{
$sql = "INSERT INTO `aki_logs` (`ts`, `name`, `email`, `phone`, `state`, `course`, `useragent`, `ip`, `status`)VALUES (now(), '$name', '$email', '$phone', '$comments', '$subject', '$useragent', '$ip', 'Success');";
}
$conn->query($sql);
$conn->close();
//$to="admissions2#ansaluniversity.edu.in,siddhartha#digidarts.com";
//$to='admissions2#ansaluniversity.edu.in';
#date_default_timezone_set('Asia/Kolkata');
#session_start();
unset($_POST['formname']); unset($_POST['submit']);
$csv = implode('","', $_POST);
$csv = '"'.date("d-m-Y").'","'. date("H:i:s") .'","' . $csv . '"' . "\r\n";
$file = '../../data/'. basename( __DIR__ ) .'.csv';
#file_put_contents($file, $csv, FILE_APPEND);
// Configuration option.
// You may change the error messages below.
// e.g. $error = 'Attention! This is a customised error message!';
if(trim($name) == '') {
$error = '<div class="error_message">Attention! You must enter your name.</div>';
} else if(trim($email) == '') {
$error = '<div class="error_message">Attention! Please enter a valid email address.</div>';
// Configuration option.
// Remove the // tags below to active phone number.
} else if(!is_numeric($phone)) {
// $error = '<div class="error_message">Attention! Phone number can only contain digits.</div>';
} else if(!isEmail($email)) {
$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
}
if(trim($organisation) == '') {
$error = '<div class="error_message">Attention! Please enter a subject.</div>';
} else if(trim($comments) == '') {
$error = '<div class="error_message">Attention! Please enter your message.</div>';
}// else if(trim($verify) == '') {
// $error = '<div class="error_message">Attention! Please enter the verification number.</div>';
//} else if(trim($verify) != '4') {
// $error = '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
//}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "";
$address = "mk#gmail.com, mk2#gmail.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_organisation = 'You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name with regards to $organisation, their additional message is as follows.\r\n\n";
$e_content = "\"$comments\"\r\n\n";
// Configuration option.
// RIf you active phone number, swap the tags of $e-reply below to include phone number.
$e_reply = "You can contact $name via email, $email or via phone $phone";
//$e_reply = "You can contact $name via email, $email";
$msg = $e_body . $e_content . $e_reply;
if(mail($address, $e_organisation, $msg, "From: 'enquiry#gmail.com'\r\nReply-To: $email\r\nReturn-Path: $email\r\n"))
{
// Email has sent successfully, echo a success page.
echo "<div id='succsess_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
} else echo "Error. Mail not sent";
}
}
if(!isset($_POST['contactus']) || $error != '') // Do not edit.
{
?>
<?php echo $error; ?>
<fieldset>
<legend>Please fill in the following form to contact us</legend>
<form method="post" action="#succsess_page">
<div class="row">
<div class="col-md-6">
<label for=name accesskey=U><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="<?php echo $name; ?>" />
<br />
<label for=email accesskey=E><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="<?php echo $email; ?>" />
<br />
<label for=phone accesskey=P><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="<?php echo $phone; ?>" />
</div><!--COL-FORM HALF-->
<div class="col-md-6">
<label for=subject accesskey=S><span class="required">*</span> Subject</label>
<select name="subject" id="subject">
<option value="B. A. (Hons) - Liberal Arts">B. A. (Hons) - Liberal Arts</option>
</select>
<br />
<label for=comments accesskey=C><span class="required">*</span> Query</label>
<textarea name="comments" cols="30" rows="3" id="comments"><?php echo $comments; ?></textarea>
<hr />
<!--<p><span class="required">*</span> Are you human?</p>
<label for=verify accesskey=V> 3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="<?php echo $verify; ?>" /><br /><br />-->
<input name="contactus" type="submit" class="submit" id="contactus" value="Submit" />
</div>
</div>
</form>
</fieldset>
<?php }
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
?>
If you should send an email after form submitting, you can use the php "mail()" function (http://php.net/manual/en/function.mail.php).
Or, if you wanna use SMTP protocol you should integrate in your project a plugins like PHPMailer. See ya!
i want to excecute php script with ajax or javascript from html form. I need receive result from php page to html page.
My changepsw.php
<?php
//Change a password for a User via command line, through the API.
//download the following file to the same directory:
//http://files.directadmin.com/services/all/httpsocket/httpsocket.php
$system = $_POST['system'];
$db = $_POST['db'];
$ftp = $_POST['ftp'];
$id = $_GET['id'];
$psw = $_POST['userpw'];
$queryda = "SELECT * FROM paugos where id = '$id'"; //You don't need a ; like you do in SQL
$resultda = mysql_query($queryda);
$rowda = mysql_fetch_array($resultda);
if($system == "" or $system == "no" or $system !== "yes"){
$system = "no";
}
if($db == "" or $db == "no" or $db !== "yes"){
$db = "no";
}
if($ftp == "" or $ftp == "no" or $ftp !== "yes"){
$ftp = "no";
}
$server_ip="127.0.0.1";
$server_login="admin";
$server_pass="kandon";
$server_ssl="N";
$username = $rowda['luser'];
$pass= $psw;
echo "changing password for user $username\n";
include 'httpsocket.php';
$sock = new HTTPSocket;
if ($server_ssl == 'Y')
{
$sock->connect("ssl://".$server_ip, 2222);
}
else
{
$sock->connect($server_ip, 2222);
}
$sock->set_login($server_login,$server_pass);
$sock->set_method('POST');
$sock->query('/CMD_API_USER_PASSWD',
array(
'username' => $username,
'passwd' => $pass,
'passwd2' => $pass,
'options' => 'yes',
'system' => $system,
'ftp' => $ftp,
'database' => $db,
));
$result = $sock->fetch_parsed_body();
if ($result['error'] != "0")
{
echo "\n*****\n";
echo "Error setting password for $username:\n";
echo " ".$result['text']."\n";
echo " ".$result['details']."\n";
}
else
{
mysql_query("UPDATE paugos SET lpass='$pass' WHERE id='$id'");
//echo "<script type='text/javascript'> document.location = 'control?id=$id&successpw=1'; </script>";
//header("Location: control?id=1&successpw=1");
echo "$user password set to $pass\n";
}
exit(0);
?>
if script fails, it returns
Error setting password for $username. If success then php script return $user password set to $pass.
So i want to return answer from php page to html page with jquery/ajax.
My html form, from where I post data to my php script
<form action="changepsw.php?id=<?=$id;?>" method="post" role="form">
<label for="disabledSelect">Directadmin account</label>
<input name="usern" class="form-control" style="width:220px;" type="text" placeholder="<?=$luser;?>" disabled>
<div class="form-group">
<label>New password</label>
<input name="userpw" class="form-control" style="width:220px;" placeholder="Enter new password">
</div>
<div class="form-group">
<label>Change password for:</label>
<div class="checkbox">
<label>
<input type="checkbox" name="system" value="yes">Directadmin
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="ftp" value="yes">FTP
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="dabatase" value="yes">MySQL
</label>
</div>
</div>
<button type="submit" id="col" class="btn btn-default">Submit Button</button>
<button type="reset" class="btn btn-default">Reset Button</button>
</form>
In your HTML page you can user AJAX post request and in php you must use the die method as follows:
$.post('url',{parameters},function(data){
if(data==='1'){
alert('Done');
}else if(data==='0'){
alert('Error');
}else{
alert(data);
}
});
In PHP code use as follows:
die('1'); or die('0'); or
echo 'error occurs';
die;
I have a contact form on my website that with the current code sends an email to the sender and the receiver, and all works fine. However, once completing the form, the page opens email.php instead of showing a popup that I hoped it would. I have no idea how to fix as I'm not used to writing for php and JS. Below is my code.
<form method="post" action="email.php" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_self" novalidate>
<input type="text" value="" name="full_name" class="fullname" id="mce-name" placeholder="full name" required>
<input type="text" value="" name="phone_num" class="phonenum" id="mce-phone" placeholder="phone number" required>
<br>
<input type="email" value="" name="email" class="email" id="mce-EMAIL" placeholder="email address" required>
<div style="position: absolute; left: -5000px;"><input type="text" name="b_cdb7b577e41181934ed6a6a44_e65110b38d" value=""></div>
<div class="clear"><input type="submit" value="Submit" name="submit" id="mc-embedded-subscribe" class="button"></div>
</form>
<?php
if(isset($_POST['submit'])){
$to = "email#help.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$full_name = $_POST['full_name'];
$phone_num = $_POST['phone_num'];
$subject = "Title";
$subject2 = "Copy of your form submission";
$message = "Message";
$message2 = "Message2";
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
if ($_POST['submit']) {
if ($name != '' && $email != '' && $subject != '' && $message != '') {
}
} else {
echo '<script>function displayPopup()
{
alert("Form submitted!");
}<script>';
}
}
?>
because you only declare the popup function, you did not run displayPopup()
try to change to
if ($_POST['submit']) {
if ($name != '' && $email != '' && $subject != '' && $message != '') {
} else {
echo '<script>function displayPopup(){alert("Form submitted!");}';
echo 'displayPopup();</script>
';
}
}
i want to display alert box when value inserted by user is less than specified value.and this specified value is taken from database. I am new in php so that i m not getting whats wrong with this code.
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("gunjanbid", $con);
$username=$_SESSION['userName'];
$id=$_SESSION['id'];
$result = mysql_query("SELECT * FROM bids WHERE id =$id");
//$query=mysql_query("SELECT * FROM bid
$numrow = mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
]
$bidfee=$row[5];
}
?>
<?php
echo '<script type="text/javascript">';
echo "function validateForm1()";
{
echo "var c=document.forms['auction1']['fir'].value";
echo "var d=document.forms['auction1']['bidamount'].value";
if echo "( c==null || c=="" )";
{
echo "alert('UserName must be filled out')";
echo "return false";
}
echo "else";
{
echo "if(c<$bidfee)"
{
echo "alert('Bid can not be less than Bid fee')";
echo "return false";
}
}
echo "if (d==null || d=="")";
{
echo "alert('UserName must be filled out')";
echo "return false";
}
echo "else";
{
echo "if(d<$bidfee)";
{
echo "alert('Bid can not be less than Bid fee')";
echo "return false";
}
}
}
echo "</script>";
?>
<form action="multiplebid.php" name="auction1" onsubmit="return validateForm1()" method="post" >
<input type="hidden" name="description" value="" >
<input type="hidden" name="closing_date" value="" >
<input type="text" name="fir" value="" size="5" >
<input type="text" name="sec" value="" size="5" ></td><td> </td><td><input type="submit" name="submit" class="button" value="Bid Now" ></form>
The above code is not displaying alert box and showing error that syntax error, unexpected T_ECHO, expecting '(' in C:\wamp\www\old\detailproduct.php on line 426
or if there be any another way to display alert box then plz help me.
Try below code:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("gunjanbid", $con);
$username=$_SESSION['userName'];
$id=$_SESSION['id'];
$result = mysql_query("SELECT * FROM bids WHERE id =$id");
$numrow = mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
$bidfee=$row[5];
}
?>
<script type="text/javascript">
var bidfee = '<?php echo $bidfee;?>';
function validateForm1(){
var c=document.forms['auction1']['fir'].value;
var d=document.forms['auction1']['bidamount'].value;
if ( c==null || c=="" ){
alert('UserName must be filled out');
return false;
}else{
if(c<bidfee){
alert('Bid can not be less than Bid fee');
return false;
}
}
if (d==null || d==""){
alert('UserName must be filled out');
return false;
}else{
if(d<bidfee){
alert('Bid can not be less than Bid fee');
return false;
}
}
}
</script>
<form action="multiplebid.php" name="auction1" onsubmit="return validateForm1()" method="post" >
<input type="hidden" name="description" value="" >
<input type="hidden" name="closing_date" value="" >
<input type="text" name="fir" value="" size="5" >
<input type="text" name="bidamount" value="" size="5" ></td><td> </td><td><input type="submit" name="submit" class="button" value="Bid Now" >
</form>