Solved

need help tweaking insert/registration form

Posted on 2006-10-26
25
219 Views
Last Modified: 2013-12-12
Hi all,

PHP,MySQL

I have created an insert form using dreamweaver. This acts as a simple user registration form. It lacks a few features that i would like implimented.

1. If any field is left blank when the form is submitted i want to echo some text under the table saying "please fill all fields marked * "
2. The confirm password field doesnt do anything at the moment but i want to have this compared with the password field to eliminate typo's on password creation.
3. The username field is currently an editable field that the user chooses. I want this to be non editable and to be auto generated based on first name and lastname. example firstname: joe Lastname: bloggs would give username: joe bloggs

Hope this isnt asking too much?


heres my code:

<?php require_once('Connections/atrbcon.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "registerform")) {
  $insertSQL = sprintf("INSERT INTO tbl_users (username, password, firstname, lastname, usergroup, email) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($HTTP_POST_VARS['username'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['password'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['firstname'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['lastname'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['usergroup'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['email'], "text"));

  mysql_select_db($database_atrbcon, $atrbcon);
  $Result1 = mysql_query($insertSQL, $atrbcon) or die(mysql_error());

  $insertGoTo = "newpage.php";
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>

<!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>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body bgcolor="#000000">

<p align="center"><font color="#FFFFFF" size="4">Registration for site</font></p>
<form name="registerform" id="registerform" method="POST" action="<?php echo $editFormAction; ?>">
  <input name="usergroup" type="hidden" id="usergroup" value="member" />
  <table width="400" border="1" align="center">
    <tr>
      <td colspan="2"><font color="#FFFFFF">All fields marked with <font color="#FF0000">*</font>
        should be filled in</font></td>
    </tr>
    <tr>
      <td width="172"> <div align="center"><font color="#FFFFFF">First Name <font color="#FF0000">*</font></font></div></td>
      <td width="212"> <div align="center">
          <input name="firstname" type="text" id="firstname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Last Name <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="lastname" type="text" id="lastname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Username</font></div></td>
      <td> <div align="center">
          <input name="username" type="text" id="username" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="password" type="text" id="password" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Confirm Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="conpassword" type="text" id="conpassword" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Email</font></div></td>
      <td> <div align="center">
          <input name="email" type="text" id="email" />
        </div></td>
    </tr>
    <tr>
      <td colspan="2"> <div align="center">
          <input type="submit" name="Submit" value="Register" />
        </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="registerform">
</form>
<p>&nbsp; </p>
</body>
</html>
0
Comment
Question by:satmanuk
  • 12
  • 12
25 Comments
 
LVL 18

Accepted Solution

by:
ingwa earned 500 total points
Comment Utility
if(isset($_POST['submit'])){
//echo "POST DETECTED<br />";
            $isSubmitValid = true;
            //echo $isSubmitValid;
            $strMessage = "";
            $ConName = $_POST["Name"];
            $ConCompany = $_POST["Company"];
            $ConPosition = $_POST["Position"];
            $ConEmail = $_POST["Email"];
            $ConTelephone = $_POST["Telephone"];
            $ConContact = $_POST["Contact"];

            if($ConCompany == ""){
                  $strMessage .= "<li>Please enter your Company name</li>";
                  $isSubmitValid = false;
            }

            if($ConName == ""){
                  $strMessage .= "<li>Please enter your name</li>";
                  $isSubmitValid = false;
            }
            if($ConPosition == ""){
                  $strMessage .= "<li>Please enter your position</li>";
                  $isSubmitValid = false;
            }
            

            if($ConEmail == ""){
                  $strMessage .= "<li>Please enter either a valid email address</li>";
                  $isSubmitValid = false;
            }

            if($ConTelephone == ""){
            //echo "telephone is blank";
                  $strMessage .= "<li>Please enter your telephone number</li>";
                  $isSubmitValid = false;
            }
            if($ConContact == ""){
            //echo "telephone is blank";
                  $strMessage .= "<li>Please select whether you like to be contacted by us</li>";
                  $isSubmitValid = false;
            }
//echo $_POST['submit'];
            
                  
            if($isSubmitValid == true){
            //echo "Submit is valid<br />";
// Do some mail stuff here            
            if(!$mail())
            {
            $isSubmitValid = false;
               echo "<p class=\"boldgrey11pt\">Message could not be sent. </p>";
               echo "Mailer Error: " . $mail->ErrorInfo;
               exit;
            }
                              
?>
                <p class="boldgrey11pt"><?=$strEndMessage?> </p>
<?php
            //If the form was not validated correctly, lets give the user error messages so that they can debug their submission.
            
            } else{
?>
display the form here
<?php } ?>

Hope this helps.  (by the way, this is a copy of some code I have used before, so I have edited out functions that are propriatory to the system I use...use the code and fill in the gaps with your code to get it functional)
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
sorry but what questions does this dela with?
0
 
LVL 2

Expert Comment

by:davidateuropol
Comment Utility
This deals with any empty field in the form...

This also works for that and you would have to do it for every field :

$error_found=false; // to make sure that the variable is on false before you begin checking the fields in general

if(isSet($_POST['firstname'])&&(strlen($_POST['firstname']))==0){ //The field has been set but it is empty
 $error_firstname = "Your errormessage";
 $error_found = true;
}

if(isSet($_POST['lastname'])&&(strlen($_POST['lastname']))==0){ //The field has been set but it is empty
 $error_lastname = "Your errormessage";
 $error_found = true;
}

and so on for the rest of the fields.

Password comparison :
if(isSet($_POST['password'])&& isSet($_POST['conpassword'])){
 if($_POST['password'] != $_POST['conpassword']){
     $error_found = true;
     $error_message = "Passwords don't match";
}
If your script for handling the content is within another file you can jump back to it using the $error_found variable

if($error_found){
   header("Location: whateverpage"); // This can only be used when you have no other headers inside the file before.
}

For your last question :

You can create a field like this :
<input type="text" name="lastandfirstname" disabled>

Now you only have to combine the values within the 2 fields and put it in this one.
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
Thanks for the respone, i have tried what you said but the code doesnt work. Any ideas how to get what you have suggested into my exisitng page?

ie. where does your suggested code insert into my code?

I will give points to anyone who can tell me where to put the needed code in order to get the results i want.


Thanks
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
ok so dealing with an empty field....

I added your code and when i tested it the page still goes to a blank white page saying Lastname cannot be NULL

here is where i put the code: i commented a line above and below the added code from your suggestion. any ideas?

<?php require_once('Connections/atrbcon.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
// start of added code
$error_found=false; // to make sure that the variable is on false before you begin checking the fields in general

if(isSet($_POST['firstname'])&&(strlen($_POST['firstname']))==0){ //The field has been set but it is empty
 $error_firstname = "Please fill in the firstname field";
 $error_found = true;
}

if(isSet($_POST['lastname'])&&(strlen($_POST['lastname']))==0){ //The field has been set but it is empty
 $error_lastname = "Please fill in the lastname field";
 $error_found = true;
}
if(isSet($_POST['password'])&&(strlen($_POST['password']))==0){ //The field has been set but it is empty
 $error_password = "Please fill in the password field";
 $error_found = true;
}
// end of added code


if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "registerform")) {
  $insertSQL = sprintf("INSERT INTO tbl_users (username, password, firstname, lastname, usergroup, email) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($HTTP_POST_VARS['username'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['password'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['firstname'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['lastname'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['usergroup'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['email'], "text"));

  mysql_select_db($database_atrbcon, $atrbcon);
  $Result1 = mysql_query($insertSQL, $atrbcon) or die(mysql_error());

  $insertGoTo = "http://www.site.co.uk";
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

?>

<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>

<!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>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body bgcolor="#000000">



<p align="center"><font color="#FFFFFF" size="4">Registration for site</font></p>
<form name="registerform" id="registerform" method="POST" action="<?php echo $editFormAction; ?>">
  <input name="usergroup" type="hidden" id="usergroup" value="member" />
  <table width="400" border="1" align="center">
    <tr>
      <td colspan="2"><font color="#FFFFFF">All fields marked with <font color="#FF0000">*</font>
        should be filled in</font></td>
    </tr>
    <tr>
      <td width="172"> <div align="center"><font color="#FFFFFF">First Name <font color="#FF0000">*</font></font></div></td>
      <td width="212"> <div align="center">
          <input name="firstname" type="text" id="firstname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Last Name <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="lastname" type="text" id="lastname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Username</font></div></td>
      <td> <div align="center">
          <input name="username" type="text" id="username" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="password" type="text" id="password" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Confirm Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="conpassword" type="text" id="conpassword" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Email</font></div></td>
      <td> <div align="center">
          <input name="email" type="text" id="email" />
        </div></td>
    </tr>
    <tr>
      <td colspan="2"> <div align="center">
          <input type="submit" name="Submit" value="Register" />
        </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="registerform">
</form>

<p>&nbsp; </p>
</body>
</html>
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
If the system is telling you that the lastname cannot be null, that's a database issue where your database is set to that field as null.  Additionally, if the value is not being parsed correctly to the database as in :

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "registerform")) {
  $insertSQL = sprintf("INSERT INTO tbl_users (username, password, firstname, lastname, usergroup, email) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($HTTP_POST_VARS['username'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['password'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['firstname'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['lastname'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['usergroup'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['email'], "text"));

Then you would need to look at the form and see exactly what the lastname field is actually called.  Chances are you have case incorrect, or there is a problem with the database field.  Give it a shot and see what happens.
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
issue where your database is set to that field as null should read: issue where your database is set to not null in the database value.  By not giving it a value, and the database receiving a null value, it will bomb out.
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
sorry but i dont get it.

My form works fine except when the fields are left empty(which peple tend to do)

so the point of this post is to find out what code i have to insert into my page so i get echo'd messages telling user to fill all fields in if they leave any empty

Do you understand?

Thanks
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
The first bit of code I provided checked whether a field was left blank, and if it was blank, to create a variable value which contained an error message.  I provided that code without every answer available because sometimes it's useful to use the logic and then improve on it to come up with a solution.  

Could I suggest that you review the code again and see where it can fit into the logic of your code.  If you don't understand what it does, let me know and I will do my best to explain how and why it works in the situation that I found it best to work in.  We can get it to fit your model perfectly, it just needs some modifcation and tweaking to fit nicely.

Hope this helps a bit.
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
Oh just one other thing, I notice that you do have some errors defined in your code above, before the sql insert statement, however your code that is asking whether something has been posted to it just before the sql statement, doesn't look for the error string.  It simply bypasses that.  

To give you a little guidance to how my script above works is that it first checks all the values of the posts, it then checks much lower down "if($isSubmitValid == true){" and then if yes, we then put in our sql statements, and email scripts, or what ever we want to happen if the values are correct and we want to process them.  If not, then we display the error messages.  Otherwise, if the whole form hasn't been submitted at that stage, instead of trying to process anything which doesn't exist, simply display the form for the user to submit :)
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
sorry mate, i am missing something(and bunged up with a cold)

Not sure what you mean by

review the code again and see where it can fit into the logic of your code

I am a relative newbie at this although i do get quite a bit. I just need help knowing what things actually do and where in my provided script i would put the suggested code.

If i am right the code you posted would need a fair bit of understanding of it, to edit and put in my script. or i am being stupid, which happens.. :O)

Thanks for your patience
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
Oh dear Satmanuk, I know exactly where you are coming from with the cold situation.  Would you believe that I have also been in the process of getting one too...not nice believe me.

Okay, I'll help you decipher where things need to be sorted because I'm just a nice guy :)  Lol, not really...uhh actually yes, but I know what it's like to be a newbie and don't apologize, that's why we are here...I hope.

I can see that your code has been generated by Dreamweaver, which I use on a daily basis to provide the skeleton of the code I wish to use, but modify it to fit my requirements.  Modify your code to the following and see if that helps:

<?php require_once('Connections/atrbcon.php'); ?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>

<!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>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body bgcolor="#000000">



<p align="center"><font color="#FFFFFF" size="4">Registration for site</font></p>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}


if(isset($_POST['submit'])){
//echo "POST DETECTED<br />";
          $isSubmitValid = true;
          //echo $isSubmitValid;
          $strMessage = "";
          $firstname = $_POST["firstname"];
          $lastname = $_POST["lastname"];
          $password = $_POST["password"];

          if($firstname == ""){
               $strMessage .= "<li>Please enter your firstname</li>";
               $isSubmitValid = false;
          }

          if($lastname == ""){
               $strMessage .= "<li>Please enter your lastname</li>";
               $isSubmitValid = false;
          }
          if($password == ""){
               $strMessage .= "<li>Please enter your password</li>";
               $isSubmitValid = false;
          }
         
               
          if($isSubmitValid == true){
$insertSQL = sprintf("INSERT INTO tbl_users (username, password, firstname, lastname, usergroup, email) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['firstname'], "text"),
                       GetSQLValueString($_POST['lastname'], "text"),
                       GetSQLValueString($_POST['usergroup'], "text"),
                       GetSQLValueString($_POST['email'], "text"));

  mysql_select_db($database_atrbcon, $atrbcon);
  $Result1 = mysql_query($insertSQL, $atrbcon) or die(mysql_error());

  $insertGoTo = "http://www.site.co.uk";
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
                <p style="color: red;"><?=$strEndMessage?> </p>
<?php
         
          } else{
?>

<form name="registerform" id="registerform" method="POST" action="<?php echo $editFormAction; ?>">
  <input name="usergroup" type="hidden" id="usergroup" value="member" />
  <table width="400" border="1" align="center">
    <tr>
      <td colspan="2"><font color="#FFFFFF">All fields marked with <font color="#FF0000">*</font>
        should be filled in</font></td>
    </tr>
    <tr>
      <td width="172"> <div align="center"><font color="#FFFFFF">First Name <font color="#FF0000">*</font></font></div></td>
      <td width="212"> <div align="center">
          <input name="firstname" type="text" id="firstname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Last Name <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="lastname" type="text" id="lastname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Username</font></div></td>
      <td> <div align="center">
          <input name="username" type="text" id="username" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="password" type="text" id="password" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Confirm Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="conpassword" type="text" id="conpassword" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Email</font></div></td>
      <td> <div align="center">
          <input name="email" type="text" id="email" />
        </div></td>
    </tr>
    <tr>
      <td colspan="2"> <div align="center">
          <input type="submit" name="Submit" value="Register" />
        </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="registerform">
</form>
<?php } ?>

<p>&nbsp; </p>
</body>
</html>

I'm not sure what version of dreamweaver you are working with, or what version of php you have on your server, however if your php version is higher than what your code was scripted with then HTTP_POST_VARS would be heavily outdated.  So I replaced it with _POST.  Just to note that both follow a $ which is a variable starter.  If you find that your php version is older and doesn't support $_POST, but only $HTTP_POST_VARS then do a search and replace on $_POST with $HTTP_POST_VARS.

Hope this helps.  let me know if you have any difficulties.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 18

Expert Comment

by:ingwa
Comment Utility
oops, where the

 header(sprintf("Location: %s", $insertGoTo));
}
?>
                <p style="color: red;"><?=$strEndMessage?> </p>
<?php
         
          } else{
?>



replace it with this:

  header(sprintf("Location: %s", $insertGoTo));
// On this page, display that the user was successful
} else{

?>
<p style="color: red;"><?=$strMessage; ?> <?php } ?>

