好吧,我有一个用PHP和javascript处理的html表单。它现在通过javascript rigth验证。它在我的localhost上没问题,但是当我在我的服务器上测试它时,它不会验证表单。当我按下按钮时,它只是加载/刷新整个页面。这是我的完整代码:(它太长了,你可以提出任何问题或者可以阅读它)
page.php
<?php
ob_start();
session_start();
require_once("auth.inc.php");
require_once("../toplevel/content/connect/shongjog.php");
require_once "phpuploader/include_phpuploader.php";
require_once("function.php");
$username = $_SESSION['email'];
$upload_directory = "../users_logo";
$sql = mysql_query("SELECT * FROM users WHERE email = '$username'");
$num = mysql_num_rows($sql);
$res = mysql_fetch_array($sql);
$uname_d = inputvalid($res['username']);
$email_d = inputvalid($res['email']);
$phone_d = inputvalid($res['phone']);
$address_d = inputvalid($res['address']);
$fb_d = inputvalid($res['fb']);
$tw_d = inputvalid($res['tw']);
$go_d = inputvalid($res['go']);
$logo_d = inputvalid($res['image']);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo "$username - Profile"; ?></title>
<link href="users_css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../toplevel/content/ckeditor/ckeditor.js"></script>
<script src="../toplevel/content/sample.js" type="text/javascript"></script>
<link href="../toplevel/content/sample.css" rel="stylesheet" type="text/css" />
<script>
function doStart()
{
var page_name = document.page.page_name.value;
var page_loc = document.page.page_location.value;
<?php
$page_limit = mysql_query("SELECT menu_name FROM cms WHERE username = '$username' AND cms_location = 1 ");
$num_page_limite = mysql_num_rows($page_limit);
$page_limit = mysql_query("SELECT menu_name FROM cms WHERE username = '$username' AND cms_location = 2 ");
$num_page_limite_2 = mysql_num_rows($page_limit);
?>
var num = <?php echo $num_page_limite; ?>
var num2 = <?php echo $num_page_limite_2; ?>
var page_content = CKEDITOR.instances['editor_kama'].getData();
var pagele = document.page.editor_kama.length;
var uploadobj = document.getElementById('myuploader');
if(page_name == null || page_name == "")
{
alert("page name require");
document.page.page_name.focus() ;
return false;
}
else if(page_name.length > 15 )
{
alert("page name is too long");
document.page.page_name.focus() ;
return false;
}
if(page_loc == null || page_loc == "")
{
alert("Select page location");
document.page.page_location.focus() ;
return false;
}
else if(num == 5 && page_loc == 1)
{
alert("You already creaed 5 pages for your top menu.");
return false;
}
else if(num2 == 5 && page_loc == 2)
{
alert("You already creaed 5 pages for your bottom menu.");
return false;
}
if(page_content == null || page_content == "")
{
alert("page content require");
return false;
}
if (uploadobj.getqueuecount() > 0)
{
uploadobj.startupload();
}
else
{
alert("Please browse files for upload");
}
}
</script>
</head>
<body>
<div id="wraper">
<div id="container">
<div id="content">
<?php
require_once("header.php");
if($num_page_limite == 5 && $num_page_limite_2 == 5)
{
echo "<p style='color:red;'>Sorry, you already created 5 pages for top menu and bottom menu. you can edit your page from <a href='all_pages.php'>here</a>.</p>";
exit();
}
else
{
if($num_page_limite >= 5)
{
echo "<p style='color:red;'>You are already created 5 pages for your top menu. We are accepting only 5 top menu for your pages.</p>";
}
if($num_page_limite_2 >= 5)
{
echo "<p style='color:red;'>You are already created 5 pages for your bottom menu. We are accepting only 5 top menu for bottom pages.</p>";
}
}
$num_page_limite_2
?>
<div id="main_content">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left"><h2>Create a new page</h2></td>
<td align="right"><a href="all_pages.php">All pages</a></td>
</tr>
</table>
<?php
if(isset($_POST['Submit']) && $_POST['Submit'] == "Create page")
{
$current_date = date('Y-m-d H:i:s');
//$p_title = inputvalid($_POST['p_title']);
$p_content = strip_tags($_POST['editor_kama']);
$page_name = inputvalid($_POST['page_name']);
$page_location = inputvalid($_POST['page_location']);
//$link = inputvalid($_POST['link']);
$gid = mt_rand(100000, 999999);
$file = $_FILES["file"]["name"];
$type = $_FILES["file"]["type"];
$size = ($_FILES["file"]["size"] / 1024);
$temp = $_FILES["file"]["tmp_name"];
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$page_pic = $gid.".".$extension;
$page_img_directory = "../page_images";
$page_limit = mysql_query("SELECT menu_name FROM cms WHERE username = '$username' AND cms_location = 1");
$num_page_limite = mysql_num_rows($page_limit);
$err = array();
if(isset($p_content) && isset($page_name) && isset($file) && isset($page_location))
{
if(empty($p_content) && empty($page_name) && empty($page_location) )
$err[] = "All field require";
else
{
if($num_page_limite == 1)
$err[] = "Sorry, you already created 5 pages for your top menu";
if(empty($page_name))
$err[] = "Write your page name";
elseif(strlen($page_name) > 15)
$err[] = "Page is too long";
elseif(strlen($page_name) < 2)
$err[] = "Page is too small";
//if(strlen($p_title) > 100)
//$err[] = "Page title is too long";
if(empty($page_location))
$err[] = "Select page location";
if(empty($p_content))
$err[] = "page content require";
elseif(strlen($p_content) < 10 )
$err[] = "page content is too small";
if(!empty($file))
{
if(!in_array($extension, $allowedExts))
$err[] = "Uploaded file must be gif, jpeg, jpg, png format";
elseif($size > 500)
$err[] = "Uploaded file must be within 500kb";
}
}
}
if(!empty($err))
{
echo "<div class='error'>";
foreach($err as $er)
{
echo "<font color=red>$er.</font><br/>";
}
echo "</div>";
echo "<br/>";
}
else
{
$insert2 = mysql_query("insert into cms VALUES('', '$p_content', '', '$page_location', '$username', '', '', '$page_name', '$current_date', '')");
$gid = mysql_insert_id();
if($insert2)
{
echo "<div class=success>";
echo "successfully created a new page.";
echo "</div>";
header("Refresh:3, url=all_pages.php");
}
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data" id="form1" name="page" >
<table width="100%" border="0" cellspacing="10" cellpadding="0" style="float:left; position:relative;">
<tr>
<td>Page name</td>
<td><input type="text" name="page_name" placeholder="page_name" value="<?php if(isset($_POST['page_name'])) echo $_POST['page_name']; ?>" class="tr" /></td>
</tr>
<!--<tr>
<td>Page title</td>
<td><input type="text" name="p_title" placeholder="Page title" value="<?php if(isset($_POST['p_title'])) echo $_POST['p_title']; ?>" class="tr" /></td>
</tr> -->
<tr>
<td>Page Location ?</td>
<td>
<select name="page_location" class="tr">
<option value="">--Select--</option>
<option value="1">Top Menu</option>
<option value="2">Bottom Menu</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Page Content</td>
<td><textarea cols="80" id="editor_kama" name="editor_kama" rows="30" class="textarea"><?php if(isset($_POST['editor_kama'])) echo $_POST['editor_kama'];?></textarea>
<script type="text/javascript">
//<![CDATA[
CKEDITOR.replace( 'editor_kama',
{
skin : 'kama'
});
//]]>
</script>
</td>
</tr>
<tr>
<!--<tr>
<td>Upload image</td>
<td><input type="file" name="file" class="tr"/></td>
</tr>
-->
<td valign="top">Upload image</td>
<td>
<?php
$uploader=new PhpUploader();
$uploader->MaxSizeKB=10240;
$uploader->Name="myuploader";
$uploader->InsertText="Upload your images";
$uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.txt,*.zip,*.rar";
$uploader->MultipleFilesUpload=true;
$uploader->ManualStartUpload=true;
$uploader->Render();
$fileguidlist=@$_POST["myuploader"];
if($fileguidlist)
{
$guidlist=explode("/",$fileguidlist);
echo("<div style='font-family:Fixedsys;'>");
echo("Uploaded ");
echo(count($guidlist));
echo(" files:");
echo("</div>");
echo("<hr/>");
$p_title = inputvalid($_POST['p_title']);
$p_content = strip_tags($_POST['editor_kama']);
$page_name = inputvalid($_POST['page_name']);
$page_location = inputvalid($_POST['page_location']);
$insert2 = mysql_query("insert into cms VALUES('', '$p_content', '$p_title', '$page_location', '$username', '', '', '$page_name',
'$current_date', '')");
$gid = mysql_insert_id();
foreach($guidlist as $fileguid)
{
$mvcfile=$uploader->GetUploadedFile($fileguid);
if($mvcfile)
{
echo("<div style='font-family:Fixedsys;border-bottom:dashed 1px gray;padding:6px;'>");
echo("FileName: ");
echo($mvcfile->FileName);
$file =$mvcfile->FileName;
echo("<br/>FileSize: ");
echo($mvcfile->FileSize." b");
//echo("<br/>FilePath: ");
//echo($mvcfile->FilePath);
echo("</div>");
//Moves the uploaded file to a new location.
$mvcfile->MoveTo("../page_images/");
//Copys the uploaded file to a new location.
//$mvcfile->CopyTo("/uploads");
//Deletes this instance.
//$mvcfile->Delete();
$insert = mysql_query("insert into galary (menuid, username, image, link, type) VALUES('$gid', '$username','$file', '', '3')");
}
}
echo "<div class=success>";
echo "successfully created a new page.";
echo "</div>";
header("Refresh:3, url=all_pages.php");
//////////////// reside uploaded image////////////
$sql2 = mysql_query("SELECT image, menuid FROM galary WHERE username = '$username' AND menuid = '$gid' AND type = '3'");
$num2 = mysql_num_rows($sql2);
if($num2 >= 1 )
{
$page_img_directory_d = "../page_images";
while($res3 = mysql_fetch_array($sql2))
{
$image = inputvalid($res3['image']);
$main_image_link = "../page_images/$image";
@define('DESIRED_IMAGE_WIDTH', 250);
@define('DESIRED_IMAGE_HEIGHT', 250);
require("page_image.php");
imagejpeg( $desired_gdim, "../page_images/$main_image_link" );
}
}
/////////////// resize uploaded image end here ////////////
}
?>
</td>
</tr>
<!-- <tr>
<td>Image link</td>
<td><input type="text" name="link" placeholder="image link" class="tr"/> <span style="color:#030;">Must have http://</span></td>
</tr>
-->
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Create page" class="submit" id="submitbutton" onclick="doStart();return false;"/></td>
</tr>
</table>
</form>
<?php
?>
</div>
</div>
</div>
</div>
<?php require_once("footer.php"); ?>