AdonaiEchad wrote:
> Am I getting this correctly?
Sorry, I don't have the faintest idea what you're actually
doing.
The following code does what I think you're trying to achieve
(for the
sake of brevity, I have left out the connection and
GetSQLValueString()
definition):
$colname_getStudentNum = "-1";
if (isset($_POST['stNum'])) {
$colname_getStudentNum = $_POST['stNum'];
}
$var2_getStudentNum = "-1";
if (isset($_POST['firstname'])) {
$var2_getStudentNum = $_POST['firstname'];
}
mysql_select_db($database_testConn, $testConn);
$query_getStudentNum = sprintf("SELECT students.stNum FROM
students
WHERE stNum = %s AND students.firstname != %s",
GetSQLValueString($colname_getStudentNum,
"int"),GetSQLValueString($var2_getStudentNum, "text"));
$getStudentNum = mysql_query($query_getStudentNum, $testConn)
or
die(mysql_error());
$row_getStudentNum = mysql_fetch_assoc($getStudentNum);
$totalRows_getStudentNum = mysql_num_rows($getStudentNum);
$colname_getStudent = "-1";
if (isset($_GET['stud_id'])) {
$colname_getStudent = $_GET['stud_id'];
}
mysql_select_db($database_testConn, $testConn);
$query_getStudent = sprintf("SELECT * FROM students WHERE
stud_id = %s",
GetSQLValueString($colname_getStudent, "int"));
$getStudent = mysql_query($query_getStudent, $testConn) or
die(mysql_error());
$row_getStudent = mysql_fetch_assoc($getStudent);
$totalRows_getStudent = mysql_num_rows($getStudent);
if ((isset($_POST["MM_update"])) &&
($_POST["MM_update"] == "form1")) {
if (strlen($_POST['stNum']) != 9 &&
!is_numeric($_POST['stNum'])) {
$error['studentNumber'] = 'The student number must be 9
numbers';
}
if ($totalRows_getStudentNum > 0) {
$error['duplicate'] = 'That number is already taken';
}
if (!$error) {
$updateSQL = sprintf("UPDATE students SET firstname=%s,
stNum=%s
WHERE stud_id=%s",
GetSQLValueString($_POST['firstname'], "text"),
GetSQLValueString($_POST['stNum'], "int"),
GetSQLValueString($_POST['stud_id'], "int"));
mysql_select_db($database_testConn, $testConn);
$Result1 = mysql_query($updateSQL, $testConn) or
die(mysql_error());
$updateGoTo = "list_studs.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
}
--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/