简体   繁体   中英

PHP MySQL query submit buttons

I have constructed the following query

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());
}

The student_id comes from the session information that is compared in the table.

The id_project comes from a hidden field that should contain the current id, and the level_of_want comes from the two submit button. When one is selected, that value is applied to the database. Below is how that looks in the form.

<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>

However when i execute this no information is applied to the database, nor is an error message shown when the button is selected. Does anyone have any possible clue to whats wrong?

I'm guessing because "SELECT id" is returning an empty resultset

try the following:

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

Notice the extra single quotes around the double quotes

Nathan,

Saw on your submit input is an array

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

so to getting value should be

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

Tomz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM