Solved

Checkboxes

Posted on 2011-02-24
97
481 Views
Last Modified: 2012-05-11
Hi
Can anyone share with me simple code which I can transfer to any form where i need checkboxes?  i need to be able to store whichever has been checked in column/s in my sql table.  they need to be sticky too?!? i really need this for a project i am doing!
thanks for your help
ian  
0
Comment
Question by:ian646
  • 51
  • 45
97 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
What does sticky checkboxes mean ?
0
 

Author Comment

by:ian646
Comment Utility
read it somwhere - all my other fields (text, radio) retain what was entered so the user can update. forgive my naivity!  i am completely stuck with checkboxes and the implode function.  may need to hire a php expert!  this is my last throw of the dice..
0
 

Author Comment

by:ian646
Comment Utility
basically, how do i post 3 ticked checkboxes into my sql column/s?
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
So I guess you need to pull the database values for the checkboxes, and if the (example) - for each checkbox
<?php
if($db[cb1] == 1) echo"selected=\"selected\"";
?>

right ?
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
I'd have to know at least your database structure. Can you post it ?
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
My database records which courses and sessions of the week(AM/PM) that a student is studying.  I therefore require checkboxes as a student may study a number of sessions across the week.  the columns for recording sessions are MonAM;MonPM;TuesAM etc...
I can arrange the sql table to have 1 column and use the impact function? or 10 columns holding each AM/PM session.
the rest of the form allows the user to go back in and make amendments and i would like this too with checkboxes.  I just seems compared to text fields etc. checkboxes seem to confuse everyone on the web.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Code done quick. I have created a table with two fields (id, data), data would store the checkbox values in format (example) 00101- where 0 means AM, 1- PM and the index of the number is the wekday - so for the example it would mean that wednesday and friday are PM. The code snippet sends checkboxes to the same page, only to see how it woul be stored in the database. If this suits your needs, we can go further for retrieving the data from the database.

<?php
    $link = mysql_connect("localhost","root","root");
    mysql_select_db("test");
    
    
    if(!empty($_POST)){
        
        $weekdays = array(0,0,0,0,0);
        
        for ($i=0; $i<count($_POST['mygroup']); $i++){ 
        
        $day = substr($_POST['mygroup'][$i],0,1); 
        $val = substr($_POST['mygroup'][$i],1,1); 
        
        $weekdays[$day] = $val;
        
        }
        
        $weekdays = implode("",$weekdays);
        
        echo $weekdays;
    }
?>
<html>
<head></head>
<body>

<form method="post" action="#">
    <input type="checkbox" name="mygroup[]" value="00" />Monday AM<br />
    <input type="checkbox" name="mygroup[]" value="01" />Monday PM<br />
    <input type="checkbox" name="mygroup[]" value="10" />Tuesday AM<br />
    <input type="checkbox" name="mygroup[]" value="11" />Tuesday PM<br />
    <input type="checkbox" name="mygroup[]" value="20" />Wednesday AM<br />
    <input type="checkbox" name="mygroup[]" value="21" />Wednesday PM<br />
    <input type="checkbox" name="mygroup[]" value="30" />Thursday AM<br />
    <input type="checkbox" name="mygroup[]" value="31" />Thursday PM<br />
    <input type="checkbox" name="mygroup[]" value="40" />Friday AM<br />
    <input type="checkbox" name="mygroup[]" value="41" />Friday PM<br />
    
    <input type="submit" value=" send " />
</form>

</body>
</html>

Open in new window

0
 

Author Comment

by:ian646
Comment Utility
Road_roads
thanks alot.  i will have a go at the code tonight and get back to you.  thanks 4 yr help!
0
 

Author Comment

by:ian646
Comment Utility
Roads_Roads
your code bringing up error in syntax.  my fault for not using it properly i reckon.
i have existing code which i  have attached which reads the value and diplays whatever is checked on a receipt page.  my code is bits and bobs from websites and probably needs replacing by yours?
thanks
if(isset($_POST['submit']))   {
   $course1 = $_POST['course1'];
   $n        = count($course1);
   $i        = 0;
   echo "Course1: The timeslots you have selected are \r\n" .
        "<ol>";
   while ($i < $n)
   {
      echo "<li>{$course1[$i]}</li> \r\n";
      $i++;
   }
   echo "</ol>";
  }
  echo 'Additional Information: ' . $additional_info . '<br />';
  }
  }
   else {
  $output_form = true;
  }
 
  if ($output_form) {
  ?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label for="first_name">First name:</label>
    <input type="text" name="first_name" value="<?php echo $first_name; ?>"/><br />
    <label for="last_name">Last name:</label>
    <input type="text" name="last_name" value="<?php echo $last_name; ?>"/><br />
    <label for="address_1">Address 1</label>
    <input type="text" name="address_1" value="<?php echo $address_1; ?>"/><br />
    <label for="address_2">Address 2</label>
    <input type="text" name="address_2" value="<?php echo $address_2; ?>"/><br />
    <label for="postcode">Postcode</label>
    <input type="text" name="postcode" value="<?php echo $postcode; ?>"/><br />    
    <label for="email">Email address</label>
    <input type="text" name="email" value="<?php echo $email; ?>"/><br />
    <label for="phone">Phone</label>
    <input type="text" name="phone" value="<?php echo $phone; ?>"/><br />
    <label for="age">Age</label>
    <input type="text" name="age" value="<?php echo $age; ?>"/><br />
    <label for="ethnicity">Ethnicity</label>
    <input type="text" name="ethnicity" value="<?php echo $ethnicity; ?>"/><br />
    <label for="school">School</label>
    <input type="text" name="school"  value="<?php echo $school; ?>"/><br />
    <label for="additional_support">Additional support</label>
    <input type="radio" name="additional_support" value="yes" "<?php if($additional_support==yes) echo "checked"; ?>"/>Yes
    <input type="radio" name="additional_support" value="no" "<?php if($additional_support==no) echo "checked"; ?>"/>No<br />
   
    <label for="course_1">Course 1</label>
    <input type="text" name="course_1" value="<?php echo $course_1; ?>"/><br />
       
   
    Course1: which days are you studying?
    <input type="checkbox" name="course1[]" value="00" />Monday AM<br />
    <input type="checkbox" name="course1[]" value="01" />Monday PM<br />
    <input type="checkbox" name="course1[]" value="10" />Tuesday AM<br />
    <input type="checkbox" name="course1[]" value="11" />Tuesday PM<br />
    <input type="checkbox" name="course1[]" value="20" />Wednesday AM<br />
    <input type="checkbox" name="course1[]" value="21" />Wednesday PM<br />
    <input type="checkbox" name="course1[]" value="30" />Thursday AM<br />
    <input type="checkbox" name="course1[]" value="31" />Thursday PM<br />
    <input type="checkbox" name="course1[]" value="40" />Friday AM<br />      
    <input type="checkbox" name="course1[]" value="41" />Friday PM<br />

Open in new window

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
A little modifications - I guess the code you posted is not complete ?

<?php

if(isset($_POST)){
    $course1 = $_POST['course1'];
    $n        = count($course1);
    $i        = 0;
    
    echo "Course1: The timeslots you have selected are \r\n"."<ol>";
    while ($i < $n)
    {
      echo "<li>{$course1[$i]}</li> \r\n";
      $i++;
    }
    echo "</ol>";
    }
  
    echo 'Additional Information: ' . $additional_info . '<br />';
  //}
  //}
   //else {
  $output_form = true;
  //}
 
  if ($output_form) {
  ?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label for="first_name">First name:</label>
    <input type="text" name="first_name" value="<?php echo $first_name; ?>"/><br />
    <label for="last_name">Last name:</label>
    <input type="text" name="last_name" value="<?php echo $last_name; ?>"/><br />
    <label for="address_1">Address 1</label>
    <input type="text" name="address_1" value="<?php echo $address_1; ?>"/><br />
    <label for="address_2">Address 2</label>
    <input type="text" name="address_2" value="<?php echo $address_2; ?>"/><br />
    <label for="postcode">Postcode</label>
    <input type="text" name="postcode" value="<?php echo $postcode; ?>"/><br />    
    <label for="email">Email address</label>
    <input type="text" name="email" value="<?php echo $email; ?>"/><br />
    <label for="phone">Phone</label>
    <input type="text" name="phone" value="<?php echo $phone; ?>"/><br />
    <label for="age">Age</label>
    <input type="text" name="age" value="<?php echo $age; ?>"/><br />
    <label for="ethnicity">Ethnicity</label>
    <input type="text" name="ethnicity" value="<?php echo $ethnicity; ?>"/><br />
    <label for="school">School</label>
    <input type="text" name="school"  value="<?php echo $school; ?>"/><br />
    <label for="additional_support">Additional support</label>
    <input type="radio" name="additional_support" value="yes" "<?php if($additional_support==yes) echo "checked"; ?>"/>Yes
    <input type="radio" name="additional_support" value="no" "<?php if($additional_support==no) echo "checked"; ?>"/>No<br />
   
    <label for="course_1">Course 1</label>
    <input type="text" name="course_1" value="<?php echo $course_1; ?>"/><br />
       
   
    Course1: which days are you studying?
    <input type="checkbox" name="course1[]" value="00" />Monday AM<br />
    <input type="checkbox" name="course1[]" value="01" />Monday PM<br />
    <input type="checkbox" name="course1[]" value="10" />Tuesday AM<br />
    <input type="checkbox" name="course1[]" value="11" />Tuesday PM<br />
    <input type="checkbox" name="course1[]" value="20" />Wednesday AM<br />
    <input type="checkbox" name="course1[]" value="21" />Wednesday PM<br />
    <input type="checkbox" name="course1[]" value="30" />Thursday AM<br />
    <input type="checkbox" name="course1[]" value="31" />Thursday PM<br />
    <input type="checkbox" name="course1[]" value="40" />Friday AM<br />      
    <input type="checkbox" name="course1[]" value="41" />Friday PM<br />
    
    <input type="submit"  value="send" />
    
<?php
}
?>

Open in new window

0
 

Author Comment

by:ian646
Comment Utility
Hi
I have uploaded the whole lot..and a screenshot of the output the user gets when he presses submit.  all other code submits to my sql table.  how do i get the checkboxes to?
<?php
  if (isset($_POST['submit'])) {
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $address_1 = $_POST['address_1'];
  $address_2 = $_POST['address_2'];
  $postcode = $_POST['postcode'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $age = $_POST['age'];
  $ethnicity = $_POST['ethnicity'];
  $school = $_POST['school'];
  $additional_support = $_POST['additional_support'];
  $course_1 = $_POST['course_1'];
  $course_2 = $_POST['course_2'];
  $course_3 = $_POST['course_3'];
  $additional_info = $_POST['additional_info'];
  $output_form = false;


    if (empty($first_name)) {
    echo 'You forgot the firstname.<br />';
    $output_form = true;
    }
	
	if (empty($last_name)) {
    echo 'You forgot the last name.<br />';
    $output_form = true;
    }

    if (empty($address_1)) {
    echo 'You forgot line 1 address.<br />';
	
    $output_form = true;
    }
	
	if (empty($address_2)) {
    echo 'You forgot line 2 address.<br />';
    $output_form = true;
    }

    if (empty($postcode)) {
    echo 'You forgot postcode.<br />';
    $output_form = true;
    }
	 
	if (empty($email)) {
    echo 'You forgot email.<br />';
    $output_form = true;
    }
	 
	if (empty($phone)) {
    echo 'You forgot phone.<br />';
    $output_form = true;
    }
	 
	if (empty($age)) {
    echo 'You forgot age.<br />';
    $output_form = true;
    }
	 
	if (empty($ethnicity)) {
    echo 'You forgot ethnicity.<br />';
    $output_form = true;
    }
	
	if (empty($school)) {
    echo 'You forgot school.<br />';
    $output_form = true;
    }

    if (empty($additional_support)) {
    echo 'You forgot additional support.<br />';
    $output_form = true;
    }
	 
	if (empty($course_1)) {
    echo 'You forgot course1.<br />';
    $output_form = true;
    }
	 
	if (empty($additional_info)) {
    echo 'You forgot additional info.<br />';
    $output_form = true;
    }
	 	 
   if ((!empty($first_name)) && !empty($last_name) && !empty($address_1)  && !empty($address_2)  && !empty($postcode) && !empty($email) && !empty($phone) && !empty($age) && !empty($ethnicity) && !empty($school) && !empty($additional_support) && !empty($course_1)  && !empty($additional_info)) {
   $dbc = mysqli_connect('localhost', 'root', 'Liverpool11', 'enrolment')
   or die('Error connecting to MySQL server.');

  $query = "INSERT INTO induction (first_name, last_name, address_1, address_2, " .
  	"postcode, email, phone, age, ethnicity, school, additional_support, " .
    "course_1, course_2, course_3, additional_info) " .
    "VALUES ('$first_name', '$last_name', '$address_1', '$address_2', '$postcode', '$email', " .
	"'$phone', '$age', '$ethnicity', '$school', '$additional_support', '$course_1', '$course_2', '$course_3', '$additional_info')";

  $result = mysqli_query($dbc, $query)
    or die('Error querying database.');

  mysqli_close($dbc);
  
  echo 'Thanks for submitting the form.<br />';
  echo 'Firstname: ' . $first_name . '<br />';
  echo 'Lastname: ' . $last_name . '<br />';
  echo 'Address 1: ' . $address_1 . '<br />';
  echo 'Address 2: ' . $address_2 . '<br />';
  echo 'Postcode: ' . $postcode . '<br />';
  echo 'Email: ' . $email . '<br />';
  echo 'Phone: ' . $phone . '<br />';
  echo 'Age: ' . $age . '<br />';
  echo 'Ethnicity: ' . $ethnicity . '<br />';
  echo 'School: ' . $school . '<br />';
  echo 'Additional Support: ' . $additional_support . '<br />';
  echo 'Course 1: ' . $course_1 . '<br />';
  
  
   if(isset($_POST))   {
   $course1 = $_POST['course1'];
   $n        = count($course1);
   $i        = 0;
   
   echo "Course1: The timeslots you have selected are \r\n" .
        "<ol>";
   while ($i < $n)
   {
      echo "<li>{$course1[$i]}</li> \r\n";
      $i++;
   }
  
   echo "</ol>";
  }
  echo 'Additional Information: ' . $additional_info . '<br />';
  }
  }
   else {
  $output_form = true;
  }
 
  if ($output_form) {
  ?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label for="first_name">First name:</label>
    <input type="text" name="first_name" value="<?php echo $first_name; ?>"/><br />
    <label for="last_name">Last name:</label>
    <input type="text" name="last_name" value="<?php echo $last_name; ?>"/><br />
    <label for="address_1">Address 1</label>
    <input type="text" name="address_1" value="<?php echo $address_1; ?>"/><br />
    <label for="address_2">Address 2</label>
    <input type="text" name="address_2" value="<?php echo $address_2; ?>"/><br />
    <label for="postcode">Postcode</label>
    <input type="text" name="postcode" value="<?php echo $postcode; ?>"/><br />    
    <label for="email">Email address</label>
    <input type="text" name="email" value="<?php echo $email; ?>"/><br />
    <label for="phone">Phone</label>
    <input type="text" name="phone" value="<?php echo $phone; ?>"/><br />
    <label for="age">Age</label>
    <input type="text" name="age" value="<?php echo $age; ?>"/><br />
    <label for="ethnicity">Ethnicity</label>
    <input type="text" name="ethnicity" value="<?php echo $ethnicity; ?>"/><br />
    <label for="school">School</label>
    <input type="text" name="school"  value="<?php echo $school; ?>"/><br />
    <label for="additional_support">Additional support</label>
    <input type="radio" name="additional_support" value="yes" "<?php if($additional_support==yes) echo "checked"; ?>"/>Yes
    <input type="radio" name="additional_support" value="no" "<?php if($additional_support==no) echo "checked"; ?>"/>No<br />
   
    <label for="course_1">Course 1</label>
    <input type="text" name="course_1" value="<?php echo $course_1; ?>"/><br />
       
   
    Course1: which days are you studying?
    <input type="checkbox" name="course1[]" value="00" />Monday AM<br />
    <input type="checkbox" name="course1[]" value="01" />Monday PM<br />
    <input type="checkbox" name="course1[]" value="10" />Tuesday AM<br />
    <input type="checkbox" name="course1[]" value="11" />Tuesday PM<br />
    <input type="checkbox" name="course1[]" value="20" />Wednesday AM<br />
    <input type="checkbox" name="course1[]" value="21" />Wednesday PM<br />
    <input type="checkbox" name="course1[]" value="30" />Thursday AM<br />
    <input type="checkbox" name="course1[]" value="31" />Thursday PM<br />
    <input type="checkbox" name="course1[]" value="40" />Friday AM<br />      
    <input type="checkbox" name="course1[]" value="41" />Friday PM<br />

Open in new window

screenshot.docx
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads
I have your code working and kinda see what you are doing but the codes seem to be the same for every am and pm instance?  if i could get that into my table column/s i would be grateful. thanks Roads_Roads
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Let me analyze this, will get back to you.
0
 

Author Comment

by:ian646
Comment Utility
have just found this code in eHow website. Would i be able to modify this to send my AM/PM data to my sql table? thanks alot:(
 

Add the PHP code to connect the check box to a database. The database will hold the data obtained from the check box. Click on the "Code" button at the bottom of the screen to change to HTML view. Type in the code similar to this:

"<?php

//Add the information to connect to the database

$host="localhost";

$username="username"; //the username for the user you set up in the previous step

$password="password"; //the password you set up in the previous step

$db_name="mydatabase"; //the name of the database you just created

$tbl_name="mytable"; //the name of the table you just created

//Connect to the database

mysql_connect("$host", "$username", "$password") or die("connection failed");

mysql_select_db("$db_name") or die ("can't connect to database");

if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];

if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])

$id = "('" . implode( "','", $checkbox ) . "');" ;

$sql="UPDATE test_mysql SET status = '".(isset($activate)?'Y':'N')."' WHERE id IN $id" ;

$result = mysql_query($sql) or die(mysql_error());

}"



