GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Aug-2008, 12:11
oggie oggie is offline
Awaiting Email Confirmation
 
Join Date: Nov 2007
Location: tattershall, UK
Posts: 28
oggie is on a distinguished road

Undefined variable: message view details....


Hi, This is what I am getting when submitting the details.

Notice: Undefined variable: message in /home/ca5iog/public_html/view-student-details.php on line 57

PHP Code:

<?php 
session_start();
//start session
$getType = 'sup';
//set user type and run check login function
//require ('check-login.php');
 
if (isset($_POST['submit'])) {
// Handle the form once it has been submitted
    $message = NULL;
//Validate cohort input
if ($_POST['programmeleader'] == "Select userID") {
    $message .='<br />You did not select a programme leader<br />';
    } 

if ($message == NULL) {
    //Start session and set session variables to pass to next page for inputting to database
    $_SESSION['programmeleader'] = $_POST['userID'];
    
    header ("Location: view-student-details2.php");
    exit();//exits page and redirects to page above
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html" />
<meta name="author" content="Ian Oglesby" />
<title>Project Monitoring System</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
<div id="title">
<h1>Project Management System</h1>
</div>
<div id="nav">
~ <a href="/">Home</a> <br />  
~ <a href="edit-password.php">Edit Password</a> <br />
~ <a href="edit-email.php">Edit Email Address</a> <br />
~ <a href="view-programmeleaders-details.php">Programme Leaders Details</a> <br />  
~ <a href="email-programmeleaders.php">Email Programme Leaders</a> <br />

<br /> 
~ <a href="/" style="clear:none" accesskey="l">Logout <img src="logout.gif" alt="Logout" width="32" height="32" align="middle"/> </a> <br /><br />
</map>
</div>
<div id="mainContent">
    <h2>View Programme Leaders Details</h2>
   <div align="center">
    <br />
    <?php
//display error message if there is one 
if ($message)    {
    echo "<p>$message</p>";  [color="Red"]line 57, this is where it goes wrong any help please, thanks.[/color]
    }
?>
    
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="SelectProgramLeader Form" title="Select Programme Leader Form">
       <?php //connect to database
require_once('mysql-connect.php');
$userID = $_SESSION['userID'];
$query = "SELECT userID FROM programmeleader WHERE userID = '$userID'";
$result = @mysql_query ($query);

if ($result)
{    
$pulldown = '<option>Select Programme Leader</option>';
while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
//put programme leaders into variable
$pulldown .="<option value=\"{$row['UserID']}\">{$row['UserID']}</option>\n";
}
}
?>
        <p>Programme Leader: <label for="programme leader">
          <select name="programme leader" alt="Select Programme Leader">
            <?php //populate list
            echo $pulldown;?> 
          </select></label>
        </p>
        <input type="submit" name="submit" value="submit" alt="Submit Button" />
    </form>
      <br />
</div>
</div>
</div>
</body>
</html>


thanks for the help

Ian
Last edited by LuciWiz : 20-Aug-2008 at 05:30. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 19-Aug-2008, 22:01
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: undefined variable: message view details....


The error as you posted places $message as suspect... not defined? hmmm...well where is that supposed to be done?
I look at the declaration and then trace down to where it is given another value which looks questionable.
So I whip out the cli to test the line:
Code:
$ php -a Interactive mode enabled <?php # ...in your script you have: $message .='<br />You did not select a programme leader<br />'; Notice: Undefined variable: message in /home/hlenderk/php/- on line 4 # I try it like this: $message = '<br />You did not select a programme leader<br />'; #so far so good... now this: echo $message; <br />You did not select a programme leader<br /> # so there's that problem solved, just a typo. <ctrl-d to exit cli> (or ctrl-x in windows?) # another thing... the echo line should be more like this: echo "<p>". $message ."</p>";

The cli is pretty handy. You can also run a script on the command line. 'man php' for info...
One other thing. You can use javascript to verfy user input before a form is submitted: w3schools.com/js/js_form_validation.asp
Last edited by Howard_L : 19-Aug-2008 at 23:10.
  #3  
Old 20-Aug-2008, 03:55
oggie oggie is offline
Awaiting Email Confirmation
 
Join Date: Nov 2007
Location: tattershall, UK
Posts: 28
oggie is on a distinguished road

Re: undefined variable: message view details....


hi Howard,

thanks for your hint. I have loooked over at what you saod and have changed it. But I am still getting

line 57 Notice: Undefined variable: message in /home/ca5iog/public_html/view-student-details.php on line 57

and now line 65 Notice: Undefined index: userID in /home/ca5iog/public_html/view-student-details.php on line 65

I am still having the same trouble with line 57 even after the change and now line 65.... Can you have a look and see where I am going wrong....

Thanks for the help

Ian

here is the code
PHP Code:

<?php 
session_start();
//start session
$getType = 'sup';
//set user type and run check login function
//require ('check-login.php');
 
if (isset($_POST['submit'])) {
// Handle the form once it has been submitted
    $message = NULL;
//Validate cohort input
if ($_POST['programmeleader'] == "Select userID") {
    $message ='<br />You did not select a programme leader<br />';
    } 

if ($message == NULL) {
    //Start session and set session variables to pass to next page for inputting to database
    $_SESSION['programmeleader'] = $_POST['userID'];
    
    header ("Location: view-student-details2.php");
    exit();//exits page and redirects to page above
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html" />
<meta name="author" content="Ian Oglesby" />
<title>Project Monitoring System</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
<div id="title">
<h1>Project Management System</h1>
</div>
<div id="nav">
~ <a href="/">Home</a> <br />  
~ <a href="edit-password.php">Edit Password</a> <br />
~ <a href="edit-email.php">Edit Email Address</a> <br />
~ <a href="view-programmeleaders-details.php">Programme Leaders Details</a> <br />  
~ <a href="email-programmeleaders.php">Email Programme Leaders</a> <br />

<br /> 
~ <a href="/" style="clear:none" accesskey="l">Logout <img src="logout.gif" alt="Logout" width="32" height="32" align="middle"/> </a> <br /><br />
</map>
</div>
<div id="mainContent">
    <h2>View Programme Leaders Details</h2>
   <div align="center">
    <br />
    <?php
//display error message if there is one 
if ($message)    {
    echo "<p>". $message ."</p>"; [color="Red"]line 57[/color]
    }
?>
    
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="SelectProgramLeader Form" title="Select Programme Leader Form">
       <?php //connect to database
require_once('mysql-connect.php');
$programmeleader = $_SESSION['userID']; [color="red"]line 65[/color]
$query = "SELECT userID FROM programmeleader WHERE userID = '$programmeleader'";
$result = @mysql_query ($query);

if ($result)
{    
$pulldown = '<option>Select Programme Leader</option>';
while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
//put programme leaders into variable
$pulldown .="<option value=\"{$row['userID']}\">{$row['userID']}</option>\n";
}
}
?>
        <p>Programme Leader: <label for="programme leader">
          <select name="programme leader" alt="Select Programme Leader">
            <?php //populate list
            echo $pulldown;?> 
          </select></label>
        </p>
        <input type="submit" name="submit" value="submit" alt="Submit Button" />
    </form>
      <br />
</div>
</div>
</div>
</body>
</html>
Last edited by LuciWiz : 20-Aug-2008 at 05:31. Reason: Please insert your Php code between [php] & [/php] tags
  #4  
Old 20-Aug-2008, 03:59
oggie oggie is offline
Awaiting Email Confirmation
 
Join Date: Nov 2007
Location: tattershall, UK
Posts: 28
oggie is on a distinguished road
Question

Re: undefined variable: message view details....


Hi Howard,

You can look at my website at osiris.sunderland.ac.uk/~ca5iog/view-student-details.php

Ian


Quote:
Originally Posted by Howard_L
The error as you posted places $message as suspect... not defined? hmmm...well where is that supposed to be done?
I look at the declaration and then trace down to where it is given another value which looks questionable.
So I whip out the cli to test the line:
Code:
$ php -a Interactive mode enabled <?php # ...in your script you have: $message .='<br />You did not select a programme leader<br />'; Notice: Undefined variable: message in /home/hlenderk/php/- on line 4 # I try it like this: $message = '<br />You did not select a programme leader<br />'; #so far so good... now this: echo $message; <br />You did not select a programme leader<br /> # so there's that problem solved, just a typo. <ctrl-d to exit cli> (or ctrl-x in windows?) # another thing... the echo line should be more like this: echo "<p>". $message ."</p>";

The cli is pretty handy. You can also run a script on the command line. 'man php' for info...
One other thing. You can use javascript to verfy user input before a form is submitted: www.w3schools.com
  #5  
Old 20-Aug-2008, 09:01
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: undefined variable: message view details....


Disclaimer: first I must state that I am new to .php , But I'll try to help.
Ok so the problem occurs at the initial loading of the 'view-student-details.php' :
Notice: Undefined variable: message in /home/ca5iog/public_html/view-student-details.php on line 57

I note that in last post above line 57 is this:
if($message) {
echo "<p>". $message ."</p>"; // *** and this is at line 58

Anyhow, so follow the logic trail of $messsage. Start at the top of the source: view-student-details.php and follow it from there.
PHP Code:

//The first occurance is:
if (isset($_POST['submit'])) {    $message = NULL;    
// the second is:
if ($_POST['programmeleader'] == "Select userID") {
    $message ='<br />You did not select a programme leader<br />';
// and the third is:
if ($message == NULL) { 



I don't think you will have any '_POST' values at the first load,
so both the first and second would not be true so nothing would be assigned to $message,
not even NULL...
You can test whether any of those tests are true by simply placing an echo statement in there.
You could also try to print $message anywhere and compare to what you would 'expect' it to be :
PHP Code:

if ($_POST['programmeleader'] == "Select userID") {
    echo "Dude, I'm Here";
    $message ='<br />You did not select a programme leader<br />';
    //or maybe
    echo "TESTING: ". $message ;... 


Try that and see how far you can get.
btw, I like the simplicity of your page... Nice quick load! ...gotta go....
  #6  
Old 25-Aug-2008, 15:11
freehen's Avatar
freehen freehen is offline
Awaiting Email Confirmation
 
Join Date: Aug 2008
Location: India
Posts: 5
freehen has a little shameless behaviour in the past

Re: undefined variable: message view details....


Quote:
Originally Posted by Howard_L
Disclaimer: first I must state that I am new to .php , But I'll try to help.
Ok so the problem occurs at the initial loading of the 'view-student-details.php' :
Notice: Undefined variable: message in /home/ca5iog/public_html/view-student-details.php on line 57

I note that in last post above line 57 is this:
if($message) {
echo "<p>". $message ."</p>"; // *** and this is at line 58

Anyhow, so follow the logic trail of $messsage. Start at the top of the source: view-student-details.php and follow it from there.
PHP Code:

//The first occurance is:
if (isset($_POST['submit'])) {    $message = NULL;    
// the second is:
if ($_POST['programmeleader'] == "Select userID") {
    $message ='<br />You did not select a programme leader<br />';
// and the third is:
if ($message == NULL) { 



I don't think you will have any '_POST' values at the first load,
so both the first and second would not be true so nothing would be assigned to $message,
not even NULL...
You can test whether any of those tests are true by simply placing an echo statement in there.
You could also try to print $message anywhere and compare to what you would 'expect' it to be :
PHP Code:

if ($_POST['programmeleader'] == "Select userID") {
    echo "Dude, I'm Here";
    $message ='<br />You did not select a programme leader<br />';
    //or maybe
    echo "TESTING: ". $message ;... 


Try that and see how far you can get.
btw, I like the simplicity of your page... Nice quick load! ...gotta go....
Going by the discussion quoted above you can use ISSET() to check if the variable is set.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fl_PNG_Image undefined reference Invincible FLTK Forum 8 22-Aug-2009 14:57
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
gnu.linkonce undefined reference newbie06 C++ Forum 4 13-Mar-2007 10:53
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 04:38
Undefined variable skyloon MySQL / PHP Forum 2 22-Aug-2004 09:58

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:54.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.