Jump to content

simple form issue


tomfmason

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
Link to comment
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.
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.