Read more: Tutorial for Dreamweaver Check Box PHP | eHow.co.uk http://www.ehow.co.uk/how_6908964_tutorial-dreamweaver-check-box-php.html#ixzz1F5tTXy6X

Open in new window

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Could you post your database table structure ?
How does that look ? I would have to klnow to what columns and how to insert the data.
0
 

Author Comment

by:ian646
Comment Utility
yes, everything except MAM - FPM work (checkboxes columns).  all the text fields and and the radiobuttons. not sure what the bottom chheckbox columns are doing there?!?  worried i am messing up the work i have done to get to this point!

SQL-Structure.doc
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Easy now. We can get this work.
Now as we know the database we can post the checkboxes (should they be radio buttons for AM/PM ?)
Just give me some time to get the code work right.
0
 

Author Comment

by:ian646
Comment Utility
don't know how to thank you.  easy for you! frustrating as got so far then stuck - i don't know enough yet!
There may be 3 or 4 of these checkbox groups set up as students may choose 1,2,3 or even four courses.  each course may be 1 session per week or many (MonAM. WedPM, FriAM etc).  therefore i originally thought checkboxes were the only way of recording multiple sessions for each course?!
thanks again
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
I was just looking at the database table and wondering - wouldn't it be better if every course had it's own row ? Just the name of the student would duplicate.
So it would be
John Smith | course1 | MAM | FPM ...
John Smith | course2 | THAM | WPM ...

I see you do have fields for the day AMs / PMs, so the checkboxes are ok. But there has to be 2 checkboxes for each day of week in the form, becuse it can be AM / PM OR NONE of these - when we add radio for AM / PM, you cannon unselect it having just two of them.

What are the fields course_2, course_3, checkbox1, checkbox2, checkbox3 ? Change the MAM, MPM, TAM, TPM, etc. fields type to integer as it would be on/off value - no need to have varchar(10).
Let me work on some code.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Try this code:

