Jump to content

Recommended Posts

<?php

function check_fields()
{
$i = '';foreach($_POST as $value => $item){if(empty($item)){$i++;}}

return $i;
}

if(isset($_POST['submit']))
{
if(!empty(check_fields()))
{
echo 'All fields are required. Please try again.';
}
else
{
mysql_query("INSERT INTO `table` () VALUES ()");
}
}
?>

 

that might do it ;)

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460141
Share on other sites

<?php

function check_fields()
{
$i = '';foreach($_POST as $value => $item){if(empty($item)){$i++;}}

return $i;
}

if(isset($_POST['submit']))
{
if(!empty(check_fields()))
{
echo 'All fields are required. Please try again.';
}
else
{
mysql_query("INSERT INTO `table` () VALUES ()");
}
}
?>

 

that might do it ;)

 

 

i have entered that script and i get this error:

 

 

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/sites/nurevolution.co.uk/public_html/register.php on line 37

 

I might of put it in the wrong place.

 

This is part of my script:

 

 

<?PHP

 

$dbhost = "localhost";

$dbname = "**********";

$dbuser = "***********";

$dbpass = "********";

 

mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error());

mysql_select_db($dbname)or die(mysql_error());

 

 

 

$name = $_POST['name'];

$email = $_POST['email'];

$username = $_POST['username'];

$password = md5($_POST['password']);

 

 

function check_fields()

{

$i = '';foreach($_POST as $value => $item){if(empty($item)){$i++;}}

 

return $i;

}

 

if(isset($_POST['submit']))

{

if(!empty(check_fields()))

{

echo 'All fields are required. Please try again.';

}

else

{

mysql_query("INSERT INTO `table` () VALUES ()");

}

}

 

 

 

$checkuser = mysql_query("SELECT username FROM users Where username='$username'");

 

$username_exist = mysql_num_rows($checkuser);

 

if($username_exist >0){

echo "I'm sorry but the username that you specified has already been taken.  Please pick another one.";

unset($username);

include 'register.html';

exit();

}

 

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460307
Share on other sites

if your only concern is blank and domt mind what ever they enter do this..........

 

$array = array ('name','lastname','email');//the value are your fields name in your form
$empty = 0;
foreach($array as $val){
if(empty($_POST[$val])){
$empty++;//emty
}
}
if($emty == 0){
//do something
}else{
//do something
}

try

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460314
Share on other sites

I have entered that code in.

 

But it didn't seem to work.

 

This is what i had entered.

 

$name = $_POST['name'];

$email = $_POST['email'];

$username = $_POST['username'];

$password = md5($_POST['password']);

 

 

$array = array ('name','lastname','email');//the value are your fields name in your form

$empty = 0;

foreach($array as $val){

if(empty($_POST[$val])){

$empty++;//emty

}

}

if($emty == 0){

//do something

}else{

//do something

}

  Thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460322
Share on other sites

$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$array = array ('name','email','username','password');
$empty = 0;
foreach($array as $val){
   if(empty($_POST[$val]) || !isset($_POST[$val])){
   $empty++;
   }
}
if($emty == 0){
//do something here put here your insert query
}
else{
echo "wrong input";
}

try

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460327
Share on other sites

On the query part i dont know what to put.

 

Im a total newbie.

 

This is the script that im using on the register.php page:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

 

<?PHP

 

$dbhost = "localhost";

$dbname = "**********";

$dbuser = "**********r";

$dbpass = "**********";

 

mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error());

mysql_select_db($dbname)or die(mysql_error());

 

 

 

$$name = $_POST['name'];

$email = $_POST['email'];

$username = $_POST['username'];

$password = md5($_POST['password']);

$array = array ('name','email','username','password');

$empty = 0;

foreach($array as $val){

  if(empty($_POST[$val]) || !isset($_POST[$val])){

  $empty++;

  }

}

if($emty == 0){

//do something here put here your insert query

}

else{

echo "wrong input";

}

 

 

 

$checkuser = mysql_query("SELECT username FROM users Where username='$username'");

 

$username_exist = mysql_num_rows($checkuser);

 

if($username_exist >0){

echo "I'm sorry but the username that you specified has already been taken.  Please pick another one.";

unset($username);

include 'register.html';

exit();

}

 

$query = "INSERT INTO users (name,email,username,password)

VALUES('$name','$email','$username','$password')";

mysql_query($query)or die(mysql_error());

mysql_close();

 

$yoursite = 'www.nurevolution.co.uk';

$webmaster = 'Johnny McCaffery';

$youremail = 'support@nurevolution.co.uk';

 

$subject = "You have successfully registered at $yoursite...";

$message = "Dear $name, you are now registered at our web site. 

    To login, simply go to our web page and enter in the following details in the login form:

 

    Username: $username

    Password: $password

 

