Newb syntax help please.
Posted: Thu Jan 21, 2010 4:26 pm
Hi all,
slightly steep learning curve for me here...
I'm trying to insert students into courses table on my DB.
I'm getting "Notice: Undefined index: coursenum" on line 37 which is causing a real
headache. The variable "coursenum" is passed to the page from a Flash front end (don't let the
Flash thing put you off - it justs "POST"s it like anything else) and it does "arrive" and is used in other parts
of the script sucessfully so I think I just have a syntax error in the "insert" part of my script.
All and and help / advice / clean ups(!) very much appreciated. (code below)
Best wishes
Monty
slightly steep learning curve for me here...
I'm trying to insert students into courses table on my DB.
I'm getting "Notice: Undefined index: coursenum" on line 37 which is causing a real
headache. The variable "coursenum" is passed to the page from a Flash front end (don't let the
Flash thing put you off - it justs "POST"s it like anything else) and it does "arrive" and is used in other parts
of the script sucessfully so I think I just have a syntax error in the "insert" part of my script.
All and and help / advice / clean ups(!) very much appreciated. (code below)
Best wishes
Monty
Code: Select all
<?php
session_start();
include_once "scripts/connect_to_mysql.php";
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];
} else {
include_once "index.php";
exit();
}
$firstname= "";
$tutor_name="";
$coursenum ="";
$tutor_num = "";
$tutor_fk= "";
$tutorFirstname="";
$tutorSecondname= "";
////////////////// IDENTIFY THE USER
$id = mysql_real_escape_string($id);
$id = eregi_replace("`", "", $id);
$sql = mysql_query("SELECT * FROM myMembers WHERE id='$id'");
while($row = mysql_fetch_array($sql)){
$firstname = $row["firstname"];
}
/////////////// IDENTIFY THE COURSE TUTOR
$groovy=$_REQUEST["coursenum"];
$id = mysql_real_escape_string($id);
$id = eregi_replace("`", "", $id);
$sql = mysql_query("SELECT * FROM courses WHERE course_id='$groovy'");
while($row = mysql_fetch_array($sql)){
$tutor_num = $row["tutor_fk"];
}
$sql = mysql_query("SELECT * FROM myMembers WHERE id= '$tutor_num'");
while($row = mysql_fetch_array($sql)){
$tutorFirstname = $row["firstname"];
$tutorSecondname = $row["lastname"];
}
$tutor_name = "$tutorFirstname" . " " . "$tutorSecondname";
?>
<?php
//////////////// INSERT THE STUDENT INTO THE students_to_courses TABLE
if (isset ($_POST['SignUp'])){
$sql = mysql_query("INSERT INTO students_to_courses ('id', 'student_fk', 'course_fk', 'course_completed')
VALUES('', '$id','$groovy', '0')")
or die (mysql_error());
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Courses</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="styles/main.css" rel="stylesheet" type="text/css" />
<link rel="icon" href="http://www.yourwebsite.com/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="http://www.yourwebsite.com/favicon.ico" type="image/x-icon" />
<style type="text/css">
<!--
a {
font-family: Verdana;
font-size: 11px;
}
a:visited {
color: #FF6600;
font-family: Verdana;
font-size: 11px;
}
a:hover {
color: #FF6600;
font-family: Verdana;
font-size: 11px;
}
-->
</style></head>
<body>
<?php include_once "header_template.php"; ?>
<br>
<br>
<table width="72%" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="480" height="326"><div align="center">
</div>
<div align="center"></div>
<div align="left">
<table width="87%" height="235" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="justify">Hi <span class="orangeText"><?php print "$firstname"; ?><br>
</span>Get ready to sign up for <span class="orangeText"><br>
<span class="Big_Orange_Times"><?php print $_REQUEST["courseName"]; ?></span>
<br>
<br>
</span>BLAH BLAH BLURB BLAH BLURB BLAH.....<br>
The tutor for this course is: <?php print'<a href="profile.php?id=' . $tutor_num . '" class="orangeText">' . $tutor_name . ' </a>'; ?> </span></div></td>
</tr>
<tr>
<td height="53"><form name="student_course_insert" method="post" action="mem_course_signup.php">
<div align="left"><br>
I have read the Terms and Conditions
<input name="terms_box" type="checkbox" id="terms_box" value="checkbox">
<br>
Sign Me Up !
<input type="submit" name="SignUp" value="Submit">
<br>
</div>
</form></td>
</tr>
</table>
</div></td>
<td width="475"><div align="center">
<?php include_once "showpics.php"; ?>
</div></td>
</tr>
</table>
<table width="990" align="center" cellpadding="6" cellspacing="24">
<tr>
<td width="378"><div align="center"><span class="style21"><span class="blueText">DB INSERT TEST <br>
</span></span></div></td>
<td width="378"><div align="justify" class="style21"></div></td>
</tr>
</table>
<p><br>
<?php include_once "footer_template.php"; ?>
</p>
</body>
</html>