Jump to content

Weird script problems, please help


xgd

Recommended Posts

Hello people,

 

I've made this registration script that actually works, nut i get weird problems when i try to submit it with emty fields or when i try to use 2 different passwords while registering.

 

If i try to submit it without entering anything into the fields, i get the following error message:

 

Didnt fill in FIRST NAME

Didnt fill in LAST NAME

Didnt enter EMAIL

Didnt enter pass

 

Notice: Undefined variable: fn in C:\Program Files\EasyPHP 3.0\www\register.php on line 76

 

And if i try to submit it using 2 different passwords i get this:

 

Passwords dont match

 

Notice: Undefined variable: p in C:\Program Files\EasyPHP 3.0\www\register.php on line 76

 

so the script actually works, it registers normally if everything is OK, and it doesnt register if something is not valid, but i get these weird error messages of undefined variables that i believe i have defined.

 

the script goes like this:

 

<?php

// SET UP THE DATA INPUT FIELDS

  if (isset($_POST['submit'])) {
   
    require_once('db_connect.php');

if (empty($_POST['first_name'])) {

   echo "Didnt fill in FIRST NAME<br />";
   } else {
   
      $fn = trim($_POST['first_name']);
	  
	  }
	  
	  
    if (empty($_POST['last_name'])) {

   echo "Didnt fill in LAST NAME<br />";
   
   } else {
   
   $ln = trim($_POST['last_name']);
   
   }
   
   if (empty($_POST['email'])) {
   
      echo "Didnt enter EMAIL<br />";
	  } else {
	  
	     $e = trim($_POST['email']);

		 }


  if (!empty($_POST['pass1'])) {
  
  if ($_POST['pass1'] != $_POST['pass2']) {
  
     echo "Passwords dont match<br />";
	 } else {

	 $p = trim($_POST['pass1']);
	 }
	 }
	 else {
	 echo "Didnt enter pass<br />";
	 }

if ($fn && $ln && $e && $p) {


// MAKE SURE EMAIL ADDRESS IS NOT ALREADY IN USE

$q = "SELECT user_id FROM users WHERE email='$e'";

$r = mysqli_query($dbc, $q) or trigger_error("Problem with query".mysqli_error($dbc));

if (mysqli_num_rows($r) == 0) {

   $q = "INSERT INTO users (email, pass, first_name, last_name, reg_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', NOW() )";
   
   $r = mysqli_query($dbc, $q) or trigger_error("error inserting".mysqli_error($dbc));
   
   if (mysqli_affected_rows($dbc) == 1) {
   
       echo "you have been regiatered";
   } else {
   echo "System error, you could not be registered";
   }
   }
   else {
   echo "Email address already in use, choose another one";
   }
   }
   }
   ?>

 

What is wrong with this WORKING code ? ???

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/164756-weird-script-problems-please-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.