Jump to content

Archived

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

tomfmason

simple form issue

Recommended Posts

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.

[code]
<?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>[/code]

and here is the addDomain function

[code=php:0]
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;
}[/code]


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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.