表单出错

时间:2014-05-22 06:49:04

标签: php

<?php
if(isset($_POST['submit'])) 
{
    if(!empty($_POST['cid']))
    {   
        mkdir('/home/something/public_html/test/ref/' . $cid . "_income" , 0777);
        copy('/home/something/public_html/test/ref/API.class.php','/home/something/public_html/test/ref/' . $cid . "_income" . '/API.class.php');
        if(isset($_POST['beach']
        {
        copy('/home/something/public_html/test/ref/beach/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        copy('/home/something/public_html/test/ref/beach/beach.jpg' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/beach.jpg');
        copy('/home/something/public_html/test/ref/beach/video.png' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/video.png') ;
        }
        else if(isset($_POST['sunset']
        {
        copy('/home/something/public_html/test/ref/sunset/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        copy('/home/something/public_html/test/ref/sunset/beach.jpg' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/beach.jpg');
        copy('/home/something/public_html/test/ref/sunset/video.png' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/video.png');
        }
        else if(isset($_POST['greenbg']
        {
        copy('/home/something/public_html/test/ref/green/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        }
        else if(isset($_POST['orangebg']
        {
        copy('/home/something/public_html/test/ref/orange/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        }
        else
        {
        copy('/home/something/public_html/test/ref/default/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        copy('/home/something/public_html/test/ref/default/beach.jpg' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/beach.jpg');
        copy('/home/something/public_html/test/ref/default/video.png' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/video.png');
        }
    $_SESSION['click'] = $cid;
    $_SESSION['Active'] = $aid;
    $_SESSION['dropdown'] = $drop;
    }
    else
    {
    echo '<script language="javascript">';
    echo 'alert("Please “Enter your ID")';
    echo '</script>';
    }
}


?>

我遇到问题,我在MAC上使用TextWrangler。我认为if和else if语句的部分有问题。

这些是我们客户选择的主题,所以当他们点击单选按钮时。然后,该值传递到PHP以生成反映其选择的页面。

现在我感觉到弄乱我的功能的代码是这样的:

if(isset($_POST['beach']
        {
        copy('/home/something/public_html/test/ref/beach/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        copy('/home/something/public_html/test/ref/beach/beach.jpg' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/beach.jpg');
        copy('/home/something/public_html/test/ref/beach/video.png' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/video.png')    ;
        }
        else if(isset($_POST['sunset']
        {
        copy('/home/something/public_html/test/ref/sunset/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        copy('/home/something/public_html/test/ref/sunset/beach.jpg' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/beach.jpg');
        copy('/home/something/public_html/test/ref/sunset/video.png' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/video.png');
        }
        else if(isset($_POST['greenbg']
        {
        copy('/home/something/public_html/test/ref/green/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        }
        else if(isset($_POST['orangebg']
        {
        copy('/home/something/public_html/test/ref/orange/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        }
        else
        {
        copy('/home/something/public_html/test/ref/default/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        copy('/home/something/public_html/test/ref/default/beach.jpg' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/beach.jpg');
        copy('/home/something/public_html/test/ref/default/video.png' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/video.png');
        }

我是PHP的新手,我希望我能学到一些东西。

2 个答案:

答案 0 :(得分:3)

在大多数以if(isset(开头的行后,您忘记了右括号。将))添加到包含if(isset(的行的末尾,并且还没有右括号,因此它看起来像这样:if(isset($_POST['beach']))else if(isset($_POST['orangebg']))

答案 1 :(得分:2)

替换

之类的所有行
if(isset($_POST['beach']

if(isset($_POST['beach'])) // see the closing parenthesis?

最终正确的代码是

if(isset($_POST['submit'])) 
{
    if(!empty($_POST['cid']))
    {   
        mkdir('/home/something/public_html/test/ref/' . $cid . "_income" , 0777);
        copy('/home/something/public_html/test/ref/API.class.php','/home/something/public_html/test/ref/' . $cid . "_income" . '/API.class.php');
        if(isset($_POST['beach']))
        {
            copy('/home/something/public_html/test/ref/beach/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
            copy('/home/something/public_html/test/ref/beach/beach.jpg' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/beach.jpg');
            copy('/home/something/public_html/test/ref/beach/video.png' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/video.png') ;
        }
        else if(isset($_POST['sunset']))
        {
            copy('/home/something/public_html/test/ref/sunset/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
            copy('/home/something/public_html/test/ref/sunset/beach.jpg' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/beach.jpg');
            copy('/home/something/public_html/test/ref/sunset/video.png' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/video.png');
        }
        else if(isset($_POST['greenbg']))
        {
            copy('/home/something/public_html/test/ref/green/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        }
        else if(isset($_POST['orangebg']))
        {
            copy('/home/something/public_html/test/ref/orange/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
        }
        else
        {
            copy('/home/something/public_html/test/ref/default/index.php' ,'/home/something/public_html/test/ref/'.$cid ."_income".'/index.php');
            copy('/home/something/public_html/test/ref/default/beach.jpg' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/beach.jpg');
            copy('/home/something/public_html/test/ref/default/video.png' ,'/home/something/public_html/test/ref/' . $cid . "_income" . '/video.png');
        }
        $_SESSION['click'] = $cid;
        $_SESSION['Active'] = $aid;
        $_SESSION['dropdown'] = $drop;
    }
    else
    {
        echo '<script language="javascript">';
        echo 'alert("Please “Enter your ID")';
        echo '</script>';
    }
}