Jump to content


Photo

simple form issue


  • Please log in to reply
2 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 07 August 2006 - 02:36 PM

I am having an issue with a form. I have tested everything that I can think of. I am sure that it is a rather simple issue. Ok this form posts to it's self and then is supposed to include a function from another file.

Here is the form.

<?php
include("db.php");
include("functions.php");	
if (isset($submit)) {
    if (!$domain) {
	   $message = "domain";
	   exit();
	}
	$domain = $_POST['domain'];
	$domain = stripslashes($domain);
	$username = "test";
	$user_id = "65";
	$test = addDomain();
	
	if ($test == "false") {
	    $message = "add";
	}else{
	   $message = "sucess";
	}   	
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Add Domain</title>
</head>

<body>
<?php
if ($message == "domain") {
    echo "You did not enter a domain";
}
if ($message == "add") {
    echo "unable to add the new domain";
}
if ($message == "success") {
    echo "The domain was added sucessfuly";
}
?>
<form action="domains.php" method="post">
<p>Add a Domain</p> 
www.<input type="text" name="domain">
<input type="submit" name="submit" value="Add Domain">
</form>

</body>
</html>

and here is the addDomain function

function addDomain() {
    function updatedb() {
        global $domain;
        global $user_id;
        global $ip;
	   
        $sql = mysql_query("INSERT INTO `domains` (`user_id`, `domain`, `date_added`) 
	    VALUES ('$user_id', '$domain', now())");
		
        if (!$sql) {
           $result = "false";
        }
        return $result;
    }
    function createDir() {
        global $domain;	   
        global $username;
	   
        $newDomain = mkdir("C:/home/$username/$domain");
        if (!$newDomain) {
           $result = "false";
        }else{
           $public = mkdir("C:/home/$username/$domain/public");
           $private = mkdir("C:/home/$username/$domain/private");
           $sub = mkdir("C:/home/$username/$domain/sub_domains");
           if ((!$public) || (!$private) || (!$sub)) {
               $result = "false";
            }
         }
         return $result;
   }
   $updateDb = updateDb();
   $createDir = createDir();
   if ($updateDb || $createDir == "false") {
       $result = "false";
   }
   return $result;
}


I tested calling the addDomain() at the end of the functions.php and it works just fine. It creates the needed directorys.

Any suggestions would be great.

Thanks,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 07 August 2006 - 02:38 PM

the damn script got knocked out of wack again. I swear my coding is cleaner then this. It may not be 100% correct but at least it is clean..lol

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 07 August 2006 - 02:41 PM

if this a case of testing on a different machine than the live serve you should check to see if register_globals is on or off (it should be off!) and i suspect the testing server has it turned on.

You should use

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

instead of just

if ($submit)

OR you can define the short name vars before you process any of the post/get data

$submit = $_POST['submit'];

and so on....

ALSO it is probably better to pass all the data to the function implicitly instead of using global within the function - just gets you used to doing things in a 'strict' manner. but it aint that important here.
follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users