我基本上只是尝试更新表中的多个值.最好的方法是什么?这是当前的代码:
$postsPerPage = $_POST['postsPerPage'];
$style = $_POST['style'];
mysql_connect ("localhost", "user", "pass") or die ('Error: ' . mysql_error());
mysql_select_db ("db");
mysql_query("UPDATE settings SET postsPerPage = $postsPerPage WHERE id = '1'") or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
我想要包括的另一个更新是:
mysql_query("UPDATE settings SET style = $style WHERE id = '1'") or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
谢谢!
嘿,所以我想要完成的是一个MySQL查询,它只抓取ID小于我当前行的第一行.所以基本上是下一个按钮.这是我想要修改的内容:
$next = mysql_query("select * from posts where id<'$id'");
Run Code Online (Sandbox Code Playgroud)
那么我该如何更改它以便它只选择小于我的ID值的第一个值(这是我当前页面的id)
谢谢!对于前一个按钮,我也会采用相反的方式.
我只是在做一些测试,我无法弄清楚我是否以正确的方式做这件事.查询将更新行..但affected_rows总是返回0 ..为什么?
<?php
$connection = new mysqli('localhost', 'user', 'pass', 'db');
if (mysqli_connect_errno()) {
printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
$email = $connection->real_escape_string($_GET['email']);
$activation = $connection->real_escape_string($_GET['hash']);
//$query = $connection->query("SELECT email, activationCode, active FROM users WHERE email='".$email."' AND hash='".$activation."' AND active='0'");
$select = $connection->query("UPDATE users SET active = '1' WHERE email='".$email."' AND activationCode='".$activation."' AND active='0'");
printf("Affected rows (UPDATE): %d\n", $select->affected_rows);
$connection->close();
?>
Run Code Online (Sandbox Code Playgroud) 有没有人知道如果键入特定文字区域我怎么能改变特定单词的颜色?例如,如果用户键入'hello my friend',它会动态地将'hello'更改为绿色?花了很多时间在谷歌上,找不到任何相关的东西.谢谢.
我正在尝试创建一个查询数组的函数,然后我将能够调用单独的值.在这里,我想你会理解我想要做的事情.除了我是一个完整的初学者.
class Posts{
var $title;
var $author;
public function querySinglePost($value){
$post = mysql_fetch_array(mysql_query("select * from posts where id=$value"));
$this->title = $post['title'];
$this->author = $post['author'];
}
}
Run Code Online (Sandbox Code Playgroud)
如何将数组值分配给类中的变量,然后在我的普通php脚本/视图中调用它们?谢谢
有没有办法在我的PHP中进行重定向,这是一个if语句.那么..只有重定向,如果这样的条件是真的吗?另外,我可以通过该URL传递变量以获取GET请求吗?
嘿大家.希望我能正确解释这一点.
我有一些URL,我想通过URL重写来整理.例如,我有:
domain.com/index.php?page=1
domain.com/index.php?page=2
domain.com/index.php?page=3
domain.com/index.php?page=4 etc..
Run Code Online (Sandbox Code Playgroud)
我希望在URL中显示为:
domain.com/page/1
domain.com/page/2
domain.com/page/3
domain.com/page/4 etc..
Run Code Online (Sandbox Code Playgroud)
还有一个简单的问题: - 如果重写URL,是否还会执行$ _GET查询?
非常感谢提前.我启用了模块,并且.htaccess已准备就绪.我只需要一些方向.谢谢!
好的,这就是问题所在.我试图在我的预定义查询中插入一个变量.但它不起作用.如果我只给它一个值,查询就有效,但当我在其中插入变量时,它会失败.救命?
$connection = new mysqli('localhost', 'user', 'pass', 'db');
$username = "test";
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($result = $connection->query("INSERT INTO users (username, password, email, firstName, lastName, createDate) VALUES ('".$username."', 'test', 'test', 'test', 'test', 'test')")){
echo "success";
$result->close();
}
else {
echo "error";
}
$connection->close();
?>
Run Code Online (Sandbox Code Playgroud)
如果我用任何值替换$ username,它都有效..我在这里遗漏了什么吗?
php ×7
mysql ×3
mysqli ×2
colors ×1
insert ×1
javascript ×1
mod-rewrite ×1
oop ×1
redirect ×1
replace ×1
sql ×1
sql-update ×1
string ×1
url ×1
variables ×1