<?php

  if (!empty($_POST)) {
  
  $output_form = false;
  
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $address_1 = $_POST['address_1'];
  $address_2 = $_POST['address_2'];
  $postcode = $_POST['postcode'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $age = $_POST['age'];
  $ethnicity = $_POST['ethnicity'];
  $school = $_POST['school'];
  $additional_support = $_POST['additional_support'];
  $additional_info = $_POST['additional_info'];  
  $course = $_POST['course'];


    if (empty($first_name)) {echo 'You forgot the firstname.<br />'; $output_form = true;}
	if (empty($last_name)) {echo 'You forgot the last name.<br />'; $output_form = true;}
    if (empty($address_1)) {echo 'You forgot line 1 address.<br />'; $output_form = true;}
	if (empty($address_2)) {echo 'You forgot line 2 address.<br />'; $output_form = true;}
    if (empty($postcode)) {echo 'You forgot postcode.<br />'; $output_form = true;}
    if (empty($email)) {echo 'You forgot email.<br />'; $output_form = true;}
	if (empty($phone)) {echo 'You forgot phone.<br />'; $output_form = true;}
	if (empty($age)) {echo 'You forgot age.<br />'; $output_form = true;}
	if (empty($ethnicity)) {echo 'You forgot ethnicity.<br />'; $output_form = true;}
	if (empty($school)) { echo 'You forgot school.<br />'; $output_form = true;}
    if (empty($additional_support)) { echo 'You forgot additional support.<br />'; $output_form = true;}
	if (empty($course)) {echo 'You forgot course1.<br />'; $output_form = true;}
	if (empty($additional_info)) {echo 'You forgot additional info.<br />'; $output_form = true;}
	
	 	 
   if ((!empty($first_name)) && !empty($last_name) && !empty($address_1)  && !empty($address_2)  && !empty($postcode) && !empty($email) && !empty($phone) && !empty($age) && !empty($ethnicity) && !empty($school) && !empty($additional_support) && !empty($course_1)  && !empty($additional_info)) 
   {
 
          echo 'Thanks for submitting the form.<br />';
          echo 'Firstname: ' . $first_name . '<br />';
          echo 'Lastname: ' . $last_name . '<br />';
          echo 'Address 1: ' . $address_1 . '<br />';
          echo 'Address 2: ' . $address_2 . '<br />';
          echo 'Postcode: ' . $postcode . '<br />';
          echo 'Email: ' . $email . '<br />';
          echo 'Phone: ' . $phone . '<br />';
          echo 'Age: ' . $age . '<br />';
          echo 'Ethnicity: ' . $ethnicity . '<br />';
          echo 'School: ' . $school . '<br />';
          echo 'Additional Support: ' . $additional_support . '<br />';
          echo 'Course: ' . $course . '<br />';
          
          
           $weekdays = $_POST['weekdays'];
           $fieldsquery = "";
           $valuesquery = "";
           
           echo "weekdays: The timeslots you have selected are \r\n"."<ol>";
           foreach($weekdays as $day => $value)
           {
              echo "<li>$value</li><br />";
            
              $day = explode("_",$value);
              $fieldsquery .= ",".$day[0]; 
              $valuesquery .= ",".$day[1];
              
           }
           echo "</ol>";
           echo 'Additional Information: ' . $additional_info . '<br />';
           
           
           // DATABASE
           //$dbc = mysqli_connect('localhost', 'root', 'Liverpool11', 'enrolment')
           // my
           $dbc = mysql_connect('localhost', 'root', 'root') or die('Error connecting to MySQL server.');
           mysql_select_db('test');

           $query = "INSERT INTO induction (first_name, last_name, address_1, address_2, " .
                "postcode, email, phone, age, ethnicity, school, additional_support, " .
                "course, additional_info ".$fieldsquery.") " .
                "VALUES ('$first_name', '$last_name', '$address_1', '$address_2', '$postcode', '$email', " .
                "'$phone', '$age', '$ethnicity', '$school', '$additional_support', '$course', '$additional_info'".$valuesquery.")";

           echo"$query";

           $result = mysql_query($query) or die('Error querying database.');
           mysql_close($dbc);   
    }
   
   
   }
   else {
    $output_form = true;
   }
 
  if ($output_form) {
  ?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label for="first_name">First name:</label>
    <input type="text" name="first_name" value="<?php echo $first_name; ?>"/><br />
    <label for="last_name">Last name:</label>
    <input type="text" name="last_name" value="<?php echo $last_name; ?>"/><br />
    <label for="address_1">Address 1</label>
    <input type="text" name="address_1" value="<?php echo $address_1; ?>"/><br />
    <label for="address_2">Address 2</label>
    <input type="text" name="address_2" value="<?php echo $address_2; ?>"/><br />
    <label for="postcode">Postcode</label>
    <input type="text" name="postcode" value="<?php echo $postcode; ?>"/><br />    
    <label for="email">Email address</label>
    <input type="text" name="email" value="<?php echo $email; ?>"/><br />
    <label for="phone">Phone</label>
    <input type="text" name="phone" value="<?php echo $phone; ?>"/><br />
    <label for="age">Age</label>
    <input type="text" name="age" value="<?php echo $age; ?>"/><br />
    <label for="ethnicity">Ethnicity</label>
    <input type="text" name="ethnicity" value="<?php echo $ethnicity; ?>"/><br />
    <label for="school">School</label>
    <input type="text" name="school"  value="<?php echo $school; ?>"/><br />
    <label for="additional_support">Additional support</label>
    <input type="radio" name="additional_support" value="yes" "<?php if($additional_support==yes) echo "checked"; ?>"/>Yes
    <input type="radio" name="additional_support" value="no" "<?php if($additional_support==no) echo "checked"; ?>"/>No<br />
   
    <label for="course">Course</label>
    <input type="text" name="course" value="<?php echo $course; ?>"/><br />
       
   
    Course1: which days are you studying?<br />
    <input type="checkbox" name="weekdays[]" value="monday_1" />Monday AM | <input type="checkbox" name="weekdays[]" value="monday_2" />Monday PM<br />
    <input type="checkbox" name="weekdays[]" value="tuesday_1" />Tuesday AM | <input type="checkbox" name="weekdays[]" value="tuesday_2" />Tuesday PM<br />
    <input type="checkbox" name="weekdays[]" value="wednesday_1" />Wednesday AM | <input type="checkbox" name="weekdays[]" value="wednesday_2" />Wednesday PM<br />
    <input type="checkbox" name="weekdays[]" value="thursday_1" />Thursday AM | <input type="checkbox" name="weekdays[]" value="thursday_2" />Thursday PM<br />
    <input type="checkbox" name="weekdays[]" value="friday_1" />Friday AM | <input type="checkbox" name="weekdays[]" value="friday_2" />Friday PM<br />


    
    <input type="submit" value="send" />Friday PM<br />
    
    <?php
    }
    ?>

Open in new window


You have to replace a database info for yours initial. And I have used this table structure


CREATE TABLE IF NOT EXISTS `induction` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(20) NOT NULL,
  `last_name` varchar(20) NOT NULL,
  `address_1` varchar(20) NOT NULL,
  `address_2` varchar(20) NOT NULL,
  `postcode` varchar(20) NOT NULL,
  `email` varchar(20) NOT NULL,
  `phone` varchar(20) NOT NULL,
  `age` int(11) NOT NULL,
  `ethnicity` varchar(20) NOT NULL,
  `school` varchar(20) NOT NULL,
  `additional_support` varchar(20) NOT NULL,
  `additional_info` varchar(20) NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `monday` int(11) NOT NULL,
  `tuesday` int(11) NOT NULL,
  `wednesday` int(11) NOT NULL,
  `thursday` int(11) NOT NULL,
  `friday` int(11) NOT NULL,
  `course` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Open in new window


I have created a fields monday, tuesday, etc... for each day of week. As you see the form has two sets of checkboxes for each day - and the values for monday am = monday_1, monday PM = monday_2, so the database field holds a value "1" for am for that day and the value "2" for pm.
0
 

Author Comment

by:ian646
Comment Utility
Hi
thanks for your code - it looks much more concise now.
you are going to hate me but i tried the code and no data displayed in HTML (via the echo commands) once i pressed submit. Also, i set up the table as you said (used your code to create another table called 'induction' in my database 'enrolment') - no fields were updated at all, including my text fields!
i know i am probably not doing something small..

thanks

echo-output.docx
report2.txt
0
 

Author Comment

by:ian646
Comment Utility
Do i put in this part of the code as is?

// DATABASE
           //$dbc = mysqli_connect('localhost', 'root', 'Liverpool11', 'enrolment')
           // my
           $dbc = mysql_connect('localhost', 'root', 'root') or die('Error connecting to MySQL server.');
           mysql_select_db('test');

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
No, you should use your database credentails.
$dbc = mysqli_connect('localhost', 'root', 'Liverpool11', 'enrolment')
0
 

Author Comment

by:ian646
Comment Utility
should no all the empty commands have a '!'  ??
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
You're missing additional_info as well as the query (course_1) should have "course"
Try this and replace with your database credentails

<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <img src="blankface.jpg" width="161" height="350" alt="" style="float:right" />
  <img name="elvislogo" src="elvislogo.gif" width="229" height="32" border="0" alt="Make Me Elvis" />
  <p><strong>Private:</strong> For Ian's use ONLY<br />
  Enrolment Form</p>

<?php


  if (!empty($_POST)) {
  
  $output_form = false;
  
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $address_1 = $_POST['address_1'];
  $address_2 = $_POST['address_2'];
  $postcode = $_POST['postcode'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $age = $_POST['age'];
  $ethnicity = $_POST['ethnicity'];
  $school = $_POST['school'];
  $additional_support = $_POST['additional_support'];
  $additional_info = $_POST['additional_info'];  
  $course = $_POST['course'];


    if (empty($first_name)) {echo 'You forgot the firstname.<br />'; $output_form = true;}
	if (empty($last_name)) {echo 'You forgot the last name.<br />'; $output_form = true;}
    if (empty($address_1)) {echo 'You forgot line 1 address.<br />'; $output_form = true;}
	if (empty($address_2)) {echo 'You forgot line 2 address.<br />'; $output_form = true;}
    if (empty($postcode)) {echo 'You forgot postcode.<br />'; $output_form = true;}
    if (empty($email)) {echo 'You forgot email.<br />'; $output_form = true;}
	if (empty($phone)) {echo 'You forgot phone.<br />'; $output_form = true;}
	if (empty($age)) {echo 'You forgot age.<br />'; $output_form = true;}
	if (empty($ethnicity)) {echo 'You forgot ethnicity.<br />'; $output_form = true;}
	if (empty($school)) { echo 'You forgot school.<br />'; $output_form = true;}
    if (empty($additional_support)) { echo 'You forgot additional support.<br />'; $output_form = true;}
	if (empty($course)) {echo 'You forgot course1.<br />'; $output_form = true;}
	if (empty($additional_info)) {echo 'You forgot additional info.<br />'; $output_form = true;}
	
	 	 
   if ((!empty($first_name)) && !empty($last_name) && !empty($address_1)  && !empty($address_2)  && !empty($postcode) && !empty($email) && !empty($phone) && !empty($age) && !empty($ethnicity) && !empty($school) && !empty($additional_support) && !empty($course)  && !empty($additional_info)) 
   {
 
          echo 'Thanks for submitting the form.<br />';
          echo 'Firstname: ' . $first_name . '<br />';
          echo 'Lastname: ' . $last_name . '<br />';
          echo 'Address 1: ' . $address_1 . '<br />';
          echo 'Address 2: ' . $address_2 . '<br />';
          echo 'Postcode: ' . $postcode . '<br />';
          echo 'Email: ' . $email . '<br />';
          echo 'Phone: ' . $phone . '<br />';
          echo 'Age: ' . $age . '<br />';
          echo 'Ethnicity: ' . $ethnicity . '<br />';
          echo 'School: ' . $school . '<br />';
          echo 'Additional Support: ' . $additional_support . '<br />';
          echo 'Course: ' . $course . '<br />';
          
          
           $weekdays = $_POST['weekdays'];
           $fieldsquery = "";
           $valuesquery = "";
           
           echo "weekdays: The timeslots you have selected are \r\n"."<ol>";
           foreach($weekdays as $day => $value)
           {
              echo "<li>$value</li><br />";
            
              $day = explode("_",$value);
              $fieldsquery .= ",".$day[0]; 
              $valuesquery .= ",".$day[1];
              
           }
           echo "</ol>";
           echo 'Additional Information: ' . $additional_info . '<br />';
           
           
           // DATABASE
           //$dbc = mysqli_connect('localhost', 'root', 'Liverpool11', 'enrolment');
           //my
           $dbc = mysql_connect('localhost', 'root', 'root') or die('Error connecting to MySQL server.');
           mysql_select_db('induction');

           $query = "INSERT INTO induction (first_name, last_name, address_1, address_2, " .
                "postcode, email, phone, age, ethnicity, school, additional_support, " .
                "course, additional_info ".$fieldsquery.") " .
                "VALUES ('$first_name', '$last_name', '$address_1', '$address_2', '$postcode', '$email', " .
                "'$phone', '$age', '$ethnicity', '$school', '$additional_support', '$course', '$additional_info'".$valuesquery.")";

           echo"$query";

           $result = mysql_query($query) or die('Error querying database.');
           mysql_close($dbc);   
    }
   
   
   }
   else {
    $output_form = true;
   }
 
  if ($output_form == true) {
  ?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label for="first_name">First name:</label><input type="text" name="first_name" value="<?php echo $first_name; ?>"/><br />
    <label for="last_name">Last name:</label><input type="text" name="last_name" value="<?php echo $last_name; ?>"/><br />
    <label for="address_1">Address 1</label><input type="text" name="address_1" value="<?php echo $address_1; ?>"/><br />
    <label for="address_2">Address 2</label><input type="text" name="address_2" value="<?php echo $address_2; ?>"/><br />
    <label for="postcode">Postcode</label><input type="text" name="postcode" value="<?php echo $postcode; ?>"/><br />    
    <label for="email">Email address</label><input type="text" name="email" value="<?php echo $email; ?>"/><br />
    <label for="phone">Phone</label><input type="text" name="phone" value="<?php echo $phone; ?>"/><br />
    <label for="age">Age</label><input type="text" name="age" value="<?php echo $age; ?>"/><br />
    <label for="ethnicity">Ethnicity</label><input type="text" name="ethnicity" value="<?php echo $ethnicity; ?>"/><br />
    <label for="school">School</label><input type="text" name="school"  value="<?php echo $school; ?>"/><br />
    <label for="additional_support">Additional support</label><input type="radio" name="additional_support" value="yes" "<?php if($additional_support==yes) echo "checked"; ?>"/>Yes
    <input type="radio" name="additional_support" value="no" "<?php if($additional_support==no) echo "checked"; ?>"/>No<br />
   
    <label for="course">Course</label>
    <input type="text" name="course" value="<?php echo $course; ?>"/><br />
    <label for="additional_info">Additional info</label><input type="text" name="additional_info"  value="<?php echo $additiona_info; ?>"/><br />
       
   
    Course1: which days are you studying?<br />
    <input type="checkbox" name="weekdays[]" value="monday_1" />Monday AM | <input type="checkbox" name="weekdays[]" value="monday_2" />Monday PM<br />
    <input type="checkbox" name="weekdays[]" value="tuesday_1" />Tuesday AM | <input type="checkbox" name="weekdays[]" value="tuesday_2" />Tuesday PM<br />
    <input type="checkbox" name="weekdays[]" value="wednesday_1" />Wednesday AM | <input type="checkbox" name="weekdays[]" value="wednesday_2" />Wednesday PM<br />
    <input type="checkbox" name="weekdays[]" value="thursday_1" />Thursday AM | <input type="checkbox" name="weekdays[]" value="thursday_2" />Thursday PM<br />
    <input type="checkbox" name="weekdays[]" value="friday_1" />Friday AM | <input type="checkbox" name="weekdays[]" value="friday_2" />Friday PM<br />

 <input type="submit" value="send" /><br />
    
    <?php
    }
    ?> 

    
          
       

</body>
</html>

Open in new window

0
 

Author Comment

by:ian646
Comment Utility
Hi
is working better now - but still not recording data in the sql table!?!.  :( I would like the output for the checkboxes in the 'thank you' screen to be printable for learners to take away so needs to be Monday AM, Tueaday PM etc. is that possible? the thank you screen says the following.  [

Thanks for submitting the form.
Firstname: jklj
Lastname: kj
Address 1: klj
Address 2:
Postcode: lkj
Email: kjk
Phone: jk
Age: jk
Ethnicity: jk
School: j
Additional Support: yes
Course: kljk
weekdays: The timeslots you have selected are
1.monday_1


2.monday_2


Additional Information: lkj
INSERT INTO induction (first_name, last_name, address_1, address_2, postcode, email, phone, age, ethnicity, school, additional_support, course, additional_info ,monday,monday) VALUES ('jklj', 'kj', 'klj', 'lkj', 'lkj', 'kjk', 'jk', 'jk', 'jk', 'j', 'yes', 'kljk', 'lkj',1,2)Error querying database.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Can you run this on PHPmyadmin to see what's wrong with this query ?
INSERT INTO induction (first_name, last_name, address_1, address_2, postcode, email, phone, age, ethnicity, school, additional_support, course, additional_info ,monday,monday) VALUES ('jklj', 'kj', 'klj', 'lkj', 'lkj', 'kjk', 'jk', 'jk', 'jk', 'j', 'yes', 'kljk', 'lkj',1,2)

And replace line 102 with
$result = mysql_query($query) or die(mysql_error());
to see what he doesn't like.
0
 

Author Comment

by:ian646
Comment Utility
sorry - getting out of my depth now.  i have php but don't think i have php admin installed!
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Not only for this project but it is good to have this tool.
Just add the line 102 to see why mysql does not like your query. I think you provided age as string value - it is supposed to be an integer.
0
 

Author Comment

by:ian646
Comment Utility
Hi
attached the code as it stands in case my input error. thanks
reader-latest.txt
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Replace lines where you connect to mysql with these ones (you have an additional parameter, which isn't supposed to be there - database), you select database below like this

           $dbc = mysql_connect('localhost', 'root', 'ENTERYOURPASS') or die('Error connecting to MySQL server.');
           mysql_select_db('enrolment');
0
 

Author Comment

by:ian646
Comment Utility
Hi
slightly different error now: -

INSERT INTO induction (first_name, last_name, address_1, address_2, postcode, email, phone, age, ethnicity, school, additional_support, course, additional_info ,monday,monday) VALUES ('jkh', 'kjh', 'kjh', 'kjhkj', 'hkj', 'hkj', 'hkj', 'hkj', 'hjk', 'hjk', 'yes', 'jhjk', 'hjk',1,2)Column 'monday' specified twice
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Replace the <ol> section to this one:

           $weekdays = $_POST['weekdays'];
           $fieldsquery = "";
           $valuesquery = "";
           
           echo "weekdays: The timeslots you have selected are \r\n"."<ol>";
           foreach($weekdays as $day => $value)
           {
              echo "<li>$value</li><br />";
            
              $day = explode("_",$value);
              
                $pos = strpos($fieldsquery,$day[0]);
                if($pos === false) {
                 // string needle NOT found in haystack
                 $fieldsquery .= ",".$day[0]; 
                 $valuesquery .= ",".$day[1];
                }
                else {
                 // string needle found in haystack
                 $valuesquery = substr($valuesquery,0,-1)."3"; //  ",".$day[1];
                }
                              
           }
           echo "</ol>";
           echo 'Additional Information: ' . $additional_info . '<br />';

Open in new window


It is true - one can select both of the checkboxes for one day. So I've changed it to:
when the user selects monday am - database gets 1
when the user selects monday pm - database gets 2
when the user selects monday am AND monday pm - database gets 3
0
 

Author Comment

by:ian646
Comment Utility
hi - get this now! still nothing in sql table

INSERT INTO induction (first_name, last_name, address_1, address_2, postcode, email, phone, age, ethnicity, school, additional_support, course, additional_info ,monday) VALUES ('jkkj', 'lkjkl', 'jk', 'jlk', 'jlk', 'jkl', 'jkl', 'jk', 'ljlk', 'j ', 'yes', 'kljkl', 'jlkj',3)Field 'tuesday' doesn't have a default value
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Run this query on your mysql

ALTER TABLE `induction` CHANGE `monday` `monday` INT( 11 ) NOT NULL DEFAULT '0',
CHANGE `tuesday` `tuesday` INT( 11 ) NOT NULL DEFAULT '0',
CHANGE `wednesday` `wednesday` INT( 11 ) NOT NULL DEFAULT '0',
CHANGE `thursday` `thursday` INT( 11 ) NOT NULL DEFAULT '0',
CHANGE `friday` `friday` INT( 11 ) NOT NULL DEFAULT '0'
0
 

Author Comment

by:ian646
Comment Utility
Hi thanks - did as you asked but follwing error -

INSERT INTO induction (first_name, last_name, address_1, address_2, postcode, email, phone, age, ethnicity, school, additional_support, course, additional_info ,monday) VALUES ('kjkl', 'jlkj', 'lkj', 'k', 'jkl', 'jkl', 'jkl', 'jk', 'jk', 'lj', 'yes', 'klj', 'klj',1)Incorrect integer value: 'jk' for column 'age' at row 1
0
 

Author Comment

by:ian646
Comment Utility
Ha ha - stupid me.  put in a number in age field and it has upated the table!  selected both monAm and MonPM and put a 3 in Monday column.  Ha Ha. Brilliant! Thanks.

thank you form still shows the follwing text  at bottom hoewever

INSERT INTO induction (first_name, last_name, address_1, address_2, postcode, email, phone, age, ethnicity, school, additional_support, course, additional_info ,monday) VALUES ('kjk', 'jklj', 'kj', 'kl', 'jk', 'jk', 'j', '23', 'kj', 'kj', 'yes', 'kjl', 'klj',3)
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Delete
           echo"$query";
0
 

Author Comment

by:ian646
Comment Utility
that's working now.  brilliant.  can i play aroudn with my code and get back to you.  nearly fully functioning. will the code work on new instances, e.g. course2, course3 and course4 (some leanrers have up to have courses in a year)? thanks again
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
I'll wait for your further feedback. :)
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
your genius has meant the project is almost complete! - i have also been working on an interface from which the user can view, update and delete the data in the sql table(the attached doc 'enrolment_interface' shows what i have done). insert and delete records work fine.  BUT..

The display records button shows the data in a tabular table ( the checkbox data outputs as 1's, 2's and 3's) - is there a way for the code to reproduce Monday AM etc for the casual viewer?  No worries if it can't..

ALSO,

the user can select 'Update Records' and choose which record to update.  at the moment, only the text fields will update - is there a way to update the checkboxes in this view?

FINALLY,

is there a script (simiilar to the report display code) to allow the user to choose a record and the 'Thanks for your submission' screen comes up?  this would allow the user to print the information off to give to the student etc (Is it therefore possible that what is submitted to this screen is the regular Monday AM, Tuesday PM text?).

I have attached the code i have been working on..

Attached  -
enrolment_interface (my interace screen)
report_update(the tabular table where the user can choose which record to update)
report_change (brings up a form where the user can change specific fields)
report_change_record (changes the data in the sql table and infoms the user the data has been updated).



enrolment-interface.docx
report-update.txt
report-update-output.docx
report-change.txt
report-change-record.txt
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
This is the PHP part of the display table data

<?php
/* Change next two lines if using online*/
$db="enrolment";
$link = mysql_connect('localhost', 'root', 'Liverpool11', 'enrolment');

if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT * FROM induction" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<br>";

print "<table width=90% border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
    foreach ($get_info as $key => $field){
    
        if($key == 14 && $field == 1) $field = " Monday AM";
        if($key == 14 && $field == 2) $field = " Monday PM";
        if($key == 14 && $field == 3) $field = " Monday AM / Monday PM";
        
        if($key == 15 && $field == 1) $field = " Tuesday AM";
        if($key == 15 && $field == 2) $field = " Tuesday PM";
        if($key == 15 && $field == 3) $field = " Tuesday AM / Tuesday PM";
        
        if($key == 16 && $field == 1) $field = " Wednesday AM";
        if($key == 16 && $field == 2) $field = " Wednesday PM";
        if($key == 16 && $field == 3) $field = " Wednesday AM / Wednesday PM";
        
        if($key == 17 && $field == 1) $field = " Thursday AM";
        if($key == 17 && $field == 2) $field = " Thursday PM";
        if($key == 17 && $field == 3) $field = " Thursday AM / Thursday PM";
        
        if($key == 18 && $field == 1) $field = " Friday AM";
        if($key == 18 && $field == 2) $field = " Friday PM";
        if($key == 18 && $field == 3) $field = " Friday AM / Friday PM";
       
        print "\t<td>$field</td>\n";
    }
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>

Open in new window

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
And this is the while section of update:

while ($i < $num) {
$first_name=mysql_result($result,$i,"first_name");
$last_name=mysql_result($result,$i,"last_name");
$address_1=mysql_result($result,$i,"address_1");
$address_2=mysql_result($result,$i,"address_2");
$postcode=mysql_result($result,$i,"postcode");
$email=mysql_result($result,$i,"email");
$phone=mysql_result($result,$i,"phone");
$age=mysql_result($result,$i,"age");
$ethnicity=mysql_result($result,$i,"ethnicity");
$school=mysql_result($result,$i,"school");
$additional_support=mysql_result($result,$i,"additional_support");
$course=mysql_result($result,$i,"course");
$additional_info=mysql_result($result,$i,"additional_info");

$monday = mysql_result($result,$i,"monday");
$tuesday = mysql_result($result,$i,"tuesday");
$wednesday = mysql_result($result,$i,"wednesday");
$thursday = mysql_result($result,$i,"thursday");
$friday = mysql_result($result,$i,"friday");
?>
<table width="90%" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Edit and Submit</h3>
<form action="report_change_record.php" method="post">
<input type="hidden" name="ud_id" value="<?php echo "$id" ?>">
FirstName:					<input type="text" name="ud_first_name" value="<?php echo "$first_name"?>"><br>
LastName: 					<input type="text" name="ud_last_name" value="<?php echo "$last_name"?>"><br>
Address1: 					<input type="text" name="ud_address_1" value="<?php echo "$address_1"?>"><br>
Address2:					<input type="text" name="ud_address_2" value="<?php echo "$address_2"?>"><br>
Postcode: 					<input type="text" name="ud_postcode" value="<?php echo "$postcode"?>"><br>
Email: 						<input type="text" name="ud_email" value="<?php echo "$email"?>"><br>
Phone:						<input type="text" name="ud_phone" value="<?php echo "$phone"?>"><br>
Age: 						<input type="text" name="ud_age" value="<?php echo "$age"?>"><br>
Ethnicity: 					<input type="text" name="ud_ethnicity" value="<?php echo "$ethnicity"?>"><br>
School:						<input type="text" name="ud_school" value="<?php echo "$school"?>"><br>
Additional Support: yes		<input type="radio" name="ud_additional_support" value="yes" <?php if($additional_support=="yes") echo "checked"; ?>><br>
					no		<input type="radio" name="ud_additional_support" value="no" <?php if($additional_support=="no") echo "checked"; ?>><br>
Course1: 					<input type="text" name="ud_course_1" value="<?php echo "$course_1"?>"><br>
Additional Info: 			<input type="text" name="ud_additional_info" value="<?php echo "$additional_info"?>"><br>

<?php echo"$monday";?>

    <input type="checkbox" name="weekdays[]" value="monday_1" <?php if($monday == 1 || $monday == 3) echo"checked='checked'";?> />Monday AM | 
    <input type="checkbox" name="weekdays[]" value="monday_2" <?php if($monday == 2 || $monday == 3) echo"checked='checked'";?> />Monday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="tuesday_1" <?php if($tuesday == 1 || $tuesday == 3) echo"checked='checked'";?> />Tuesday AM | 
    <input type="checkbox" name="weekdays[]" value="tuesday_2" <?php if($tuesday == 2 || $tuesday == 3) echo"checked='checked'";?> />Tuesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="wednesday_1" <?php if($wednesday == 1 || $wednesday == 3) echo"checked='checked'";?> />Wednesday AM | 
    <input type="checkbox" name="weekdays[]" value="wednesday_2" <?php if($wednesday == 2 || $wednesday == 3) echo"checked='checked'";?> />Wednesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="thursday_1" <?php if($thursday == 1 || $thursday == 3) echo"checked='checked'";?> />Thursday AM | 
    <input type="checkbox" name="weekdays[]" value="thursday_2" <?php if($thursday == 2 || $thursday == 3) echo"checked='checked'";?> />Thursday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="friday_1" <?php if($friday == 1 || $friday == 3) echo"checked='checked'";?> />Friday AM | 
    <input type="checkbox" name="weekdays[]" value="friday_2" <?php if($friday == 2 || $friday == 3) echo"checked='checked'";?> />Friday PM<br />

<input type="Submit" value="Update">
</form>
</td></tr></table>

<?php
++$i;
}

Open in new window

0
 

Author Comment

by:ian646
Comment Utility
thanks again Roads_Roads - will try it out tonight.
0
 

Author Comment

by:ian646
Comment Utility
Hi Reader
The Display code worked a treat; brilliant thanks :)
I pasted your 'update' code into the while section as requested;  unfortunately the update code seems to have no effect on report_change code or report_change_record (report_update allows the user to select the record to amend, report_change diplays the student fields and report_change_record actually amends the record and informs user it has been done).
i have attached the newly updated 'update' code in case I have missed something (probably)
thanks
report-update-Roads.txt
0
 

Author Comment

by:ian646
Comment Utility
Hi
i have attached what the user sees when needing to amend a record.  As it shows, fine with textboxes but no fields to update checkboxes..

report-change-display.docx
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
report_change file has an $id instead of $_POST[id] and that is the method for the form you are submitting, so change the query to
$query=" SELECT * FROM induction WHERE id='$_POST[id]'";
that is 1.
and I'm working on the 2. :P
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
2. Those values for changing should be in report_change:

<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form (change form)</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
$id=$_POST['id'];
$db="test";
$link = mysql_connect('localhost', 'root', 'root', 'test');
if (! $link)
die("Couldn't connect to MySQL");

mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());

$query=" SELECT * FROM induction WHERE id='$_POST[id]'";
echo"$query";
$result=mysql_query($query);
$num=mysql_num_rows($result);

$i=0;
while ($i < $num) {
$first_name=mysql_result($result,$i,"first_name");
$last_name=mysql_result($result,$i,"last_name");
$address_1=mysql_result($result,$i,"address_1");
$address_2=mysql_result($result,$i,"address_2");
$postcode=mysql_result($result,$i,"postcode");
$email=mysql_result($result,$i,"email");
$phone=mysql_result($result,$i,"phone");
$age=mysql_result($result,$i,"age");
$ethnicity=mysql_result($result,$i,"ethnicity");
$school=mysql_result($result,$i,"school");
$additional_support=mysql_result($result,$i,"additional_support");
$course=mysql_result($result,$i,"course");
$additional_info=mysql_result($result,$i,"additional_info");


// THIS ONE
$monday = mysql_result($result,$i,"monday");
$tuesday = mysql_result($result,$i,"tuesday");
$wednesday = mysql_result($result,$i,"wednesday");
$thursday = mysql_result($result,$i,"thursday");
$friday = mysql_result($result,$i,"friday");

?>
<table width="90%" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Edit and Submit</h3>
<form action="report_change_record.php" method="post">
<input type="hidden" name="ud_id" value="<?php echo "$id" ?>">
FirstName:					<input type="text" name="ud_first_name" value="<?php echo "$first_name"?>"><br>
LastName: 					<input type="text" name="ud_last_name" value="<?php echo "$last_name"?>"><br>
Address1: 					<input type="text" name="ud_address_1" value="<?php echo "$address_1"?>"><br>
Address2:					<input type="text" name="ud_address_2" value="<?php echo "$address_2"?>"><br>
Postcode: 					<input type="text" name="ud_postcode" value="<?php echo "$postcode"?>"><br>
Email: 						<input type="text" name="ud_email" value="<?php echo "$email"?>"><br>
Phone:						<input type="text" name="ud_phone" value="<?php echo "$phone"?>"><br>
Age: 						<input type="text" name="ud_age" value="<?php echo "$age"?>"><br>
Ethnicity: 					<input type="text" name="ud_ethnicity" value="<?php echo "$ethnicity"?>"><br>
School:						<input type="text" name="ud_school" value="<?php echo "$school"?>"><br>
Additional Support: yes		<input type="radio" name="ud_additional_support" value="yes" <?php if($additional_support=="yes") echo "checked"; ?>><br>
					no		<input type="radio" name="ud_additional_support" value="no" <?php if($additional_support=="no") echo "checked"; ?>><br>
Course1: 					<input type="text" name="ud_course" value="<?php echo "$course"?>"><br>
Additional Info: 			<input type="text" name="ud_additional_info" value="<?php echo "$additional_info"?>"><br>

// AND THOSE

    <input type="checkbox" name="weekdays[]" value="monday_1" <?php if($monday == 1 || $monday == 3) echo"checked='checked'";?> />Monday AM | 
    <input type="checkbox" name="weekdays[]" value="monday_2" <?php if($monday == 2 || $monday == 3) echo"checked='checked'";?> />Monday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="tuesday_1" <?php if($tuesday == 1 || $tuesday == 3) echo"checked='checked'";?> />Tuesday AM | 
    <input type="checkbox" name="weekdays[]" value="tuesday_2" <?php if($tuesday == 2 || $tuesday == 3) echo"checked='checked'";?> />Tuesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="wednesday_1" <?php if($wednesday == 1 || $wednesday == 3) echo"checked='checked'";?> />Wednesday AM | 
    <input type="checkbox" name="weekdays[]" value="wednesday_2" <?php if($wednesday == 2 || $wednesday == 3) echo"checked='checked'";?> />Wednesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="thursday_1" <?php if($thursday == 1 || $thursday == 3) echo"checked='checked'";?> />Thursday AM | 
    <input type="checkbox" name="weekdays[]" value="thursday_2" <?php if($thursday == 2 || $thursday == 3) echo"checked='checked'";?> />Thursday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="friday_1" <?php if($friday == 1 || $friday == 3) echo"checked='checked'";?> />Friday AM | 
    <input type="checkbox" name="weekdays[]" value="friday_2" <?php if($friday == 2 || $friday == 3) echo"checked='checked'";?> />Friday PM<br />



<input type="Submit" value="Update">
</form>
</td></tr></table>

<?php
++$i;
}
?>
</body>
</html>

Open in new window

0
 

Author Comment

by:ian646
Comment Utility
Hi Roads
The Report.update code appears to be working as normal however when i selct a record i get the following:

SELECT * FROM induction WHERE id=''


i have attached the code i am using in case i have inaccuracies..

thanks
report-changev3.txt
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
$POST[id] should be $_POST[id] (notice the _ )
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
It is looking really good now - it seems to be almost there. but when i go into the report_change screen it doesn't update changes to the checkbox fields (text fields are fine).  Also, for some strange anything in the course field (for that specific record) disappears in the sql table!

this line appears on the report_change screen..

SELECT * FROM induction WHERE id='8'

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Can you post alle the files you have with all the updates ? As we're getting 'almost there' I'm a little lost with the versions.
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
I have attached everything, even the interface code.  the 3 pages whihc relate to updatingf records are report_change, report_change_record and report_update.  Sorry to put you to this trouble - honestly you have been immense!

8007339 = report1.php
8007340 = report_change.php
8007341 - report_change_record.php
8007342 = report_display.php
8007344 = report_update.php
8007345 - report_remove.php
8007346 = report_interface.php
<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<table width="300" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="left" colspan="1" rowspan="1" bgcolor="64b1ff">
<h3>Enrolment Interface</h3>
<form method="POST" action="report1.php">
<input type="submit" value="Insert Record">
</form><br>
<form method="POST" action="report_display.php">
<input type="submit" value="Display Records">
</form><br>
<form method="POST" action="report_update.php">
<input type="submit" value="Update Records">
</form><br>
<form method="POST" action="report_remove.php">
<input type="submit" value="Delete Record">
</form><br>
</td></tr></table>
</body>
</html>

Open in new window

<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form (update form)</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
/* Change next two lines if using online*/
$db="enrolment";
$link = mysql_connect('localhost', 'root', 'Liverpool11', 'enrolment');

if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT * FROM induction" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<br>";

print "<table width=90% border=1>\n";
while ($get_info = mysql_fetch_row($result)){
	while ($i < $num) {
$first_name=mysql_result($result,$i,"first_name");
$last_name=mysql_result($result,$i,"last_name");
$address_1=mysql_result($result,$i,"address_1");
$address_2=mysql_result($result,$i,"address_2");
$postcode=mysql_result($result,$i,"postcode");
$email=mysql_result($result,$i,"email");
$phone=mysql_result($result,$i,"phone");
$age=mysql_result($result,$i,"age");
$ethnicity=mysql_result($result,$i,"ethnicity");
$school=mysql_result($result,$i,"school");
$additional_support=mysql_result($result,$i,"additional_support");
$course=mysql_result($result,$i,"course");
$additional_info=mysql_result($result,$i,"additional_info");

$monday = mysql_result($result,$i,"monday");
$tuesday = mysql_result($result,$i,"tuesday");
$wednesday = mysql_result($result,$i,"wednesday");
$thursday = mysql_result($result,$i,"thursday");
$friday = mysql_result($result,$i,"friday");
?>
<table width="90%" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Edit and Submit</h3>
<form action="report_change_record.php" method="post">
<input type="hidden" name="ud_id" value="<?php echo "$id" ?>">
FirstName:					<input type="text" name="ud_first_name" value="<?php echo "$first_name"?>"><br>
LastName: 					<input type="text" name="ud_last_name" value="<?php echo "$last_name"?>"><br>
Address1: 					<input type="text" name="ud_address_1" value="<?php echo "$address_1"?>"><br>
Address2:					<input type="text" name="ud_address_2" value="<?php echo "$address_2"?>"><br>
Postcode: 					<input type="text" name="ud_postcode" value="<?php echo "$postcode"?>"><br>
Email: 						<input type="text" name="ud_email" value="<?php echo "$email"?>"><br>
Phone:						<input type="text" name="ud_phone" value="<?php echo "$phone"?>"><br>
Age: 						<input type="text" name="ud_age" value="<?php echo "$age"?>"><br>
Ethnicity: 					<input type="text" name="ud_ethnicity" value="<?php echo "$ethnicity"?>"><br>
School:						<input type="text" name="ud_school" value="<?php echo "$school"?>"><br>
Additional Support: yes		<input type="radio" name="ud_additional_support" value="yes" <?php if($additional_support=="yes") echo "checked"; ?>><br>
					no		<input type="radio" name="ud_additional_support" value="no" <?php if($additional_support=="no") echo "checked"; ?>><br>
Course1: 					<input type="text" name="ud_course_1" value="<?php echo "$course_1"?>"><br>
Additional Info: 			<input type="text" name="ud_additional_info" value="<?php echo "$additional_info"?>"><br>

<?php echo"$monday";?>

    <input type="checkbox" name="weekdays[]" value="monday_1" <?php if($monday == 1 || $monday == 3) echo"checked='checked'";?> />Monday AM | 
    <input type="checkbox" name="weekdays[]" value="monday_2" <?php if($monday == 2 || $monday == 3) echo"checked='checked'";?> />Monday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="tuesday_1" <?php if($tuesday == 1 || $tuesday == 3) echo"checked='checked'";?> />Tuesday AM | 
    <input type="checkbox" name="weekdays[]" value="tuesday_2" <?php if($tuesday == 2 || $tuesday == 3) echo"checked='checked'";?> />Tuesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="wednesday_1" <?php if($wednesday == 1 || $wednesday == 3) echo"checked='checked'";?> />Wednesday AM | 
    <input type="checkbox" name="weekdays[]" value="wednesday_2" <?php if($wednesday == 2 || $wednesday == 3) echo"checked='checked'";?> />Wednesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="thursday_1" <?php if($thursday == 1 || $thursday == 3) echo"checked='checked'";?> />Thursday AM | 
    <input type="checkbox" name="weekdays[]" value="thursday_2" <?php if($thursday == 2 || $thursday == 3) echo"checked='checked'";?> />Thursday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="friday_1" <?php if($friday == 1 || $friday == 3) echo"checked='checked'";?> />Friday AM | 
    <input type="checkbox" name="weekdays[]" value="friday_2" <?php if($friday == 2 || $friday == 3) echo"checked='checked'";?> />Friday PM<br />

<input type="Submit" value="Update">
</form>
</td></tr></table>

<?php
++$i;
} 

print "<tr>\n";
foreach ($get_info as $field)
print "\t<td>$field</td>\n";
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>
<br>
<form method="POST" action="report_change.php">
<pre>
Enter Id Number to Edit: <input type="text" name="id" size="5">
<input type="submit" value="Submit"><input type="reset">
</pre>
</form>
</body>
</html>

Open in new window

<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>

<?php
/* REport allows the user to export sql database into .csv */
$host = 'localhost';
$user = 'root';
$pass = 'Liverpool11';
$db = 'enrolment';
$table = 'induction';
$file = 'export';

$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");

$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."; ";
$i++;
}
}
$csv_output .= "\n";

$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}

$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
</body>
</html>

Open in new window

<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
/* Change next two lines if using online*/
$db="enrolment";
$link = mysql_connect('localhost', 'root', 'Liverpool11', 'enrolment');

if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT * FROM induction" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<br>";

print "<table width=90% border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
    foreach ($get_info as $key => $field){
    
        if($key == 14 && $field == 1) $field = " Monday AM";
        if($key == 14 && $field == 2) $field = " Monday PM";
        if($key == 14 && $field == 3) $field = " Monday AM / Monday PM";
        
        if($key == 15 && $field == 1) $field = " Tuesday AM";
        if($key == 15 && $field == 2) $field = " Tuesday PM";
        if($key == 15 && $field == 3) $field = " Tuesday AM / Tuesday PM";
        
        if($key == 16 && $field == 1) $field = " Wednesday AM";
        if($key == 16 && $field == 2) $field = " Wednesday PM";
        if($key == 16 && $field == 3) $field = " Wednesday AM / Wednesday PM";
        
        if($key == 17 && $field == 1) $field = " Thursday AM";
        if($key == 17 && $field == 2) $field = " Thursday PM";
        if($key == 17 && $field == 3) $field = " Thursday AM / Thursday PM";
        
        if($key == 18 && $field == 1) $field = " Friday AM";
        if($key == 18 && $field == 2) $field = " Friday PM";
        if($key == 18 && $field == 3) $field = " Friday AM / Friday PM";
       
        print "\t<td>$field</td>\n";
    }
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
?> 

<br>

<form method="POST" action="report_interface.php">
<input type="submit" value="Dbase Interface">
</form>
</body>

</html>

Open in new window

<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form (change record)</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
$ud_id=$_POST['ud_id'];
$ud_first_name=$_POST['ud_first_name'];
$ud_last_name=$_POST['ud_last_name'];
$ud_address_1=$_POST['ud_address_1'];
$ud_address_2=$_POST['ud_address_2'];
$ud_postcode=$_POST['ud_postcode'];
$ud_email=$_POST['ud_email'];
$ud_phone=$_POST['ud_phone'];
$ud_age=$_POST['ud_age'];
$ud_ethnicity=$_POST['ud_ethnicity'];
$ud_school=$_POST['ud_school'];
$ud_additional_support=$_POST['ud_additional_support'];
$ud_additional_info=$_POST['ud_additional_info'];
$ud_course=$_POST['ud_course'];

$db="enrolment";
$link = mysql_connect('localhost', 'root', 'Liverpool11', 'enrolment');
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
mysql_query(" UPDATE induction SET first_name='$ud_first_name' , last_name='$ud_last_name' , address_1='$ud_address_1' , address_2='$ud_address_2' , postcode='$ud_postcode' , email='$ud_email' , phone='$ud_phone' , age='$ud_age' , ethnicity='$ud_ethnicity' , school='$ud_school' , additional_support='$ud_additional_support' , additional_info='$ud_additional_info' , course='$ud_course' WHERE id='$ud_id'");
echo "Record Updated";
mysql_close($link);
?>


</body>
</html>

Open in new window

<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form (change form)</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
$id=$_POST['id'];
$db="enrolment";
$link = mysql_connect('localhost', 'root', 'Liverpool11', 'enrolment');
if (! $link)
die("Couldn't connect to MySQL");

mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());

$query=" SELECT * FROM induction WHERE id='$_POST[id]'";
echo"$query";
$result=mysql_query($query);
$num=mysql_num_rows($result);

$i=0;
while ($i < $num) {
$first_name=mysql_result($result,$i,"first_name");
$last_name=mysql_result($result,$i,"last_name");
$address_1=mysql_result($result,$i,"address_1");
$address_2=mysql_result($result,$i,"address_2");
$postcode=mysql_result($result,$i,"postcode");
$email=mysql_result($result,$i,"email");
$phone=mysql_result($result,$i,"phone");
$age=mysql_result($result,$i,"age");
$ethnicity=mysql_result($result,$i,"ethnicity");
$school=mysql_result($result,$i,"school");
$additional_support=mysql_result($result,$i,"additional_support");
$course_1=mysql_result($result,$i,"course");
$additional_info=mysql_result($result,$i,"additional_info");
$monday = mysql_result($result,$i,"monday");
$tuesday = mysql_result($result,$i,"tuesday");
$wednesday = mysql_result($result,$i,"wednesday");
$thursday = mysql_result($result,$i,"thursday");
$friday = mysql_result($result,$i,"friday");


?>
<table width="90%" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Edit and Submit</h3>
<form action="report_change_record.php" method="post">
<input type="hidden" name="ud_id" value="<?php echo "$id" ?>">
FirstName:					<input type="text" name="ud_first_name" value="<?php echo "$first_name"?>"><br>
LastName: 					<input type="text" name="ud_last_name" value="<?php echo "$last_name"?>"><br>
Address1: 					<input type="text" name="ud_address_1" value="<?php echo "$address_1"?>"><br>
Address2:					<input type="text" name="ud_address_2" value="<?php echo "$address_2"?>"><br>
Postcode: 					<input type="text" name="ud_postcode" value="<?php echo "$postcode"?>"><br>
Email: 						<input type="text" name="ud_email" value="<?php echo "$email"?>"><br>
Phone:						<input type="text" name="ud_phone" value="<?php echo "$phone"?>"><br>
Age: 						<input type="text" name="ud_age" value="<?php echo "$age"?>"><br>
Ethnicity: 					<input type="text" name="ud_ethnicity" value="<?php echo "$ethnicity"?>"><br>
School:						<input type="text" name="ud_school" value="<?php echo "$school"?>"><br>
Additional Support: yes		<input type="radio" name="ud_additional_support" value="yes" <?php if($additional_support=="yes") echo "checked"; ?>><br>
					no		<input type="radio" name="ud_additional_support" value="no" <?php if($additional_support=="no") echo "checked"; ?>><br>
Course1: 					<input type="text" name="ud_course_1" value="<?php echo "$course_1"?>"><br>
Additional Info: 			<input type="text" name="ud_additional_info" value="<?php echo "$additional_info"?>"><br>

    <input type="checkbox" name="weekdays[]" value="monday_1" <?php if($monday == 1 || $monday == 3) echo"checked='checked'";?> />Monday AM | 
    <input type="checkbox" name="weekdays[]" value="monday_2" <?php if($monday == 2 || $monday == 3) echo"checked='checked'";?> />Monday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="tuesday_1" <?php if($tuesday == 1 || $tuesday == 3) echo"checked='checked'";?> />Tuesday AM | 
    <input type="checkbox" name="weekdays[]" value="tuesday_2" <?php if($tuesday == 2 || $tuesday == 3) echo"checked='checked'";?> />Tuesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="wednesday_1" <?php if($wednesday == 1 || $wednesday == 3) echo"checked='checked'";?> />Wednesday AM | 
    <input type="checkbox" name="weekdays[]" value="wednesday_2" <?php if($wednesday == 2 || $wednesday == 3) echo"checked='checked'";?> />Wednesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="thursday_1" <?php if($thursday == 1 || $thursday == 3) echo"checked='checked'";?> />Thursday AM | 
    <input type="checkbox" name="weekdays[]" value="thursday_2" <?php if($thursday == 2 || $thursday == 3) echo"checked='checked'";?> />Thursday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="friday_1" <?php if($friday == 1 || $friday == 3) echo"checked='checked'";?> />Friday AM | 
    <input type="checkbox" name="weekdays[]" value="friday_2" <?php if($friday == 2 || $friday == 3) echo"checked='checked'";?> />Friday PM<br />

<input type="Submit" value="Update">
</form>
</td></tr></table>

<?php
++$i;
}
?>
</body>
</html>

Open in new window

<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <img src="blankface.jpg" width="161" height="350" alt="" style="float:right" />
  <img name="elvislogo" src="elvislogo.gif" width="229" height="32" border="0" alt="Make Me Elvis" />
  <p><strong>Private:</strong> For Ian's use ONLY<br />
  Enrolment Form</p>

<?php


  if (!empty($_POST)) {
  
  $output_form = false;
  
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $address_1 = $_POST['address_1'];
  $address_2 = $_POST['address_2'];
  $postcode = $_POST['postcode'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $age = $_POST['age'];
  $ethnicity = $_POST['ethnicity'];
  $school = $_POST['school'];
  $additional_support = $_POST['additional_support'];
  $additional_info = $_POST['additional_info'];  
  $course = $_POST['course'];


    if (empty($first_name)) {echo 'You forgot the firstname.<br />'; $output_form = true;}
	if (empty($last_name)) {echo 'You forgot the last name.<br />'; $output_form = true;}
    if (empty($address_1)) {echo 'You forgot line 1 address.<br />'; $output_form = true;}
	if (empty($address_2)) {echo 'You forgot line 2 address.<br />'; $output_form = true;}
    if (empty($postcode)) {echo 'You forgot postcode.<br />'; $output_form = true;}
    if (empty($email)) {echo 'You forgot email.<br />'; $output_form = true;}
	if (empty($phone)) {echo 'You forgot phone.<br />'; $output_form = true;}
	if (empty($age)) {echo 'You forgot age.<br />'; $output_form = true;}
	if (empty($ethnicity)) {echo 'You forgot ethnicity.<br />'; $output_form = true;}
	if (empty($school)) { echo 'You forgot school.<br />'; $output_form = true;}
    if (empty($additional_support)) { echo 'You forgot additional support.<br />'; $output_form = true;}
	if (empty($course)) {echo 'You forgot course1.<br />'; $output_form = true;}
	if (empty($additional_info)) {echo 'You forgot additional info.<br />'; $output_form = true;}
	
	 	 
   if ((!empty($first_name)) && !empty($last_name) && !empty($address_1)  && !empty($address_2)  && !empty($postcode) && !empty($email) && !empty($phone) && !empty($age) && !empty($ethnicity) && !empty($school) && !empty($additional_support) && !empty($course)  && !empty($additional_info)) 
   {
 
          echo 'Thanks for submitting the form.<br />';
          echo 'Firstname: ' . $first_name . '<br />';
          echo 'Lastname: ' . $last_name . '<br />';
          echo 'Address 1: ' . $address_1 . '<br />';
          echo 'Address 2: ' . $address_2 . '<br />';
          echo 'Postcode: ' . $postcode . '<br />';
          echo 'Email: ' . $email . '<br />';
          echo 'Phone: ' . $phone . '<br />';
          echo 'Age: ' . $age . '<br />';
          echo 'Ethnicity: ' . $ethnicity . '<br />';
          echo 'School: ' . $school . '<br />';
          echo 'Additional Support: ' . $additional_support . '<br />';
          echo 'Course: ' . $course . '<br />';
          
          
           $weekdays = $_POST['weekdays'];
           $fieldsquery = "";
           $valuesquery = "";
           
           echo "weekdays: The timeslots you have selected are \r\n"."<ol>";
           foreach($weekdays as $day => $value)
           {
              echo "<li>$value</li><br />";
            
              $day = explode("_",$value);
              
                $pos = strpos($fieldsquery,$day[0]);
                if($pos === false) {
                 // string needle NOT found in haystack
                 $fieldsquery .= ",".$day[0]; 
                 $valuesquery .= ",".$day[1];
                }
                else {
                 // string needle found in haystack
                 $valuesquery = substr($valuesquery,0,-1)."3"; //  ",".$day[1];
                }
                              
           }
           echo "</ol>";
           echo 'Additional Information: ' . $additional_info . '<br />'; 

           
           
           // DATABASE
           //$dbc = mysqli_connect('localhost', 'root', 'Liverpool11', 'enrolment');
           //my
           $dbc = mysql_connect('localhost', 'root', 'Liverpool11') or die('Error connecting to MySQL server.');
           mysql_select_db('enrolment');

           $query = "INSERT INTO induction (first_name, last_name, address_1, address_2, " .
                "postcode, email, phone, age, ethnicity, school, additional_support, " .
                "course, additional_info ".$fieldsquery.") " .
                "VALUES ('$first_name', '$last_name', '$address_1', '$address_2', '$postcode', '$email', " .
                "'$phone', '$age', '$ethnicity', '$school', '$additional_support', '$course', '$additional_info'".$valuesquery.")";

           //echo"$query";

           $result = mysql_query($query) or die(mysql_error());
           mysql_close($dbc);   
    }
   
   
   }
   else {
    $output_form = true;
   }
 
  if ($output_form == true) {
  ?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label for="first_name">First name:</label><input type="text" name="first_name" value="<?php echo $first_name; ?>"/><br />
    <label for="last_name">Last name:</label><input type="text" name="last_name" value="<?php echo $last_name; ?>"/><br />
    <label for="address_1">Address 1</label><input type="text" name="address_1" value="<?php echo $address_1; ?>"/><br />
    <label for="address_2">Address 2</label><input type="text" name="address_2" value="<?php echo $address_2; ?>"/><br />
    <label for="postcode">Postcode</label><input type="text" name="postcode" value="<?php echo $postcode; ?>"/><br />    
    <label for="email">Email address</label><input type="text" name="email" value="<?php echo $email; ?>"/><br />
    <label for="phone">Phone</label><input type="text" name="phone" value="<?php echo $phone; ?>"/><br />
    <label for="age">Age</label><input type="text" name="age" value="<?php echo $age; ?>"/><br />
    <label for="ethnicity">Ethnicity</label><input type="text" name="ethnicity" value="<?php echo $ethnicity; ?>"/><br />
    <label for="school">School</label><input type="text" name="school"  value="<?php echo $school; ?>"/><br />
    <label for="additional_support">Additional support</label><input type="radio" name="additional_support" value="yes" "<?php if($additional_support==yes) echo "checked"; ?>"/>Yes
    <input type="radio" name="additional_support" value="no" "<?php if($additional_support==no) echo "checked"; ?>"/>No<br />
   
    <label for="course">Course</label><input type="text" name="course" value="<?php echo $course; ?>"/><br />
    <label for="additional_info">Additional info</label><input type="text" name="additional_info"  value="<?php echo $additiona_info; ?>"/><br />
       
   
    Course1: which days are you studying?<br />
    <input type="checkbox" name="weekdays[]" value="monday_1" />Monday AM | <input type="checkbox" name="weekdays[]" value="monday_2" />Monday PM<br />
    <input type="checkbox" name="weekdays[]" value="tuesday_1" />Tuesday AM | <input type="checkbox" name="weekdays[]" value="tuesday_2" />Tuesday PM<br />
    <input type="checkbox" name="weekdays[]" value="wednesday_1" />Wednesday AM | <input type="checkbox" name="weekdays[]" value="wednesday_2" />Wednesday PM<br />
    <input type="checkbox" name="weekdays[]" value="thursday_1" />Thursday AM | <input type="checkbox" name="weekdays[]" value="thursday_2" />Thursday PM<br />
    <input type="checkbox" name="weekdays[]" value="friday_1" />Friday AM | <input type="checkbox" name="weekdays[]" value="friday_2" />Friday PM<br />

 <input type="submit" value="send" /><br />
    
    <?php
    }
    ?> 
</body>
</html>

Open in new window

0
 

Author Comment

by:ian646
Comment Utility
Reader_Reader
The above output has come up upside down.  Report1 is the bottom code and the interface code is at the top :)
 
One last big favour? is it possible for the user to go into report display screen, choose a record and consequently pull up the learners details from the 'thank you for submitting the form' screen?  this would allow the user to print off a students profile including the courses/timeslots they have chosen...
thanks again
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Yes, ok but first: what about the update record ?
Where is the "select record" and update gone from display_record ? By pulling the user data you mean to display the same data from the database, right ?
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads

Yes, ii think so.  it was working fine with just the text boxes.  

muy understanding is there are 3 pages of code which drive the update procedure: report_update , report_change and  report_change_record.

the user goes into report_update screen and types the index number of the record he wishes to change.  the report_change screen appears with the fields prepopulated with the individuals data; the user makes the necessary changes and clicks 'update'. The report_change_record screen inserts the new data back into the dbase and tells the user the database has been successfully updated.

Has this clarified things?  Let me know :)  thanks Roads_Roads
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Yes this clarified thing BUT the code got into pieces... :P Let me work on it so we can have a little less code. Will post back in a sec (or two).
0
 

