我有3个文件1)show_createtable.html 2)do_showfielddef.php 3)do_showtble.php
1)第一个文件用于为数据库创建新表,它是一个具有2个输入的表,表名和字段数.这个工作很精细!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<h1>Step 1: Name and Number</h1>
<form method="post" action="do_showfielddef.php" />
<p><strong>Table Name:</strong><br />
<input type="text" name="table_name" size="30" /></p>
<p><strong>Number of fields:</strong><br />
<input type="text" name="num_fields" size="30" /></p>
<p><input type="submit" name="submit" value="go to step2" /></p>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
2)此脚本验证字段并创建另一个表单以输入所有表格行.这也很精致!
<?php
//validate important input
if ((!$_POST[table_name]) || (!$_POST[num_fields])) {
header( "location: show_createtable.html");
exit;
}
//begin creating form for display
$form_block = "
<form action=\"do_createtable.php\" method=\"post\">
<input name=\"table_name\" …
Run Code Online (Sandbox Code Playgroud) 我正在学习php,尝试使用该fopen()
功能。我正在编码的 php 文件在这个目录中/domains/xxxxx.com.au/public_html/phpfile.php
我指定要打开的文件的路径是什么,我正在查看的示例基于 PC 上的服务器,其中这是文件路径$filename = "c:/newfile.txt";
而不是在线服务器。
更新!
这是整个脚本,我的文件位置正确,现在 4 脚本返回“无法创建文件”这与文件文件夹位置的权限有关吗?
<?php
$filename = "/domains/xxxxxxxx.com.au/public_html/newfile.txt";
$newfile = @fopen($filename, "w+") or die ("couldnt create the file");
fclose($newfile);
$msg = "<p>File Created</p>";
?>
<HTML>
<HEAD>
</HEAD>
<BODY>
<? echo "$msg" ?>
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带身份验证的cookie.
此页面一旦进入用户并通过即可运行
<?
if ((!$_POST[username]) || (!$_POST[password])) {
header("Location: show_login.html");
exit;
}
$db_name = "testDB";
$table_name = "auth_users";
$connection = @mysql_connect("localhost", "user", "pass") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE username ='$_POST[username]' AND password = password('$_POST[password]')";
$result = @mysql_query($sql, $connection) or die(mysql_error());
$num = mysql_num_rows($result);
if ($num != 0) {
$cookie_name = "auth";
$cookie_value = "ok";
$cookie_expire = "0";
$cookie_domain = "domain.com.au";
setcookie($cookie_name, $cookis_value, $cookie_expire, "/", $cookie_domain, 0);
$display_block = "
<p><strong>Secret …
Run Code Online (Sandbox Code Playgroud) 我正在研究一本来自php书籍的例子,并且在第8行使用此代码收到错误
<?php
$agent = getenv("HTTP_USER_AGENT");
if (preg_match("/MSIE/i", "$agent"));
{
$result = "You are using Microsoft Internet Explorer";
}
else if (preg_match("/Mozilla/i", "$agent"));
{
$result = "You are using Mozilla firefox";
}
else {$result = "you are using $agent"; }
echo $result;
?>
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个通过html表单上传文件的脚本.当我点击提交没有任何反应.
file:upload_form.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="do_upload.php" method="post" enctype="multipart/form-data"></form>
<p><strong>File to upload</strong></p>
<p><input name="img1" type="file" size="30" /></p>
<p><input name="submit" type="submit" value="Upolad File" /></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
file:do_upload.php
<?php
if ($_FILES[img1] != "" {
@copy($_FILES[img1] [tm_name], "/tmp" .$_FILES[img1][name])
or die("couldnt copy the file");
} else {
die("no file specified");
}
?>
<HTML>
<head>
<title>Successfull File Upload</title>
</head>
<body>
<h1>Success</h1>
<p>You sent: <? echo $_FILES[img1][name]; ?>, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试连接到mysql并收到错误.我把我的服务器IP地址放入并使用端口3306 whihch post应该使用?
<?php
$connection = mysql_connect("serer.ip:port", "user", "pass")
or die(mysql_error());
if ($connection) {$msg = "success";}
?>
<html>
<head>
</head>
<body>
<? echo "$msg"; ?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是它产生的错误:
警告:mysql_connect()[function.mysql-connect]:对/home/admin/domains/domain.com.au/public_html/db_connect.php中的用户'user'@'localhost'(使用密码:YES)拒绝访问第3行拒绝用户'用户'@'localhost'访问(使用密码:YES)
这是我正在学习的书中的验证脚本,为什么要删除引号necassery?例如<option value=\"char\">char</option>
<?php
//validate important input
if ((!$_POST[table_name]) || (!$_POST[num_fields])) {
header( "location: show_createtable.html");
exit;
}
//begin creating form for display
$form_block = "
<form action=\"do_createtable.php\" method=\"post\">
<input name=\"table_name\" type=\"hidden\" value=\"$_POST[table_name]\">
<table cellspacing=\"5\" cellpadding=\"5\">
<tr>
<th>Field Name</th><th>Field Type</th><th>Table Length</th>
</tr>";
//count from 0 until you reach the number fo fields
for ($i = 0; $i <$_POST[num_fields]; $i++) {
$form_block .="
<tr>
<td align=center><input type=\"texr\" name=\"field name[]\"
size=\"30\"></td>
<td align=center>
<select name=\"field_type[]\">
<option value=\"char\">char</option>
<option value=\"date\">date</option>
<option value=\"float\">float</option>
<option value=\"int\">int</option> …
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个cookie,由于我收到错误,这个错误.
警告:setcookie()期望参数3为long,第6行的/home/admin/domains/domain.com.au/public_html/setcookie.php中给出了字符串
<?php
$cookie_name = "test_cookie";
$cookie_value = "test_string";
$cookie_expire = "time()+86400";
$cookie_domain = "localhost";
setcookie($cookie_name, $cookis_value, $cookie_expire, "/", $cookie_domain, 0);
?>
<HTM>
<HEAD>
</HEAD>
<BODY>
<h1>cookie mmmmmmm</h1>
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud) 我尝试通过HTML和PHP制作一个简单的联系表单,但表单似乎没有提交.它保留在HTML页面上,不会发布到php表单.
simple_form.html代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple Feedback Form</title>
</head>
<body>
<form action="send_simpleform.php" method="post">
<p>Your name<br />
<input name="sender_name" type="text" size="30" /></p>
<p>Email<br />
<input name="sender_email" type="text" size="30" /></p>
<p>Message<br />
<textarea name="message" cols="30" rows="5"></textarea></p>
<input name="submit" type="button" value="Send This Form" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
send_simpleform.php代码
<?
if (($_POST[sender_name] == "") || ($_POST[sender_email] == "") || ($_POST[message] == "") {
header("Location: simple_form.php");
exit;
}
$msg = "Email sent …
Run Code Online (Sandbox Code Playgroud) 我的脚本应该在表格中查找联系人并在屏幕上显示然后进行编辑.然而,这不是这种情况.我收到错误Parse错误:语法错误,第50行/home/admin/domains/domain.com.au/public_html/pick_modcontact.php中的意外$ end注意:这是此脚本中的最后一行.
<?
session_start();
if ($_SESSION[valid] != "yes") {
header( "Location: contact_menu.php");
exit;
}
$db_name = "testDB";
$table_name = "my_contacts";
$connection = @mysql_connect("localhost", "user", "pass") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT id, f_name, l_name FROM $table_name ORDER BY f_name";
$result = @mysql_query($sql, $connection) or die(mysql_error());
$num = @mysql_num_rows($result);
if ($num < 1) {
$display_block = "<p><em>Sorry No Results!</em></p>";
} else {
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$f_name = $row['f_name'];
$l_name = $row['l_name']; …
Run Code Online (Sandbox Code Playgroud) php ×10
cookies ×2
html ×2
mysql ×2
syntax-error ×2
file-upload ×1
if-statement ×1
iframe ×1
syntax ×1