我已定义变量$row_id1(例如$row_id1 = 1;)
在mysql中是名为Number的列.
想要选择列号,如果列中存在$row_id,则想要获取(获取,定义)该值.实际上想要检查列号中是否存在$row_id值.
代码有什么问题?
$stmt = $db->prepare("SELECT Number FROM 2_1_journal WHERE Number = :Number1");
$stmt->bindParam(':Number1', $row_id1); //value from $_POST
$stmt->execute();
$Number1 = $stmt->fetchAll(PDO::FETCH_ASSOC); // seems here something is wrong
echo $Number1 .' $Number1
';
在输出中我得到Array $Number1
好像简单(愚蠢)的问题,但搜索一些小时,没有解决方案
更新的代码
这部分与问题无关(仅供参考)
require($_SERVER['DOCUMENT_ROOT'] . "/_additionally_protected/session.class.php");
$session = new session();
// Set to true if using https
$session->start_session('_a', false);
session_regenerate_id();
//require($_SERVER['DOCUMENT_ROOT'].'/_additionally_protected/request_blocker.php'); //slow page load
require($_SERVER['DOCUMENT_ROOT'].'/_measure_time_start.php');
require($_SERVER['DOCUMENT_ROOT'].'/_additionally_protected/db_config.php');
header('Content-type: text/html; charset=utf8');
require($_SERVER['DOCUMENT_ROOT'] . "/only_private/blackhole.php");
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 0);
这与问题有关(这里我从输入中获取值)
if(get_magic_quotes_gpc())
$row_id1 = htmlspecialchars(stripslashes($_POST['row_id1']));
else
$row_id1 = htmlspecialchars($_POST['row_id1']);
echo $row_id1 .' row_id1 from $_POST
';
连接到mysql
try {
$db = new PDO("mysql:host={$dbhost};dbname={$dbname};charset=utf8", $dbuser, $dbpass//, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
//echo "Connected to database"; // check for connection
}
catch(PDOException $ex) {
//echo "An Error occured!"; //user friendly message
//print "Error!: " . $ex->getMessage() . "
";
//some_logging_function($ex->getMessage());
exit;
}
这里我从mysql获取最后一行编号.后者我将数字1传递给html隐藏的输入字段.我的意思是页面加载我得到最后一个数字.如果用户点击按钮,则不执行代码.
//fetch last Number to pass to row_id and entry_id
if( !$_POST['register'] ) {
echo '!$_POST[register]
';
//+++++++++++++ now multiple PDO
// Select table with query
$stmt = $db->query("
SELECT Number FROM 2_1_journal ORDER BY Number DESC LIMIT 1
");
// Set fetching mode
$stmt->setFetchMode(PDO::FETCH_ASSOC);
// Assign $row as your key to access Table fields
foreach ($stmt as $row) :
echo $row['Number'] .' $row[Number] On page load (reload) get number of last row in mysql; to pass to Entry ID and rowid
';
$_SESSION['last_number_from_mysql'] = $row['Number'];
endforeach;
}//if( !$_POST['register'] ) {
会议(上)
这是给我带来麻烦的部分
//从DB获取Number以与行ID(隐藏)进行比较.目的是决定是否需要记录新行或是否更新现有行.代码在$_POST上执行.所以必须定义$row_id(上面定义)
if( $_POST['register'] ) {
如果用户仅单击按钮,则执行代码
echo $row_id1 .' row_id1 before select Number where Number is $row_id1
';
这是检查.我看到row_id1号码;这意味着收到了这个号码.就在下面想要使用它
$stmt = $db->prepare("SELECT Number FROM 2_1_journal WHERE Number = :Number1");
$stmt->bindParam(':Number1', $row_id1);
$stmt->execute();
echo $Number1 = $stmt->fetchColumn() .' $Number1
';
只有在点击按钮2次时才会回显
这是html输入