<?php
         
          } else{
?>
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
Thanks for the help and understanding!

My PHP version is 4.4.4

I have run the page with the changed code but now the page loads fine but when i try and submit the form, the form emptys and it returns to the same page. I have tried with all fields filled out and i have tried missing some out but the same things happens.

i am pretty sure i have used POST in other pages do you know if this is ok?
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
i have tried replacing all $_post with $HTTP_POST_VARS  but nothing changes.

The page loads but is un useable, if you fill the form in and submit it, it returns to the same page and emptys the fields. No message about not filling in the fields and no data is inserted into the database.


anyone got any ideas on this?
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
Okay, I've had a look at it, and noticed that you don't have a default font colour, so all the text on the page is hidden.  I have done a slight re-write so that you can see how your code should look with the couple of mistakes fixed, along with some visible text.  Modify it so that it fits your design, but also use your mouse if you don't see an error message, especially if the form says it's successfully been submitted.

<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>

<!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>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body bgcolor="#000000">



<p align="center"><font color="#FFFFFF" size="4">Registration for site</font></p>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . $_SERVER['QUERY_STRING'];
}


if(isset($_POST['MM_insert'])){
//echo "POST DETECTED<br />";
      $isSubmitValid = true;
      //echo $isSubmitValid;
      $strMessage = "";
      $firstname = $_POST["firstname"];
      $lastname = $_POST["lastname"];
      $password = $_POST["password"];
      $conpassword = $_POST["conpassword"];
      
      if($firstname == ""){
      $strMessage .= "<li style=\"color: red;\">Please enter your firstname</li>";
      
      $isSubmitValid = false;
      }
      
      if($lastname == ""){
      $strMessage .= "<li style=\"color: red;\">Please enter your lastname</li>";
      $isSubmitValid = false;
      }
      if($password == ""){
      $strMessage .= "<li style=\"color: red;\">Please enter your password</li>";
      $isSubmitValid = false;
      }
      if($password != $conpassword){
      $strMessage .= "<li style=\"color: red;\">Your passwords do not match...please confirm your password</li>";
      $isSubmitValid = false;
      }

      if($isSubmitValid == true){
            echo "<p style=\"color: red;\">Form was successfully submitted</p>";
            $insertSQL = sprintf("INSERT INTO tbl_users (username, password, firstname, lastname, usergroup, email) VALUES (%s, %s, %s, %s, %s, %s)",
            GetSQLValueString($_POST['username'], "text"),
            GetSQLValueString($_POST['password'], "text"),
            GetSQLValueString($_POST['firstname'], "text"),
            GetSQLValueString($_POST['lastname'], "text"),
            GetSQLValueString($_POST['usergroup'], "text"),
            GetSQLValueString($_POST['email'], "text"));
            
            mysql_select_db($database_atrbcon, $atrbcon);
            $Result1 = mysql_query($insertSQL, $atrbcon) or die(mysql_error());
            
            $insertGoTo = "http://www.site.co.uk";
            
            header(sprintf("Location: %s", $insertGoTo));
            // On this page, display that the user was successful
      } else{
      
      ?>
      <p style="color: red;"><?php echo "There was an error with your submission:<br />".
$strMessage; ?></p> <?php } ?>
      
      <?php
      
} else{
      ?>

<form name="registerform" id="registerform" method="POST" action="<?php echo $editFormAction; ?>">
  <input name="usergroup" type="hidden" id="usergroup" value="member" />
  <table width="400" border="1" align="center">
    <tr>
      <td colspan="2"><font color="#FFFFFF">All fields marked with <font color="#FF0000">*</font>
        should be filled in</font></td>
    </tr>
    <tr>
      <td width="172"> <div align="center"><font color="#FFFFFF">First Name <font color="#FF0000">*</font></font></div></td>
      <td width="212"> <div align="center">
          <input name="firstname" type="text" id="firstname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Last Name <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="lastname" type="text" id="lastname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Username</font></div></td>
      <td> <div align="center">
          <input name="username" type="text" id="username" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="password" type="text" id="password" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Confirm Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="conpassword" type="text" id="conpassword" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Email</font></div></td>
      <td> <div align="center">
          <input name="email" type="text" id="email" />
        </div></td>
    </tr>
    <tr>
      <td colspan="2"> <div align="center">
          <input type="submit" name="Submit" value="Register" />
        </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="registerform">
</form>
<?php } ?>

