English 中文(简体)
MySQL 之后没有保留刑期
原标题:MySQL not saving sentence after an
  • 时间:2012-05-25 15:48:16
  •  标签:
  • php
  • mysql
  • sql

这使我陷入困境。 当我试图将某个东西保存到数据库中包含一个代号( ) 的数据库时, 它会一直保存到那时, 在那之后它不会保存。 例如 :

说我想保存这个消息:报告详述了蒂姆·库克在苹果店的变动,

它节省:报告细节Tim Cook

它保存到数据库 罚款,但只有所有之前

我的代码:

if(isset($_POST[ submit ]))
{
global $db, $db_table_prefix;


$origRLTitle = $_POST[ RLTitle ];
$origRLURL = $_POST[ RLURL ];
$origRLUserID = $_POST[ user-id ];

$RLTitle = mysql_real_escape_string($origRLTitle);
$RLURL = mysql_real_escape_string($origRLURL);
$RLUserID = mysql_real_escape_string($origRLUserID);    


if(strlen($RLTitle)>0 && strlen($RLURL)>0 && strlen($RLUserID)>0)
{
mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db("sf") or die(mysql_error());
mysql_query("INSERT  INTO `ReadLater` (Title, URL, User_ID) VALUES ( ".$RLTitle." ,  ".$RLURL." ,  ".$RLUserID." )");
echo "Saved";
}
}

我尝试过我的sql_real_escape_string,但(如果我正确使用)似乎行不通。

次要注意:确保上述形式免受攻击的最佳途径是什么?

也是为了 " 。

问题回答

您需要调用 mysql_ real_ escape_string > () 连接到您的数据库 :

if(isset($_POST[ submit ]))
{
    global $db, $db_table_prefix;


    $origRLTitle = $_POST[ RLTitle ];
    $origRLURL = $_POST[ RLURL ];
    $origRLUserID = $_POST[ user-id ];
    mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
    mysql_select_db("sf") or die(mysql_error());

    $RLTitle = mysql_real_escape_string($origRLTitle);
    $RLURL = mysql_real_escape_string($origRLURL);
    $RLUserID = mysql_real_escape_string($origRLUserID);    


    if(strlen($RLTitle)>0 && strlen($RLURL)>0 && strlen($RLUserID)>0)
    {
        mysql_query("INSERT  INTO `ReadLater` (Title, URL, User_ID) VALUES ( ".$RLTitle." ,  ".$RLURL." ,  ".$RLUserID." )");
        echo "Saved";
    }
}

变动 变动

mysql_query("INSERT  INTO `ReadLater` (Title, URL, User_ID) VALUES ( ".$RLTitle." ,  ".$RLURL." ,  ".$RLUserID." )");

$query = "INSERT  INTO `ReadLater` (Title, URL, User_ID) VALUES ( ".$RLTitle." ,  ".$RLURL." ,  ".$RLUserID." )";
echo $query;
mysql_query($query);

And check out the actual query you are sending, easy 至 spot the problems then :)





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签