SQL problem
Posted: Sun Mar 20, 2005 9:47 am
Hi,
I'm having problems getting an sql query to run. The program is meant to compare the data in a form with an underlying MySQL database to ensure that the data in each row is consistent with the corresponding row in the database. However, the query just doesn't execute.
I've declared the query at the start of the program:
However, everytime I click the button I just get the 'Query did not execute' warning.
Any suggestions would be greatly appreciated!
feyd | Please review how to post code using
I'm having problems getting an sql query to run. The program is meant to compare the data in a form with an underlying MySQL database to ensure that the data in each row is consistent with the corresponding row in the database. However, the query just doesn't execute.
I've declared the query at the start of the program:
Code: Select all
$consistency = ('SELECT a.Module_code, a.Module_title, a.Module_credits, a.New_module,
a.Prereq_for, a.Co-req_for, is.Pass_required FROM all_modules a INNER JOIN is_specific is ON
a.Module_code = is.Module_code WHERE a.Module_code = \'' .
$_POST["code$i"] . '\' and a.Module_title = \'' .
$_POST["title$i"] . '\' and a.Module_credits = \'' .
$_POST["credits$i"] . '\' and a.New_module = \'' .
$_POST["new$i"] . '\' and a.Prereq_for = \'' .
$_POST["pre-requisite$i"] . '\' and a.Co-req_for = \'' .
$_POST["co-requisite$i"] . '\' and is.Pass_required = \'' .
$_POST["pass$i"] . '\' ');
The following loop is then executed to iterate through each row in the form whenever the user clicks the 'Check Modules' button:
// User pressed button
if ( $_POST['action'] == 'Check Modules' ) {
// Connect to MySQL database
$conn = mysql_connect("localhost", "root") or die ( 'Could not connect to the database' );
mysql_select_db("prototype1", $conn) or die( 'Could not locate database on the database server' );
// Verify compulsory modules
for ( $i = 0; $i < $MAXCOMPULSORY; $i++ ) {
if ( ( $_POST["code$i"] != "" ) ) {
// The user entered information in this row
// execute the sql query
$result = mysql_query($consistency, $conn) or die ( 'Query not executed' );
// get the number of rows in the result set
$number_of_rows = mysql_num_rows($result) or die ( 'num_rows function did not run' );
// if the row doesn't exist, create a warning
if ( $number_of_rows == 0 ) {
array_merge($g_aryErrors, array ( 'The following module is not
consistent with the database:' . $_POST["code$i"] ) );
$g_numberErrors++;
}
}
}Any suggestions would be greatly appreciated!
feyd | Please review how to post code using
Code: Select all
andCode: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]