Author Comment

by:ian646
Comment Utility
thanks for your help.  I have been working from several books and a book guided me to use this method to update records on a dbase :(
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
I hope you haven't hit a brick wall with the code? :(
i hope to have this app working for us at a charity i work at which runs courses for youngsters and it would be a real help to have something like this running at applications level...
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Yes, I'm working on it, I'll post soon today.
0
 

Author Comment

by:ian646
Comment Utility
Roads_Roads
Thanks - I not trying to hurry you.  I really appreciate your help.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Well, ok, this is the report_change_record.php
<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form (change record)</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
$ud_id=$_POST['ud_id'];
$ud_first_name=$_POST['ud_first_name'];
$ud_last_name=$_POST['ud_last_name'];
$ud_address_1=$_POST['ud_address_1'];
$ud_address_2=$_POST['ud_address_2'];
$ud_postcode=$_POST['ud_postcode'];
$ud_email=$_POST['ud_email'];
$ud_phone=$_POST['ud_phone'];
$ud_age=$_POST['ud_age'];
$ud_ethnicity=$_POST['ud_ethnicity'];
$ud_school=$_POST['ud_school'];
$ud_additional_support=$_POST['ud_additional_support'];
$ud_additional_info=$_POST['ud_additional_info'];
$ud_course=$_POST['ud_course'];

           $weekdays = $_POST['weekdays'];
           $fieldsquery = "";
           
           foreach($weekdays as $day => $value)
           {
           
              $day = explode("_",$value);
              
                $pos = strpos($fieldsquery,$day[0]);
                if($pos === false) {
                 // string needle NOT found in haystack
                 $fieldsquery .= ", ".$day[0]." = '$day[1]'"; 
                }
                else {
                 // string needle found in haystack
                 $fieldsquery = substr($fieldsquery,0,-2)."3"; //  ",".$day[1];
                }
                              
           }

$db="test";
$link = mysql_connect('localhost', 'root', 'root', 'test');
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$q = " UPDATE induction SET first_name='$ud_first_name' , last_name='$ud_last_name' , address_1='$ud_address_1' , address_2='$ud_address_2' , postcode='$ud_postcode' , email='$ud_email' , phone='$ud_phone' , age='$ud_age' , ethnicity='$ud_ethnicity' , school='$ud_school' , additional_support='$ud_additional_support' , additional_info='$ud_additional_info' , course='$ud_course' ".$fieldsquery." WHERE id='$ud_id'";
mysql_query($q);
echo "Record Updated";
mysql_close($link);
?>


</body>
</html>

Open in new window

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
report-display.php connect.php

I have separated the connection string to be easily used in the future, for multiple files.
If I have forgotten any file just tell.
0
 

Author Comment

by:ian646
Comment Utility
Thanks Roads_Roads
I will test the files later today and leet you know. thanks again.
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
I must be testing your patience by now! Sorry.  I have tested out the code - there seems to be some problems.

report_display.php
rather than the filling in the ID number and moving to the edit screen - would it be possible for the user to select an ID and the code output the details of the learner in exactly the fashion of the 'thank you for submitting the form' from the report1.php code?

report_update.php
The screen has the following at the top of the page: SELECT * from induction WHERE id='2'
Also, the code does not update the course field or the timeslots.

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
:D
Could you post the whole package of your scripts as zipped archive ?
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
Attached as requested. the sql dbase is as you specified some time ago -
ian
master2.zip
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Thanks. Just give me a moment. Oh don't worry about my patience - rather my scrolling finger :D
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
First of all - let's get report1.php to show nice submitted info - monday am / pm instead of monday_1 report1.php
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
It seems a little complicated:
when you display (record_display.php) you want to select a record to an update -> should go to report_change.php and not to report_update.php (this one seems to be unnecessary file)
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
I would keep it simple just like in the zipped included archive, take a look:
 test.zip
0
 

Author Comment

by:ian646
Comment Utility
Thanks Roads_Roads

Will check your files later today  - thanks :)
the 3 page code to update a file was how i was instructed from a php book.  1st page - choose the record to update; 2nd page -  update the learner record; 3rd page update the dbase and confirm to user.  this code may not be too elegant so have no probs if changed!

