为什么服务器不能将其识别为PHP代码?

时间:2012-10-21 21:55:55

标签: php

当加载到服务器http://letsplays.uni.me/addchannel.html时,代码将从此部分出现,因为这是语法突出显示停止的地方! $ value){if(empty($ value)&& in_array($ key,$ required_fields)=== true){$ errors [] ='标有*的字段为必填项';休息1; }>

似乎相当突然,似乎没有任何问题!

<?php
if(empty($_Post) === false) {
    $required_fields = array('email', 'password', 'repeatpassword', 'channelurl', 'chanelname', 'embedd1', 'keywords');
    foreach($_POST as $key=>$value) {
        if (empty($value) && in_array($key, $required_fields) === true) {
            $errors[] = 'Fields marked with * are required';
            break 1;
        }
    }
}
?>






<?php require_once('Connections/connecttotable.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO Userchannel (chanelID, firstname, lastname, email, password, channelurl, chanelname, `description`, embedd1, game1, Embedd2, game2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['chanelID'], "int"),
                       GetSQLValueString($_POST['firstname'], "text"),
                       GetSQLValueString($_POST['lastname'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['channelurl'], "text"),
                       GetSQLValueString($_POST['chanelname'], "text"),
                       GetSQLValueString($_POST['description'], "text"),
                       GetSQLValueString($_POST['embedd1'], "text"),
                       GetSQLValueString($_POST['game1'], "text"),
                       GetSQLValueString($_POST['Embedd2'], "text"),
                       GetSQLValueString($_POST['game2'], "text"));

  mysql_select_db($database_connecttotable, $connecttotable);
  $Result1 = mysql_query($insertSQL, $connecttotable) or die(mysql_error());

  $insertGoTo = "mychanel.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_connecttotable, $connecttotable);
$query_Recordset1 = "SELECT * FROM Userchannel";
$Recordset1 = mysql_query($query_Recordset1, $connecttotable) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<style type="text/css">
#wrapper .pretag #main h1 {
    text-align: center;
}
</style>
<!-- InstanceBegin template="/Templates/header.dwt" codeOutsideHTMLIsLocked="false" -->
        <style type="text/css">
        .links {
    font-size: 24px;
    color: #FFF;
}
        #main {
    height: auto;
    width: 1024px;
}
        #main {
    height: auto;
    width: 1024px;
}
        #footer {
    height: auto;
    width: 1024px;
}
        #navbar2 {
    height: auto;
    width: 512px;
    float: left;
}
        #advertisement {
    background-color: #039;
    height: 150px;
    width: 512px;
    float: left;
}
        </style>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript">
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
<body onLoad="MM_preloadImages('images/homerollover.jpg','images/ChannelSearchrlo.jpg','images/Channelcreaterlo.jpg','images/Newsrlo.jpg','images/about.jpg','images/Aboutrlo.jpg')">
<!-- InstanceBeginEditable name="mainarea" -->
<div id="wrapper">
  <style type="text/css">
#wrapper {
    height: auto;
    width: 1024px;
    margin-right: auto;
    margin-left: auto;
}
#header {
    background-image: url(images/heading2.jpg);
    height: 200px;
    width: 1024px;
}
  </style>
  <div id="header">
    <pre>
    <p class="pretag"><span class="links"></span></p>
    <pre class="pretag"><span class="links">           

               <a href="http://letsplays.uni.me/" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','images/homerollover.jpg',1)"><img src="images/Home.jpg" alt="Go Home" name="Image1" width="150" height="30" border="0"></a><a href="http://letsplays.uni.me/" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','images/homerollover.jpg',1)"></a></span>  <a href="ChannelSearch.php.txt" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Channelsearch','','images/ChannelSearchrlo.jpg',1)"><img src="images/channelsearch.jpg" alt="Channel Search" name="Channelsearch" width="150" height="30" border="0"></a>  <a href="CreateChannel.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Create Channel','','images/Channelcreaterlo.jpg',1)"><img src="images/channeladd.jpg" alt="Create Channel" name="Create Channel" width="150" height="30" border="0"></a>  <a href="ign.com" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('News','','images/Newsrlo.jpg',1)"><img src="images/News.jpg" alt="News" name="News" width="150" height="30" border="0"></a> <a href="About.html.txt" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('About','','images/Aboutrlo.jpg',1)"><img src="images/about.jpg" alt="About this page" name="About" width="150" height="30" border="0"></a><a href="About.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('About ','','images/about.jpg',1)"></a></pre>
  </div>
  <span class="pretag">
  <div id="main"><h1>Add Your Channel</h1>
  <?php
