MySql& PHP代码显示为纯文本

时间:2015-06-18 05:01:02

标签: php html mysql localhost

在cPanel中我没有问题那些工作正常。但是在localhost中我遇到了很多错误。

 Notice: Undefined variable: eroare in C:\xampp\htdocs\invo\install\index.php on line 68

Notice: Undefined variable: suc in C:\xampp\htdocs\invo\install\index.php on line 69

下面的index.php文件:

<?php
session_start();
if(isset($_POST['submit'])){
    if($_POST['admin_user']=='' || $_POST['admin_pass']==''){
        $eroare='Admin User/Pass Empty!';
    }
    if(!@mysql_connect($_POST['mysql_host'],$_POST['mysql_user'],$_POST['mysql_pass'])){
        $eroare='MySQL Connection Failure';
    }   

    if(!@mysql_select_db($_POST['mysql_db'])){
        $eroare='MySQL Database Not Found!';
    }
    if(!$eroare){
    $filename       = 'sql.sql';
        $templine = '';
        $lines    = @file($filename);
        if(is_array($lines)){
            foreach ($lines as $line_num => $line) {
                if (substr($line, 0, 2) != '--' && $line != '') {
                    $templine .= $line;
                    if (substr(trim($line), -1, 1) == ';') {
                        mysql_query($templine) or print('Error performing query \'<b>' . $templine . '</b>\': ' . mysql_error() . '<br /><br />');
                        $templine = '';
                    }
                }
            }
        }

        $myFile = "../inc/db.php";
            $fh = @fopen($myFile, 'w+') or $success=1;
            $stringData = '<?php
                $host      = "'.$_POST['mysql_host'].'";
                $username  = "'.$_POST['mysql_user'].'";
                $password  = "'.$_POST['mysql_pass'].'";
                $db        = "'.$_POST['mysql_db'].'";
                mysql_connect($host, $username, $password) or die("<center><font color=\"darkred\"><b>Cannot connect to database!</b></font></center>");
                mysql_select_db($db);
            ?>';
            @fwrite($fh, $stringData);
            @fclose($fh);   
            mysql_query("insert into config(name,value) values('admin_user','".$_POST['admin_user']."')")or die(mysql_error());
            mysql_query("insert into config(name,value) values('admin_pass','".$_POST['admin_pass']."')")or die(mysql_error());

            if($success!=1){
                $_SESSION['logged']=1;
                $suc="Successfully Installed!<br/>Please configure your script from the <a href='../settings.php'>Settings Tab</a>";    

            }else
                $suc='<b>Success!</b> The inc/db.php file <b>could not be created</b>. Please rename the db_config.php to db.php and configure it manually by opening the file in a text editor through FTP!';

    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>CDM Maker Installation</title>
    <link rel="stylesheet" type="text/css" href="install.css" media="screen"/>
</head>
<body>

        <div id="container2">
            <div id="container">
                <div class='header'>Installation</div>
                <div class="content">
                    <?php if($eroare){?><div class='error'><?php echo $eroare?></div><?php }?>
                    <?php if($suc){?><div class='suc'><?php echo $suc?></div><?php }?>
                        <form action='' method='POST'>          
                            <table width='100%' cellspacing='0' cellpadding='0'>
                                <tr>
                                    <td>
                                        <label for='username'>Admin Username</label>
                                        <input type='text' class='login' name='admin_user' id='username' value='<? echo $_POST['admin_user']?>' placeholder="admin" required/>  

                                        <label for='parola'>Admin Password</label>
                                        <input type='text' class='login' name='admin_pass' id='parola' value='<? echo $_POST['admin_pass']?>' placeholder="admin" required/>                                        

                                        <label for='host'>MySQL Host</label>
                                        <input type='text' class='login' name='mysql_host' id='host' value='<? echo $_POST['mysql_host']?>' placeholder="localhost" required/>

                                        <label for='user'>MySQL User</label>
                                        <input type='text' class='login' name='mysql_user' id='user' value='<? echo $_POST['mysql_user']?>' placeholder="johndoe" required/>

                                        <label for='pass'>MySQL Password</label>
                                        <input type='text' class='login' name='mysql_pass' id='pass' value='<? echo $_POST['mysql_pass']?>' placeholder="********" required/>

                                        <label for='db'>MySQL DB</label>
                                        <input type='text' class='login' name='mysql_db' id='db' value='<? echo $_POST['mysql_db']?>' placeholder="my_database" required/>

                                        <div style='clear:both; height:15px;'></div>
                                        <center><button class="submit" name='submit' type="submit">Install</button></center>
                                    </td>
                                </tr>
                            </table>
                        </form>                 
                </div>          
            </div>
        </div>
</body>
</html>

我已经尝试过ioncube但是我认为我的本地主机中缺少一些东西,请告诉我如何在我的本地主机上运行它。这个undefine变量仅在localhost中声明,但在cpanel中声明为bot。

4 个答案:

答案 0 :(得分:2)

在文件开头初始化所有变量无论

    $eroare = $suc  = '';

请使用像PHPStorm这样的好IDE,然后点击Inspect Code工具查看弱错误和警告。

在服务器上,警告,错误已关闭。所以看到你的代码失败而没有发出任何警告的噩梦。所以请检查代码,然后只上传到实时服务器上。

答案 1 :(得分:0)

首先,您在localhost中启用了更高级别的错误报告,而不是在远程计算机上启用。此通知级别错误不应该停止脚本执行。如果要修复错误,请在if语句中使用!empty($variable)表达式,如下所示:

            <div class="content">
                <?php if(!empty($eroare)){?><div class='error'><?php echo $eroare?></div><?php }?>
                <?php if(!empty($suc)){?><div class='suc'><?php echo $suc?></div><?php }?>
                    <form action='' method='POST'>  

答案 2 :(得分:0)

试试这个脚本。

在session start()函数之后添加这两行。

 $eroare='';
 $suc='';

答案 3 :(得分:0)

试试这个

if (empty($_POST['eroare'])) {
    $eroare="";
} else {
    $eroare=$_POST['eroare'];
}