essentially, i want the user to be able to update existing learner records.  in addition, be able to choose a learner record and have it display in the browser which can then be printed and taken away by the learner for reference.

Ultimately, the final form will take 4 or 5 course details for each student with a drop-down button for the user to choose each course.  The user will also be able to display each of the learner records including all course details, including timeslots in a presentable format.
0
 

Author Comment

by:ian646
Comment Utility
Thanks Roads_Roads  
I like the new interface - much more simple - i will add the export to .csv option in the interface screen as i think it be used a lot by staff.

It seems to be working fine except it is still not updating the checkboxes when i edit them (a number is coming up on the form screen which suggests a syntax error? Also, when i add checkboxes for another 3 courses entries will it become unmanageable?
Also , i would like an option in the edit/remove screen to display an individuals record full screen?
 :)
0
 

Author Comment

by:ian646
Comment Utility
just noticed that the table displaying the data shows one of my records as having 'Monday AM' against the Monday, Tuesday, Wednesday, Thursday columns :)
0
 

Author Comment

by:ian646
Comment Utility
seems the checkboxes work fine if they have all been completed and user changes 1 or more (from e.g. AM to PM) -  but not happy if uncheck a box or boxes and save...
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
1. The edit screen: what number comes out ?
2. You can add as many courses as you like but you have to remember to add weekdays for them
3. I'll take a look at unchecking
0
 

