Jump to content

[SOLVED] !isset help


shergold

Recommended Posts

hey, i was wondering if anyone could help me with the following,

 

<?php
//connect to host and select database.
include ('dbconnect.inc');

mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db ("test") or die(mysql_error());
//get POST data from form.
$reg_username   =$_POST[username];
$reg_password   =md5($_POST[password]);
$reg_email      =$_POST[email];
$activation_code=uniqid(rand()); 

if (!isset($reg_username) || !isset($reg_password) || !isset($reg_email))
{
echo "Please enter the required fields.";
echo"</br><a href=\"javascript: history.go(-1)\">Back</a>";
}

 

everytime i send data via the forum this php file returns the echo string i have set for the !isset if statement even when i enter data for all 3 fields.

 

If anyone can point out my mistake i will be really gratefull.

 

Thanks,

Shergold.

Link to comment
Share on other sites

The form:

 

<?php
  
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
</head>
  <meta name="generator" content=
  "HTML Tidy for Windows (vers 14 February 2006), see www.w3.org">
  <title>Intranet Registration</title>
</head>

<body>
  <h3>Intranet Registration</h3>

  <form name="register" action="register.php" method="post"
  enctype="multipart/form-data" id="register">
    Username: <input type="text" name="username" id="username"
    maxlength="20"><br>
    Password: <input type="password" name="password" id="password" maxlength=
    "30"></br>
    Email:<input type="text" name"email" id="email" maxlength = "60"></br>
    <input type="submit" value="submit">
  </form>
</body>
</html>

 

ill just echo them and get back to you.

 

thanks,

shergold.

Link to comment
Share on other sites

ah thank you i echo'ed and only the email wasn't showing.

although now i have done this I'm getting another error, when i type a password im getting

"The password is to long" string that i set.

 

i used an if statement to check it.

 

if (!isset($reg_username) || !isset($reg_password) || !isset($reg_email))
{
echo "Please enter the required fields.";
echo"</br><a href=\"javascript: history.go(-1)\">Back</a>";
}
elseif( strlen($reg_username)>20 )
echo "$username is too long - <b>it must be 20 characters or under.</b>";
elseif( strlen($reg_password)>30 )
echo "your password is too long - <b>it must be 30 characters or under.</b>";
elseif( strlen($reg_email)>60 )
echo "your email address is too long - <b>it must be 60 characters or under.</b>";
else

 

thanks allot for your help,

shergold.

Link to comment
Share on other sites

doing this

$reg_username  =$_POST[username];

 

will make an isset($reg_username) return true...always

 

you need to test if it's empty() instead of isset.

 

use isset on things in which if they weren't set you wouldn't have all the other variables either.....such as the submit button

Link to comment
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.