Now you are able to sign in to <a href='www.nurevolution.co.uk'>NuRevolution</a>

   

    Please print this information out and store it for future reference.

   

    Thanks,

    $webmaster";

   

mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

 

echo "you have successfully Registered.";

   

echo "Your information has been mailed to your email address.";

?>

 

</body>

</html>

 

Once again thanks for all of you help

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460342
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?PHP

$dbhost = "localhost";
$dbname = "**********";
$dbuser = "**********r";
$dbpass = "**********";

mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error());
mysql_select_db($dbname)or die(mysql_error());



$$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$array = array ('name','email','username','password');
$empty = 0;
foreach($array as $val){
   if(empty($_POST[$val]) || !isset($_POST[$val])){
      $empty++;
   }
}
if($emty == 0){
$checkuser = mysql_query("SELECT username FROM users Where username='$username'");
$username_exist = mysql_num_rows($checkuser);
if($username_exist >0){
	echo "I'm sorry but the username that you specified has already been taken.  Please pick another one.";
	unset($username);
	include 'register.html';
	exit();
}
else{
			$query = "INSERT INTO users (name,email,username,password)
	VALUES('$name','$email','$username','$password')";
	mysql_query($query)or die(mysql_error());
	mysql_close();

	$yoursite = 'www.nurevolution.co.uk';
	$webmaster = 'Johnny McCaffery';
	$youremail = 'support@nurevolution.co.uk';

	$subject = "You have successfully registered at $yoursite...";
	$message = "Dear $name, you are now registered at our web site. 
		To login, simply go to our web page and enter in the following details in the login form:
	   
		Username: $username
		Password: $password
	   
	   Now you are able to sign in to <a href='www.nurevolution.co.uk'>NuRevolution[/url]
	   
		Please print this information out and store it for future reference.
	   
		Thanks,
		$webmaster";
	   
	mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

	echo "you have successfully Registered.";
	   
	echo "Your information has been mailed to your email address.";
}
}
else{
   echo "missing field";
}
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460348
Share on other sites

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?PHP

$dbhost = "localhost";
$dbname = "**********";
$dbuser = "**********r";
$dbpass = "**********";
mysql_connect ($dbhost,$dbuser,$dbpass));
mysql_select_db($dbname)or die(mysql_error());
$$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$array = array ('name','email','username','password');
$empty = 0;
foreach($array as $val){
   if(empty($_POST[$val]) || !isset($_POST[$val])){
      $empty++;
   }
}
if($empty == 0){
$checkuser = mysql_query("SELECT username FROM users Where username='$username'");
$username_exist = mysql_num_rows($checkuser);
if($username_exist >0){
	echo "I'm sorry but the username that you specified has already been taken.  Please pick another one.";
	unset($username);
	include 'register.html';
	exit();
}
else{
			$query = "INSERT INTO users (name,email,username,password)
	VALUES('$name','$email','$username','$password')";
	mysql_query($query)or die(mysql_error());
	mysql_close();

	$yoursite = 'www.nurevolution.co.uk';
	$webmaster = 'Johnny McCaffery';
	$youremail = 'support@nurevolution.co.uk';

	$subject = "You have successfully registered at $yoursite...";
	$message = "Dear $name, you are now registered at our web site. 
		To login, simply go to our web page and enter in the following details in the login form:
	   
		Username: $username
		Password: $password
	   
	   Now you are able to sign in to <a href='www.nurevolution.co.uk'>NuRevolution[/url]
	   
		Please print this information out and store it for future reference.
	   
		Thanks,
		$webmaster";
	   
	mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

	echo "you have successfully Registered.";
	   
	echo "Your information has been mailed to your email address.";
}
}
else{
   echo "missing field";
}
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460380
Share on other sites

I have tried this code that i had found.

 

But i'm still getting the same error as i was with the other codes.

 

I only get the error when i try to validate the form.

 

This is the error that i'm getting:

 

Parse error: syntax error, unexpected $end in /home/sites/nurevolution.co.uk/public_html/register.php on line 77.

 

That is the end of the page.

 

This is the code that im using.

 