<p>&nbsp; </p>
</body>
</html>

Hope this helps.
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
Oh, in answer to using $_POST instead of $HTTP_POST_VARS, as you are running a version of php higher than php 4.3x, you should always use the latest code.  $_POST looks for fields in a form that have been submitted and $_GET looks for variable values in the address line (eg: http://www.mysite.com/index.php?id=63&uid=72&ref=29 produces 3 variables called id, uid, and ref, and each has a value).

Hope this helps.
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
Ok, thanks again.

A couple of things.
1. The form says "Form was successfully submitted" when  all fields are filled. but nothing is added to the database?
i looked at "view source" of the page and saw this:
<p style="color: red;">Form was successfully submitted</p><br />
<b>Warning</b>:  mysql_select_db(): supplied argument is not a valid MySQL-Link resource in <b>/home/user/public_html/atrb/register3.php</b> on line <b>86</b><br />
<br />
<b>Warning</b>:  mysql_query(): supplied argument is not a valid MySQL-Link resource in <b>/home/user/public_html/atrb/register3.php</b> on line <b>87</b><br />

Line 86:           mysql_select_db($database_atrbcon, $atrbcon);
Line 87:           $Result1 = mysql_query($insertSQL, $atrbcon) or die(mysql_error());

2. If i leave a field blank i do get a message "There was an error with your submission:Please enter your lastname" but this is a blank page and the form is no longer there. I was hoping to have the form sat there and echo the error below the table so thery can try again.
The way it is i dont see the form no more. Works great though...

Thanks so much for this!






 

0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
ok i noticed the first line was missing
<?php require_once('Connections/atrbcon.php'); ?>

So i added that line. The record is now added. so all good. I looked at the "view source" again and noticed this though:
<p align="center"><font color="#FFFFFF" size="4">Registration for site</font></p>
<p style="color: red;">Form was successfully submitted</p><br />
<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/user/public_html/atrb/register3.php:15) in <b>/home/user/public_html/atrb/register3.php</b> on line <b>91</b><br />

