English 中文(简体)
PHP MySQL 查询提交按钮
原标题:PHP MySQL query submit buttons
  • 时间:2012-05-24 18:43:14
  •  标签:
  • php
  • mysql

我构建了以下查询

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO selection (student_id, id_project, level_of_want) 
VALUES ((SELECT id FROM users WHERE Username = ".$_SESSION[ MM_Username ]." ), %s, %s)",
GetSQLValueString($_POST[ Project_id ], "int"),
GetSQLValueString($_POST[ Want ], "text"));

mysql_select_db($database_projectsite, $projectsite);
$Result1 = mysql_query($insertSQL, $projectsite) or die(mysql_error());
}

学生代号来自表格中比较的会话信息。

id_ project 来自于一个隐藏的字段, 该字段应该包含当前 id, 而级别是_of_want 来自于两个提交按钮。 当选中一个按钮时, 该数值应用到数据库中。 下面是窗体中该数值的外观 。

<input type="submit" name="Want[]" id="Want_0" value="Really Want" />
      <input type="submit" name="Want[]" id="Want_1" value="Partially Want" />
    </p>
    <p>
      <input name="Project_id" type="hidden" id="Project_id" value="<?php echo $row_Test[ Project_id ]; ?>" />
    </p>

然而,当我执行此操作时, 数据库没有应用此信息, 选择按钮时也没有显示错误信息。 是否有人知道什么是错的?

问题回答

我猜是因为"SELECT id"正在返回空结果板

尝试以下内容:

SELECT id FROM users WHERE Username =  ".$_SESSION[ MM_Username ]." 

注意双引号周围的 额外单引号

内森

在您提交时的输入显示为数组

<input type="submit" name="Want[]" id="Want_0" value="Really Want" />
<input type="submit" name="Want[]" id="Want_1" value="Partially Want" />

为了获得价值,应该:

GetSQLValueString($_POST[ Want ][0], "text"));

托木士





相关问题
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 ...

热门标签