Author Comment

by:ian646
Comment Utility
Hi
In report_display screen, the number 1 or 2 comes up against a chosen record(just to the side of MondayAM checkbox).
The checkboxes seem to record any changes as long as you don't leave an AM or PM checkbox blank.  At least i think that's what happening.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
delete line 72 from report_display
<?php echo"$monday";?>

and 2 files with changes:
 report-change-record.php report-display.php
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Any luck there ?
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
Sorry -been distracted - my bro lives just outside Tokyo but is OK. Phew!

Thanks for the code - it all seems to work fine except the checkboxes cant seem to record a blank entry?!  they update fine as long as i put in either a AM or PM time.  If I leave 1 or both time4s blank, it keeps the existing record.

thanks again
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Report change record has:
$q = " UPDATE induction SET monday = 0, tuesday = 0, wednesday = 0, thursday = 0, friday = 0 WHERE id='$ud_id'";
mysql_query($q) or die(mysql_error());

so the day values are set to 0 prior to setting them to 1,2 or 3 - this should work then...

This is the record change record code again -try replacing it:

<?php
include("connect.php");

$ud_id=$_POST['ud_id'];
$ud_first_name=$_POST['ud_first_name'];
$ud_last_name=$_POST['ud_last_name'];
$ud_address_1=$_POST['ud_address_1'];
$ud_address_2=$_POST['ud_address_2'];
$ud_postcode=$_POST['ud_postcode'];
$ud_email=$_POST['ud_email'];
$ud_phone=$_POST['ud_phone'];
$ud_age=$_POST['ud_age'];
$ud_ethnicity=$_POST['ud_ethnicity'];
$ud_school=$_POST['ud_school'];
$ud_additional_support=$_POST['ud_additional_support'];
$ud_additional_info=$_POST['ud_additional_info'];
$ud_course=$_POST['ud_course'];