if($email == NULL || $username == NULL || $password == NULL || $name == NULL || $address1 == NULL || $address2 == NULL || city == NULL || $county == NULL || $postal == NULL || $country == NULL){
echo "You must complete all fields with *";

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460673
Share on other sites

NONONONONONONO.

<script type="text/javascript">

var red = 5;

var blue = 3;

var green = 3;

var match = null;

if ((red == blue) && (red == green)) {

match = 'equal';

} else {

purple = 'unequal';

}

document.write(red + ' and ' + blue + ' are ' + match);

</script>

In this example the red must equal both the value in blue and the value in green for the if statement to evaluate as true. If either comparison evaluates as false then the entire if statement evaluates as false. Had we wanted to test if the value in red matched the value in blue or the value in green then we would have used the following if statement:

 

if ((red == blue) || (red == green))

 

See what I mean? You can't use || if you want to test if all the values must be filled in. Hope this helps you!!!

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460738
Share on other sites

Try something similar to

 

<?php
function validateForm() {
  $valid = false;
  foreach($_POST as $field) {
    if(empty($field)) {
      $valid = false;
    } else {
      $valid = true;
    }
  }
  
  if($valid) {
     echo 'Form submitted successfully.';
  } else {
     echo 'Please fill in all fields.';
  }
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460798
Share on other sites

I have tried all of the codes that people have told me to put.

 

Everytime i enter their code i get this error:

 

Parse error: syntax error, unexpected $end in /home/sites/nurevolution.co.uk/public_html/register.php on line 91

 

This is the register code that i using:


<?PHP

$dbhost = "localhost";
$dbname = "**********";
$dbuser = "**********";
$dbpass = "*******";

mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error());
mysql_select_db($dbname)or die(mysql_error());



$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$companyname = $_POST['companyname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$county = $_POST['county'];
$postal = $_POST['postal'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$mobile = $_POST['mobile'];

if(($email == NULL)&&($username == NULL)&&($password == NULL)&&($name == NULL)&&($address1 == NULL)&&($address2 == NULL)&&(city == NULL)&&($county == NULL)&&($postal == NULL)&&($country == NULL));{
echo "You must complete all fields with *";
include 'register.html';
exit();

$checkuser = mysql_query("SELECT username FROM users Where username='$username'");

$username_exist = mysql_num_rows($checkuser);

if($username_exist >0){
echo "I'm sorry but the username that you specified has already been taken.  Please pick another one.";
unset($username);
include 'register.html';
exit();

$query = "INSERT INTO users (name,email,username,password,companyname,address1,address2,city,county,postal,country,phone,mobile)
VALUES('$name','$email','$username','$password','$companyname','$address1','$address2','$city','$county','$postal','$country','$phone','$mobile')";
mysql_query($query)or die(mysql_error());
mysql_close();

$yoursite = 'www.nurevolution.co.uk';
$webmaster = 'Johnny McCaffery';
$youremail = 'support@nurevolution.co.uk';

$subject = "You have successfully registered at $yoursite...";
$message = "Dear $name, you are now registered at our web site.  
    To login, simply go to our web page and enter in the following details in the login form:

    Username: $username
    Password: $password
    
    Please print this information out and store it for future reference.
    
    Thanks,
    $webmaster";
    
mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

echo "you have successfully Registered.";
    
echo "Your information has been mailed to your email address.";

?>

 

Can someone please check it and tell me what is wrong.

 

O and if i dont put the validate into the code it is working file.

 

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460861
Share on other sites

Try this, you were missing an }

 


<?PHP

$dbhost = "localhost";
$dbname = "**********";
$dbuser = "**********";
$dbpass = "*******";

mysql_connect ($dbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error());
mysql_select_db($dbname)or die(mysql_error());



$name = $_POST['name'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$companyname = $_POST['companyname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$county = $_POST['county'];
$postal = $_POST['postal'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$mobile = $_POST['mobile'];

if(($email == NULL)&&($username == NULL)&&($password == NULL)&&($name == NULL)&&($address1 == NULL)&&($address2 == NULL)&&(city == NULL)&&($county == NULL)&&($postal == NULL)&&($country == NULL));{
echo "You must complete all fields with *";
include 'register.html';
exit();
}

$checkuser = mysql_query("SELECT username FROM users Where username='$username'");

$username_exist = mysql_num_rows($checkuser);

if($username_exist >0){
echo "I'm sorry but the username that you specified has already been taken.  Please pick another one.";
unset($username);
include 'register.html';
exit();
}

$query = "INSERT INTO users (name,email,username,password,companyname,address1,address2,city,county,postal,country,phone,mobile)
VALUES('$name','$email','$username','$password','$companyname','$address1','$address2','$city','$county','$postal','$country','$phone','$mobile')";
mysql_query($query)or die(mysql_error());
mysql_close();

$yoursite = 'www.nurevolution.co.uk';
$webmaster = 'Johnny McCaffery';
$youremail = 'support@nurevolution.co.uk';

$subject = "You have successfully registered at $yoursite...";
$message = "Dear $name, you are now registered at our web site.  
    To login, simply go to our web page and enter in the following details in the login form:

    Username: $username
    Password: $password
    
    Please print this information out and store it for future reference.
    
    Thanks,
    $webmaster";
    
mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

echo "you have successfully Registered.";
    
echo "Your information has been mailed to your email address.";

?>

Link to comment
https://forums.phpfreaks.com/topic/89783-solved-form-help/#findComment-460897
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.