Jump to content

After validation name doesnt post to database???


mikebyrne

Recommended Posts

Once my code runs through the validation process ok and posts all the data to the database apart from the name field. I cant figure out why though??

 

My code is

<?php
require_once("adminconnect.php");

$tbl_name="adminusers";


$name = $_POST['name'];
$address = $_POST['address'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$address4 = $_POST['address4'];
$county = $_POST['county'];
$zip = $_POST['zip'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$password =$_POST['password'];
$username = $_POST['username'];
$num =$_POST ['num'];


if($_POST["action"] == "signup"){

        $valid=1;

                if ($_POST['name']=="") {
			echo 'got no name<br>';
                $valid=0;
                $style_name = "background-color:#FF5959";
                $error_name = "Your name seems to be mising?<br>";
                                }

			if ($address == "" || strlen($address) < 2) {
    			echo 'got no address1<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address = "There is a problem with the address field?<br>";
							}


			if ($address1 == "" || strlen($address1) < 2) {
    			echo 'got no address1<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address1 = "There is a problem with the address field?<br>";
							}

			if ($address2 == "" || strlen($address2) < 2) {
    			echo 'got no address2<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address2 = "There is a problem with the address field?<br>";
							}

			if ($address3 == "" || strlen($address3) < 2) {
    			echo 'got no address3<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address3 = "There is a problem with the address field?<br>";
							}

			if ($address4 == "" || strlen($address4) < 2) {
    			echo 'got no address4<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address4 = "There is a problem with the address field?<br>";
							}
			if ($county == "" || strlen($county)<2) {
			echo 'got no county<br>';
                $valid=0;
                $style_county = "background-color:#FF5959";
                $error_county = "The County field is blank?<br>";
        						} 
			if ($zip == "" || strlen($zip)<2) {
			echo 'got no zip<br>';
                $valid=0;
                $style_zip = "background-color:#FF5959";
                $error_zip = "Theres a problem with the zip code?<br>";
        						}   
			if (!eregi("^[0-9]+",$telephone)) {
			echo 'got no phone<br>';
                $valid=0;
                $style_telephone = "background-color:#FF5959";
                $error_telephone = "Theres a problem with the telephone number?<br>";
        						}   
			  if (!eregi("^[A-Za-z0-9.-]+",$email)) {
			echo 'got no mail';
                $valid=0;
                $style_email = "background-color:#FF5959";
                $error_email = "Theres a problem with the email address?<br>";
       						 	}
        
        		if ($password == "" || strlen($password)<7) {
			echo 'got no password';
                $valid=0;
                $style_password = "background-color:#FF5959";
                $error_password = "Theres a problems with your password?<br>";
       							 }      


$user = mysql_real_escape_string(htmlspecialchars($_POST['username']));


$sql = "SELECT name FROM adminusers WHERE username ='$user'";
echo ".$user.";
$result = mysql_query($sql) or die("Error in SQL: ".mysql_error());
$row = mysql_fetch_array($result);
$count = mysql_num_rows($result);

$name = $row['name'];


			if ($count > 0) { // username should only exist once.
			$valid=0;
			$style_username = "background-color:#FF5959";
			$error_username = "Error! The username " . $user . " already exists in the database.";
							}

			if ($password == "" || strlen($password)<7) {
                $valid=0;
                $style_password = "background-color:#FF5959";
                $error_password = "Theres a problems with your password?<br>";

        						}
if ($valid==1) {       
                $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password, usertype)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password' , 2)";
$result=mysql_query($sql)or die(mysql_error()."<p>With Query<br>$sql");
}
?>

 

The sql for the database is

 

CREATE TABLE `adminusers` (

  `name` varchar(255) collate latin1_general_ci default NULL,

  `address` varchar(255) collate latin1_general_ci default NULL,

  `address1` varchar(255) collate latin1_general_ci default NULL,

  `address2` varchar(255) collate latin1_general_ci default NULL,

  `address3` varchar(255) collate latin1_general_ci default NULL,

  `address4` varchar(255) collate latin1_general_ci default NULL,

  `county` varchar(255) collate latin1_general_ci default NULL,

  `zip` varchar(255) collate latin1_general_ci default NULL,

  `telephone` decimal(10,0) default NULL,

  `email` varchar(255) collate latin1_general_ci default NULL,

  `username` varchar(255) collate latin1_general_ci default NULL,

  `password` varchar(255) collate latin1_general_ci default NULL,

  `usertype` decimal(10,0) default NULL

) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

 

Link to comment
Share on other sites

if ($valid==1) {       
                $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password, usertype)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password' , 2)";
echo $result;

$result=mysql_query($sql)or die(mysql_error()."<p>With Query<br>$sql");
}

 

The echo seems to be Resource id #4

Link to comment
Share on other sites

INSERT INTO adminusers(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password, usertype)VALUES('', 'kjsfksjdisjdsklj', 'aixasixuxiau', 'iduwiuewieu','iudisudisuci', 'isucdiuvdifuiof','idudiufdifueiof' ,'ocdicodicsodisoi', '92839483984390', 'oskfodjfoefkodvop', 'bisgosowo', 'okcodfodfosi' , 2)

 

seems to be leaving name out

Link to comment
Share on other sites

Yeah I see what you mean

 

$name = $row['name']; is used as part of this validation

 

$user = mysql_real_escape_string(htmlspecialchars($_POST['username']));


$sql = "SELECT name FROM adminusers WHERE username ='$user'";
echo ".$user.";
$result = mysql_query($sql) or die("Error in SQL: ".mysql_error());
$row = mysql_fetch_array($result);
$count = mysql_num_rows($result);

$name = $row['name'];


			if ($count > 0) { // username should only exist once.
			$valid=0;
			$style_username = "background-color:#FF5959";
			$error_username = "Error! The username " . $user . " already exists in the database.";
							}

 

Would you recommend I change the varible names? If so, how would you word it?

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.