Line 91 is:           header(sprintf("Location: %s", $insertGoTo));


here is my code now:

<?php require_once('Connections/atrbcon.php'); ?>

<!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>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body bgcolor="#000000">



<p align="center"><font color="#FFFFFF" size="4">Registration for site</font></p>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . $_SERVER['QUERY_STRING'];
}


if(isset($_POST['MM_insert'])){
//echo "POST DETECTED<br />";
     $isSubmitValid = true;
     //echo $isSubmitValid;
     $strMessage = "";
     $firstname = $_POST["firstname"];
     $lastname = $_POST["lastname"];
     $password = $_POST["password"];
     $conpassword = $_POST["conpassword"];
     
     if($firstname == ""){
     $strMessage .= "<li style=\"color: red;\">Please enter your firstname</li>";
     
     $isSubmitValid = false;
     }
     
     if($lastname == ""){
     $strMessage .= "<li style=\"color: red;\">Please enter your lastname</li>";
     $isSubmitValid = false;
     }
     if($password == ""){
     $strMessage .= "<li style=\"color: red;\">Please enter your password</li>";
     $isSubmitValid = false;
     }
     if($password != $conpassword){
     $strMessage .= "<li style=\"color: red;\">Your passwords do not match...please confirm your password</li>";
     $isSubmitValid = false;
     }

     if($isSubmitValid == true){
          echo "<p style=\"color: red;\">Form was successfully submitted</p>";
          $insertSQL = sprintf("INSERT INTO tbl_users (username, password, firstname, lastname, usergroup, email) VALUES (%s, %s, %s, %s, %s, %s)",
          GetSQLValueString($_POST['username'], "text"),
          GetSQLValueString($_POST['password'], "text"),
          GetSQLValueString($_POST['firstname'], "text"),
          GetSQLValueString($_POST['lastname'], "text"),
          GetSQLValueString($_POST['usergroup'], "text"),
          GetSQLValueString($_POST['email'], "text"));
         
          mysql_select_db($database_atrbcon, $atrbcon);
          $Result1 = mysql_query($insertSQL, $atrbcon) or die(mysql_error());
         
          $insertGoTo = "http://www.site.co.uk";
         
          header(sprintf("Location: %s", $insertGoTo));
          // On this page, display that the user was successful
     } else{
     
     ?>
     <p style="color: red;"><?php echo "There was an error with your submission:<br />".
$strMessage; ?></p> <?php } ?>
     
     <?php
     
} else{
     ?>

<form name="registerform" id="registerform" method="POST" action="<?php echo $editFormAction; ?>">
  <input name="usergroup" type="hidden" id="usergroup" value="member" />
  <table width="400" border="1" align="center">
    <tr>
      <td colspan="2"><font color="#FFFFFF">All fields marked with <font color="#FF0000">*</font>
        should be filled in</font></td>
    </tr>
    <tr>
      <td width="172"> <div align="center"><font color="#FFFFFF">First Name <font color="#FF0000">*</font></font></div></td>
      <td width="212"> <div align="center">
          <input name="firstname" type="text" id="firstname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Last Name <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="lastname" type="text" id="lastname" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Username</font></div></td>
      <td> <div align="center">
          <input name="username" type="text" id="username" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="password" type="text" id="password" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Confirm Password <font color="#FF0000">*</font></font></div></td>
      <td> <div align="center">
          <input name="conpassword" type="text" id="conpassword" />
        </div></td>
    </tr>
    <tr>
      <td> <div align="center"><font color="#FFFFFF">Email</font></div></td>
      <td> <div align="center">
          <input name="email" type="text" id="email" />
        </div></td>
    </tr>
    <tr>
      <td colspan="2"> <div align="center">
          <input type="submit" name="Submit" value="Register" />
        </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="registerform">
</form>
<?php } ?>

