acadia Posted July 12, 2009 Share Posted July 12, 2009 Hi Everyone, I have a simple form below that that dynamically populates a dropdown from one table in the database and when you press insert record it is supposed to insert the name into another table. It does autopopulate the drop down however it does not insert the data. Can someone take a look for me? <?php require_once('Connections/SBS.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO student 'CaseManager' VALUES (%s)", GetSQLValueString($_POST['CaseManager'], "text")); mysql_select_db($database_SBS, $SBS); $Result1 = mysql_query($insertSQL, $SBS) or die(mysql_error()); $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_SBS, $SBS); $query_student = "SELECT * FROM student ORDER BY FirstName ASC"; $student = mysql_query($query_student, $SBS) or die(mysql_error()); $row_student = mysql_fetch_assoc($student); $totalRows_student = mysql_num_rows($student); mysql_select_db($database_SBS, $SBS); $query_case = "SELECT FirstName, Surname FROM providercontact ORDER BY FirstName ASC"; $case = mysql_query($query_case, $SBS) or die(mysql_error()); $row_case = mysql_fetch_assoc($case); $totalRows_case = mysql_num_rows($case); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">CaseManager:</td> <td><select name="CaseManager"> <?php do { ?> <option value="<?php echo $row_case['FirstName']?>" ><?php echo $row_case['FirstName']?></option> <?php } while ($row_case = mysql_fetch_assoc($case)); ?> </select> </td> </tr> <tr> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> <p> </p> <p> </p> </body> </html> <?php mysql_free_result($student); mysql_free_result($case); ?> Cheers, Acadia Link to comment https://forums.phpfreaks.com/topic/165663-simple-form/ Share on other sites More sharing options...
trq Posted July 12, 2009 Share Posted July 12, 2009 Eww, Dreamweaver. Maybe if you wrote the code yourself you would also be able to debug it. Link to comment https://forums.phpfreaks.com/topic/165663-simple-form/#findComment-873905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.