Jump to content

Query problem in MySQL


heshan

Recommended Posts

Hi All,

 

I want to generate time table reports. A form includes labels to enter grade, class and stream. After selecting data user should click on "Generate" button and relevant time table details. The data is submitted for the following page and there was an empty set of data shown in the report. I want to know where i went wrong? The piece of PHP code is as follows.

 

table structure is as follows.

 

class (class_id, class_name, grade_id, stream)

subject (subject_id, name, --)

time_table (class_id, time_from, time_to, subject_id, date)

 

<?php
public function myconnection(){
$this->con = mysql_connect("localhost","root","");
mysql_select_db("student_management", $this->con);

$grade=$_POST['grade_ID'];
$class=$_POST['class_ID'];
$stream=$_POST['stream_ID'];

$this->result = mysql_query("SELECT time_table.time_from, time_table.time_to, time_table.date, subject.name FROM time_table
                                               INNER JOIN subject ON time_table.subject_id=subject.subject_id INNER JOIN class
                                               ON time_table.class_id=class.class_id WHERE class.class_name='$class' AND class.stream='$stream'")
                                               or die (mysql_error());
    }
    ?>

Link to comment
Share on other sites

Not from that code, I'm afraid. You're missing some quite vital information in there, such as where you're outputting the data. Could also be a problem with the data itself, or the input process. So verify that the data in your database is correct first and foremost, then post the rest of the code.

 

PS: You really need to read up on Input Validation and Output Escaping, your script is wide open for attackers to abuse. Also remember to remove mysql_error () when putting into production, replace it with a custom message which doesn't divulge any details about your script's inner workings.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.