I am still very new to all of this. I need a bit of help here, but am sorry if this is too simple.
The Code:
//Establish the variables to be entered
$userid = $POST['login'];
$password = $POST['password'];
$passwordconf = $POST['passconf'];
$school = $POST['school'];
$username = $POST['username'];
$useremail = $POST['useremail'];
$usertype = $_POST['yg'];
//Check to make sure that passwords match
If ($password != $passwordconf) {
die ('Passwords do not match');
}
//Create queries
$schoolcheck = sprintf ("SELECT schoolid FROM School WHERE school LIKE '%s'",
mysql_real_escape_string ($school));
$schoolid = mysql_query ($schoolcheck);
$schoolidno = mysql_fetch_array ($schoolid);
$userquery = sprintf ("SELECT userid FROM users WHERE userid LIKE %s",
mysql_real_escape_string ($userid));
$insertyg = sprintf ("INSERT INTO Users (UserID, UserName, UserEMail, UserPWD, SchoolID, UserType) VALUES (%s, %s, %s, %s, %s, 2)",
mysql_real_escape_string ($userid),
mysql_real_escape_string ($username),
mysql_real_escape_string ($useremail),
mysql_real_escape_string ($password),
mysql_real_escape_string ($schoolcheck['schoolid']));
$insertteach = sprintf (("INSERT INTO Users (UserID, UserName, UserEMail, UserPWD, SchoolID, UserType) VALUES (%s, %s, %s, %s, %s, 1)"),
mysql_real_escape_string ($userid),
mysql_real_escape_string ($username),
mysql_real_escape_string ($useremail),
mysql_real_escape_string ($password),
mysql_real_escape_string ($schoolID));
//Check to make sure that the school is registered
If (!$schoolid) {
$message = 'Invalid query at schoolcheck: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $schoolcheck;
die($message);
}
If ($schoolid > 0) {
printf ("The school ID is " . $schoolid);
}
Else {
printf ("No School ID");
}
If ($schoolid < 1) {
die ("School is not registered. Please contact xxxxx for assistance");
printf ('school not registered');
}
Elseif ($usertype == "yes") {
//printf ("youth group");
//printf ($insertyg);
$error = "\n" . $schoolcheck['schoolid'] . "\n";
printf ($error);
$register = mysql_query ($insertyg);
if (!$register) {
$message = 'Invalid query at register: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $insertyg;
die($message);
}
}
The Output:
The school ID is Resource id #2 S Invalid query at register: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Meyer, jmeyer@serviceevaluation.com, sweetroze, S, 2)' at line Whole query: INSERT INTO Users (UserID, UserName, UserEMail, UserPWD, SchoolID, UserType) VALUES (justin, Justin Meyer, jmeyer@serviceevaluation.com, sweetroze, S, 2)
My questions:
A) Why is the school ID "Resource id #2" instead of simply "1" which is the ID assigned in the table?
😎 Why, when I call the schoolID do I get "S"?
C) What is wrong with the insert query (I think I know the answer and it revolves around the "S" that is in place of a number)?