$q = " UPDATE induction SET monday = 0, tuesday = 0, wednesday = 0, thursday = 0, friday = 0 WHERE id='$ud_id'";
mysql_query($q) or die(mysql_error());

           $weekdays = $_POST['weekdays'];
           $fieldsquery = "";
           
           foreach($weekdays as $day => $value)
           {
           //echo "$day, $value<br />";
           
              $day = explode("_",$value);
              
                $pos = strpos($fieldsquery,$day[0]);
                if($pos === false) {
                 // string needle NOT found in haystack
                 $fieldsquery .= ", ".$day[0]." = '$day[1]'"; 
                }
                else {
                 // string needle found in haystack
                 $fieldsquery = substr($fieldsquery,0,-2)."3'"; //  ",".$day[1];
                }
                              
           }



if (! $link) die("Couldn't connect to MySQL");
mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());
$q = " UPDATE induction SET first_name='$ud_first_name' , last_name='$ud_last_name' , address_1='$ud_address_1' , address_2='$ud_address_2' , postcode='$ud_postcode' , email='$ud_email' , phone='$ud_phone' , age='$ud_age' , ethnicity='$ud_ethnicity' , school='$ud_school' , additional_support='$ud_additional_support' , additional_info='$ud_additional_info' , course='$ud_course' ".$fieldsquery." WHERE id='$ud_id'";
mysql_query($q) or die(mysql_error());

