Page 1 of 1

Newb syntax help please.

Posted: Thu Jan 21, 2010 4:26 pm
by MiniMonty
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

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&nbsp;<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 ! &nbsp;&nbsp;
                  <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>
 

Re: Newb syntax help please.

Posted: Thu Jan 21, 2010 5:41 pm
by AbraCadaver
If you are getting Notice: Undefined index: coursenum" , then it isn't defined as a POST or GET var regardless of whether you think it is or not.

Code: Select all

print_r($_REQUEST);

Re: Newb syntax help please.

Posted: Thu Jan 21, 2010 6:28 pm
by MiniMonty
AbraCadaver - thanks for the reply.
Still confused I'm afraid...

print_r($_REQUEST);

returns this:

Code: Select all

 
Array ( [coursenum] => 1 [courseName] => Day One Digital [CAKEPHP] => qkdebehth7g5mim42ljk2rf045 [idCookie] => 1 [firstnameCookie] => Tony [emailCookie] => me@email.com [passCookie] => 1742bd3f4b23a93b47baa3c449594ba0 [PHPSESSID] => r3gebs1t5d6s3lklo4u3bml4d7 )
 
So "coursenum" has a value of 1 - which is what I would expect.
I thought I'd taken the value of "coursenum" and declared it's value as a variable "$groovy" on line 37.
I've already successfully used the variable "$groovy" on line 41 to select from a table on the DB and in that instance the value of "coursenum"
(which is somewhere between 1 and 6) was given to SQL as "$groovy" and worked fine.
So... (remember the "Newb" line in my original post) why can't I just go on using $groovy and happily assume it's value will be that imported by "coursenum" as posted from Flash ?

AM I missing something basic and fundamental ?

Or more succinctly - how do I make it work ?? :?

Best wishes
Monty


PS - I once met a bloke in Soho (London) who claimed to be the Texan Ambassador. He had ancient paperwork from ]when it relly WAS a republic. Complete nutter but an interesting bloke !