<p>&nbsp; </p>
</body>
</html>

Thanks again
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
Okay, if you want the script to direct the user to a new page, with a custom message, change header(sprintf("Location: %s", $insertGoTo)); to header(sprintf("Location: mynewpage.php"));  Otherwise comment out the line with two forward slashes // header(sprintf("Location: %s", $insertGoTo));

hope this helps.
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
for some reason that head line doesnt work, i get this in the view source on internet explorer and that tells me thats why it isnt going to the page i have chosen in the header string.

<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/user/public_html/atrb/register3.php:15) in <b>/home/user/public_html/atrb/register3.php</b> on line <b>91</b><br />
     
Line 91 is:           header(sprintf("Location: http://www.mysite.co.uk"));

i have tried both

          header(sprintf("Location: http://www.mysite.co.uk"));
and

        //  header(sprintf("Location: %s", $insertGoTo));

with the same results.


The page stays on register.php and the table disapears.
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
If you want the table to show, remove the text that says the form was submitted, and then put in the form before the else
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
hey? you lost me

The way i imagined my page to work is.

visit page and view a form to fill.
If you forget to fill a field or pasword doesnt match then the echo'd message would be displayed below the showing table/form. Bit like when you register on any site really. You still see the form as you havent filled it out correctly yet. and the echo'd messages display either below the table or some have it by the field you havent filled in. i would be happy with the message being displayed below the table, as i want the user to still try and regsiter using the table/form. If the page goes else where then they may not go back and try again.

If the form is filled correctly then they would not see the form they would be directed to www.mysite.co.uk


Does that make sesne?

sorry and thanks
0
 
LVL 1

Author Comment

by:satmanuk
Comment Utility
hey, no worries i kind of got what i am looking for. i will put another post up about the fine tweaking....


Thanks
0
 
LVL 18

Expert Comment

by:ingwa
Comment Utility
Hi Satmanuk, glad you got it working.  Thanks for the points and grade, have a great day.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now