header("Location: report_display.php");

?>

Open in new window

0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
I think it is working when there is an input recorded for an AM, PM (or both) for each day.  it also  records amendments fine. problems recording when nothing runs on for e.g. a wednesday.  Does it need a 'blank' entry for those days which i want to remain blank?
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
I was too hasty with my reply - it is working!  Can i mess round with it and get back to you if any probs?
Many thanks
0
 

Author Comment

by:ian646
Comment Utility
Hi Roads_Roads
Sorry - it isn't quite working  - seems very tempermental when submitting  - sometimes it works other times not. When it does work it restricts itself to the top line record (attached).  Also, doesn't seem to be auto updating the sql database when pressing the update button (i could be wrong).  i have the dbase up and need to refresh the data and can see it is changing the fields, but refreshed or not, it doesn't show the blank records in the display screen.
thanks

Checkbox.docx
0
 

Author Comment

by:ian646
Comment Utility
Sorry me again
it does seem the problem is that it updates top line of display screen table  - has problems with any records below that top record. :)
0
 

Author Comment

by:ian646
Comment Utility
yes- if i click enough times i do get some blank fields in display_record table; mostly it ignores any updates whih require a 'empty' day.  strange.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Can you post your full zipped updated version again ? :P
0
 

Author Comment

by:ian646
Comment Utility
Ok- will do - in about 2hrs thanks
0
 

Author Comment

by:ian646
Comment Utility
Hi
Attached as requested
enrolment.zip
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
This is changed report_change_record.php

<?php
include("connect.php");

$ud_id=$_POST['ud_id'];
$ud_first_name=$_POST['ud_first_name'];
$ud_last_name=$_POST['ud_last_name'];
$ud_address_1=$_POST['ud_address_1'];
$ud_address_2=$_POST['ud_address_2'];
$ud_postcode=$_POST['ud_postcode'];
$ud_email=$_POST['ud_email'];
$ud_phone=$_POST['ud_phone'];
$ud_age=$_POST['ud_age'];
$ud_ethnicity=$_POST['ud_ethnicity'];
$ud_school=$_POST['ud_school'];
$ud_additional_support=$_POST['ud_additional_support'];
$ud_additional_info=$_POST['ud_additional_info'];
$ud_course=$_POST['ud_course'];


           $weekdays = $_POST['weekdays'];
           $fieldsquery = "";
           
           $days = array("monday" => 0,"tuesday" => 0,"wednesday" => 0,"thursday" => 0,"friday" => 0);
           
           foreach($weekdays as $day => $value)
           {
                $day = explode("_",$value);
                $days[$day[0]] += $day[1];
           }
           
           foreach($days as $day => $value){
                $fieldsquery .= ", ".$day." = '$value'"; 
           }
           

if (! $link) die("Couldn't connect to MySQL");
mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());
$q = " UPDATE induction SET first_name='$ud_first_name' , last_name='$ud_last_name' , address_1='$ud_address_1' , address_2='$ud_address_2' , postcode='$ud_postcode' , email='$ud_email' , phone='$ud_phone' , age='$ud_age' , ethnicity='$ud_ethnicity' , school='$ud_school' , additional_support='$ud_additional_support' , additional_info='$ud_additional_info' , course='$ud_course' ".$fieldsquery." WHERE id='$ud_id'";
echo"$q<br />";
mysql_query($q) or die(mysql_error());

header("Location: report_display.php");

?> 

Open in new window

0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
Comment Utility
just comment out the line 39 in the above
and this is the report_display:

<!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; charset=utf-8" />
  <title>Greenbank College - Admissions Form</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
    include("connect.php");
    
    
    // HERE WE WOULD HANDLE THE SELECTED ACTION
    // DELETION OR EDIT
    
    if(!empty($_GET[action]) && !empty($_GET[id])){
        if($_GET[action] == "delete"){
            // delete the record with given id
            $query = "delete from induction where id = $_GET[id]";
            $result = mysql_query($query) or die(mysql_error());
            echo "RECORD DELETED.<br />";
        }
        elseif($_GET[action] == "edit"){
        
            $query = "select * from induction where id = $_GET[id]";
            $result = mysql_query($query) or die(mysql_error());
            
            while ($row = mysql_fetch_array($result)) {
                $first_name = $row["first_name"];
                $last_name = $row["last_name"];
                $address_1 = $row["address_1"];
                $address_2 = $row["address_2"];
                $postcode = $row["postcode"];
                $email = $row["email"];
                $phone = $row["phone"];
                $age = $row["age"];
                $ethnicity = $row["ethnicity"];
                $school = $row["school"];
                $additional_support = $row["additional_support"];
                $course = $row["course"];
                $additional_info = $row["additional_info"];

                $monday = $row["monday"];
                $tuesday = $row["tuesday"];
                $wednesday = $row["wednesday"];
                $thursday = $row["thursday"];
                $friday = $row["friday"];
            }
?>
<table width="90%" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Edit and Submit</h3>
<form action="report_change_record.php" method="post">
<input type="hidden" name="ud_id" value="<?php echo "$_GET[id]" ?>">
FirstName:					<input type="text" name="ud_first_name" value="<?php echo "$first_name"?>"><br>
LastName: 					<input type="text" name="ud_last_name" value="<?php echo "$last_name"?>"><br>
Address1: 					<input type="text" name="ud_address_1" value="<?php echo "$address_1"?>"><br>
Address2:					<input type="text" name="ud_address_2" value="<?php echo "$address_2"?>"><br>
Postcode: 					<input type="text" name="ud_postcode" value="<?php echo "$postcode"?>"><br>
Email: 						<input type="text" name="ud_email" value="<?php echo "$email"?>"><br>
Phone:						<input type="text" name="ud_phone" value="<?php echo "$phone"?>"><br>
Age: 						<input type="text" name="ud_age" value="<?php echo "$age"?>"><br>
Ethnicity: 					<input type="text" name="ud_ethnicity" value="<?php echo "$ethnicity"?>"><br>
School:						<input type="text" name="ud_school" value="<?php echo "$school"?>"><br>
Additional Support: yes		<input type="radio" name="ud_additional_support" value="yes" <?php if($additional_support=="yes") echo "checked"; ?>><br>
					no		<input type="radio" name="ud_additional_support" value="no" <?php if($additional_support=="no") echo "checked"; ?>><br>
Course1: 					<input type="text" name="ud_course" value="<?php echo "$course"?>"><br>
Additional Info: 			<input type="text" name="ud_additional_info" value="<?php echo "$additional_info"?>"><br>


    <input type="checkbox" name="weekdays[]" value="monday_1" <?php if($monday == 1 || $monday == 3) echo"checked='checked'";?> />Monday AM | 
    <input type="checkbox" name="weekdays[]" value="monday_2" <?php if($monday == 2 || $monday == 3) echo"checked='checked'";?> />Monday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="tuesday_1" <?php if($tuesday == 1 || $tuesday == 3) echo"checked='checked'";?> />Tuesday AM | 
    <input type="checkbox" name="weekdays[]" value="tuesday_2" <?php if($tuesday == 2 || $tuesday == 3) echo"checked='checked'";?> />Tuesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="wednesday_1" <?php if($wednesday == 1 || $wednesday == 3) echo"checked='checked'";?> />Wednesday AM | 
    <input type="checkbox" name="weekdays[]" value="wednesday_2" <?php if($wednesday == 2 || $wednesday == 3) echo"checked='checked'";?> />Wednesday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="thursday_1" <?php if($thursday == 1 || $thursday == 3) echo"checked='checked'";?> />Thursday AM | 
    <input type="checkbox" name="weekdays[]" value="thursday_2" <?php if($thursday == 2 || $thursday == 3) echo"checked='checked'";?> />Thursday PM<br />
    
    <input type="checkbox" name="weekdays[]" value="friday_1" <?php if($friday == 1 || $friday == 3) echo"checked='checked'";?> />Friday AM | 
    <input type="checkbox" name="weekdays[]" value="friday_2" <?php if($friday == 2 || $friday == 3) echo"checked='checked'";?> />Friday PM<br />

<input type="Submit" value="Update">
</form>
</td></tr></table>

<?php




        
        }
    }
    
    
    
    
    
    $result = mysql_query( "SELECT * FROM induction" )
    or die("SELECT Error: ".mysql_error());
    $num_rows = mysql_num_rows($result);
    print "There are $num_rows records.<br>";

    echo "<table width=90% border=1>";
    
    
    echo "<tr>";
    echo "<td>id</td>";
    echo "<td>first name</td>";
    echo "<td>last name</td>";
    echo "<td>address 1</td>";
    echo "<td>address </td>";
    echo "<td>postcode</td>";
    echo "<td>email</td>";
    echo "<td>phone</td>";
    echo "<td>age</td>";
    echo "<td>ethnicity</td>";
    echo "<td>school</td>";
    echo "<td>additional support</td>";
    echo "<td>additional info</td>";
    echo "<td>date</td>";
    echo "<td>monday</td>";
    echo "<td>tuesday</td>";
    echo "<td>wednesday</td>";
    echo "<td>thursday</td>";
    echo "<td>friday</td>";
    echo "<td>course</td>";
    echo "<td>actions</td>";
    echo "</tr>";
    
    
    while ($get_info = mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>$get_info[id]</td>";
    echo "<td>$get_info[first_name]</td>";
    echo "<td>$get_info[last_name]</td>";
    echo "<td>$get_info[address_1]</td>";
    echo "<td>$get_info[address_2]</td>";
    echo "<td>$get_info[postcode]</td>";
    echo "<td>$get_info[email]</td>";
    echo "<td>$get_info[phone]</td>";
    echo "<td>$get_info[age]</td>";
    echo "<td>$get_info[ethnicity]</td>";
    echo "<td>$get_info[school]</td>";
    echo "<td>$get_info[additional_support]</td>";
    echo "<td>$get_info[additional_info]</td>";
    echo "<td>$get_info[date]</td>";
        if($get_info[monday] == 0) $field = "-";
        if($get_info[monday] == 1) $field = "Monday AM";
        if($get_info[monday] == 2) $field = "Monday PM";
        if($get_info[monday] == 3) $field = "Monday AM / PM";
    echo "<td>$field</td>";
        if($get_info[tuesday] == 0) $field = "-";
        if($get_info[tuesday] == 1) $field = "Tuesday AM";
        if($get_info[tuesday] == 2) $field = "Tuesday PM";
        if($get_info[tuesday] == 3) $field = "Tuesday AM / PM";    
    echo "<td>$field</td>";
        if($get_info[wednesday] == 0) $field = "-";
        if($get_info[wednesday] == 1) $field = "Wednesday AM";
        if($get_info[wednesday] == 2) $field = "Wednesday PM";
        if($get_info[wednesday] == 3) $field = "Wednesday AM / PM";        
    echo "<td>$field</td>";
        if($get_info[thursday] == 0) $field = "-";
        if($get_info[thursday] == 1) $field = "Thursday AM";
        if($get_info[thursday] == 2) $field = "Thursday PM";
        if($get_info[thursday] == 3) $field = "Thursday AM / PM";        
    echo "<td>$field</td>";
        if($get_info[friday] == 0) $field = "-";
        if($get_info[friday] == 1) $field = "Friday AM";
        if($get_info[friday] == 2) $field = "Friday PM";
        if($get_info[friday] == 3) $field = "Friday AM / PM";        
    echo "<td>$field</td>";
    echo "<td>$get_info[course]</td>";
    echo "<td><a href=\"report_display.php?action=edit&amp;id=$get_info[id]\">edit</a> | <a href=\"report_display.php?action=delete&amp;id=$get_info[id]\">remove</a></td>";
    echo "</tr>";

}
print "</table>";
mysql_close($link);
?> 

<br>


<form method="POST" action="report_interface.php">
<input type="submit" value="Dbase Interface">
</form>
</body>

</html>

Open in new window

0
 

Author Comment

by:ian646
Comment Utility
brilliant - the checkboxes work now - and leave a '-' for blank days. i would like an option for the user to display a learner record for printing.  would this be best produced from the dispaly screen? As in, edit, delete and display? i guess i can spruce up the output in html and add additional courses if required to the form?
0
 

Author Closing Comment

by:ian646
Comment Utility
FantAstic help
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
No points then ?
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
I believe I've spent enough time to be awarded with some points...
?
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now