我准备好拔掉我的头发了...
这工作得很好:
$link = mysql_connect('localhost', 'prototype_wp_usr', 'password') or die("Error: " . mysql_error());
mysql_select_db('prototype_wp');
$query = "INSERT INTO wp_zsession_capture
(id, session_id, user_login, first_name, last_name, user_email, phone_number, last_conviction)
VALUES (
'NULL',
'". session_id() ."',
'". $_POST['user_login'] ."',
'". $_POST['first_name'] ."',
'". $_POST['last_name'] ."',
'". $_POST['user_email'] ."',
'". $_POST['phone_number'] ."',
'". $_POST['last_conviction'] ."'
)";
mysql_query($query) or die ('Error updating database: ' . mysql_error());
mysql_close($link);
这确实不工作:
$link = mysql_connect('localhost', 'prototype_wp_usr', 'password') or die("Error: " . mysql_error());
mysql_select_db('prototype_wp');
$query = "UPDATE wp_zsession_capture SET removed = 1 WHERE session_id = '$sessionid'";
mysql_query($query) or die ('Error updating database: ' . mysql_error());
mysql_close($link);
这两段代码在一个表单中...如果表单中有错误,则第一个运行 sql 查询来保存当时会话中的所有内容。如果没有错误,并且在发生其他一些事情之后,将运行第二个 sql 查询来更新那些先前保存的条目中的“已删除”状态。
我一直在修改一百万种替代语法,但无法更新这些行。当我在 phpMyAdmin 中执行原始 SQL 时,它工作正常。这毫无逻辑可言……或者也许我只是太累了。
仅供参考:$sessionid = session_id();
-- 更新 --
我真的很感谢大家的关心,但让我解决一些问题:
- 是的,我的表中有一个名为“已删除”的列...你是认真的吗? :P
- 我当然使用 session_start();
- 是的,我正在检查 $sessionid 以确保它被调用。它始终在页面上回显,并且也在我执行的任何
die
语句中。
- 第一个查询负责创建第二个查询应该更新的行......所以数据就在那里。
-
mysql_error()
不会产生任何结果...根本就没有错误。
再次感谢您的关心,但到目前为止,所有建议都已尝试过并再次尝试。
I'm ready to pull my hair out...
This works perfectly:
$link = mysql_connect('localhost', 'prototype_wp_usr', 'password') or die("Error: " . mysql_error());
mysql_select_db('prototype_wp');
$query = "INSERT INTO wp_zsession_capture
(id, session_id, user_login, first_name, last_name, user_email, phone_number, last_conviction)
VALUES (
'NULL',
'". session_id() ."',
'". $_POST['user_login'] ."',
'". $_POST['first_name'] ."',
'". $_POST['last_name'] ."',
'". $_POST['user_email'] ."',
'". $_POST['phone_number'] ."',
'". $_POST['last_conviction'] ."'
)";
mysql_query($query) or die ('Error updating database: ' . mysql_error());
mysql_close($link);
This does NOT work:
$link = mysql_connect('localhost', 'prototype_wp_usr', 'password') or die("Error: " . mysql_error());
mysql_select_db('prototype_wp');
$query = "UPDATE wp_zsession_capture SET removed = 1 WHERE session_id = '$sessionid'";
mysql_query($query) or die ('Error updating database: ' . mysql_error());
mysql_close($link);
These two pieces of code are within a form... if there are errors in the form, the FIRST sql query is run to save whatever is in the session at that point. If there are no errors, and after some other stuff goes on, the SECOND sql query is run to UPDATE the 'removed' status within those previously saved entries.
I have been tinkering with a million alternative syntaxes and I cannot get those rows to UPDATE. When I execute raw SQL within phpMyAdmin, it works fine. There is nothing logical about this... or maybe I'm just so fantastically tired.
FYI: $sessionid = session_id();
-- UPDATE --
I really do appreciate everyone's concern, but let me address some things:
- Yes, there is a column in my table named 'removed' ... are you serious? :P
- I am of course using session_start();
- Yes, I am checking the $sessionid to make sure it is invoked. It's echoed on the page at all times and is also within any
die
statements I execute.
- The FIRST query is responsible for creating the rows that the SECOND query is supposed to be updating... so the data is there.
mysql_error()
does not produce anything ... there's simply no error.
Again, I appreciate your concern, but so far all suggestions have been tried and tried again.
发布评论
评论(5)
使用 mysql_error() 来从数据库获取错误消息,如下所示:
错误可能是多种原因之一,例如用户可能没有 DELETE 权限。如果您不使用
mysql_error()
,则无法知道发生了什么。编辑 session_id 列中的数据看起来很短。检查
session_id
返回的字符串有多长,并检查数据库中的列长度。插入对于列来说太长的数据并不是错误,但它会裁剪数据。Use
mysql_error()
to obtain the error message from the database, like this:The error could be one of many things, like for example maybe the user does not have the DELETE permission. If you don't use
mysql_error()
there's no way to know what happened.Edit The data in your session_id column looks suspiciously short. Check how long the strings returned by
session_id
are and check the column length in the database. Inserting data that is too long for a column is not an error but it does crop the data.您是否尝试过检查...
$sessionid
的值是什么?您可以通过将
die()
更改为...来实现后者。Have you tried checking...
$sessionid
is when the script is invokedYou can do the latter by changing your
die()
to be...不知道为什么第二个查询不执行。如果没有看到数据库表的架构,也没有发布服务器生成的错误消息的内容,那么真的很难为您提供帮助。但与此同时,我强烈建议您花点时间研究一下 SQL 注入。
可能还想确保在使用
session_id();
之前先调用session_start()
No idea why the second query does not execute. Without seeing your database table's schema and without you posting the contents of the server's generated error message, it really is going to be difficult to assist you. In the mean time though, I highly recommend you take a moment to do some research on the dangers of SQL Injection.
Might also want to ensure you call
session_start()
before messing withsession_id();
mysql_error() 返回空白的一个可能原因是同时打开了多个连接。我最近在将脚本传输到较新的服务器/版本的 PHP 时遇到了这个问题。尝试在您的调用中提供连接句柄,如下所示: mysql_error( $link )
这应该可以帮助您找到错误是什么,并且了解这一点将有助于我们回答您的问题。
而且,尽管您表示您并不担心注入攻击 - 您应该始终转义来自用户/可疑来源的所有数据。至少在放入数据库的每个 $_GET、$_POST、$_COOKIE、$_REQUEST 和 $_SERVER 变量周围使用 mysql_real_escape_string() 。我建议您参考小 Bobby Tables 的故事...
( http://xkcd.com/327/ )
One possible reason mysql_error() is returning blank is that more than one connection is open at the same time. I have had this issue recently while transferring scripts onto a newer server/version of PHP. Try providing the connection handle in your call like so: mysql_error( $link )
That should help you find what the error is, and knowing that will help us answer your question.
And, although you stated you weren't concerned about injection attacks - you should ALWAYS ESCAPE ALL DATA that comes from a user/questionable source. At least use mysql_real_escape_string() around EVERY $_GET, $_POST, $_COOKIE, $_REQUEST, and $_SERVER variable you put into the database. I refer you to the story of little Bobby Tables...
( http://xkcd.com/327/ )
取消选中数据库结构中的自动增量框,然后再次选中它以保存自动增量结构,您的问题将得到解决。
时遇到这种错误
我在执行错误
好像发生了这个错误,我忽略了复制
Uncheck your auto increment box into the database structure then check it again to save auto increment structure, your problem will be solved.
I got this kind of error while doing
Error is:
Seems like this error was occur I omitted to copy