<?php
if(empty($_POS) === false) {
    $required_fields = array('email', 'password', 'repeatpassword', 'channelurl', 'chanelname', 'embedd1', 'keywords')
    foreach($_POST as $key=>$value) {
        if (empty($value) && in_array($key, $required_fields) === true) {
            $errors[] = 'Fields marked with * are required';
            break 1;
        }
    }
}
print_r($errors);
?>



  </h1>
    <p>&nbsp;</p>
    <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
      <table align="center">
        <tr valign="baseline">
          <td nowrap align="right">First name:</td>
          <td><input type="text" name="firstname" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Last name:</td>
          <td><input type="text" name="lastname" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Email:*</td>
          <td><input type="text" name="email" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Password:*</td>
          <td><input type="password" name="password" value="" size="32"></td>
        </tr>
         <tr valign="baseline">
          <td nowrap align="right">Repeat Password:*</td>
          <td><input type="password" name="repeatpassword" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right" valign="top">Channel url:*</td>
          <td><textarea name="channelurl" cols="50" rows="1"></textarea></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Channel name:*</td>
          <td><input type="text" name="chanelname" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Description:</td>
          <td><textarea name="description" cols="32" rows="6"></textarea></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Video 1:* </td>
          <td><input type="text" name="embedd1" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">What game is it?</td>
          <td><input type="text" name="game1" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Video 2:</td>
          <td><input type="text" name="Embedd2" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">What game is it?</td>
          <td><input type="text" name="game2" value="" size="32"></td>
          </tr>
         <tr valign="baseline">
          <td nowrap align="right">Keywords to describe and find your channel*</td>
          <td><input type="text" name="keywords" value="" size="32"></td>  
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">&nbsp;</td>
          <td><input type="submit" value="Channel Create"></td>
        </tr>
      </table>
      <input type="hidden" name="chanelID" value="">
      <input type="hidden" name="MM_insert" value="form1">
    </form>
    <p>&nbsp;</p>
  </div>
  </span>
  <div id="footer">
    <div id="navbar2">
      <ul>
        <li>
          <url src="http://letsplays.uni.me">
          Home</li>
        <li>
          <url src="http://letsplays.uni.me/addchannel">
          Cnannel Add</li>
        <li>
          <url src="http://letsplays.uni.me/channelsearch">
          Channel Search</li>
        <li>
          <url src="http://letsplays.uni.me/news">
          News</li>
        <li>
          <url src="http://letsplays.uni.me/about">
          About and Contact</li>
      </ul>
    </div>
    <div id="advertisement"></div>
  </div>
</div>
<!-- InstanceEndEditable -->
</body>
<!-- InstanceEnd -->
<?php
mysql_free_result($Recordset1);
?>

3 个答案:

答案 0 :(得分:1)

您的服务器未配置为运行php /没有安装php / 无法将html文件识别为php

如果您在浏览器中查看页面的来源,您会看到它以:

开头
<?php require_once('Connections/connecttotable.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
// ........

我认为这是你文件的顶部。

您可能只需要将文件的扩展名更改为.php

答案 1 :(得分:0)

我没有看到任何语法问题。 (黄色警告是关于未初始化的变量)。另外,第一个$ _Post应该是$ _POST imo。

enter image description here

答案 2 :(得分:0)

这是你的问题:

$required_fields = array('email', 'password', 'repeatpassword', 'channelurl', 'chanelname', 'embedd1', 'keywords')
                                                                                                                //^ No semi-colon.

你必须用分号结束所有的php语句。