Jump to content

mtvaran

Members
  • Posts

    61
  • Joined

  • Last visited

    Never

Posts posted by mtvaran

  1. this is my full query for searching data from multiple table. still i could not get any result. could anyone check please where am i made mistake?

    <?php  
    
    	$con = mysql_connect("localhost","root","");
    if (!$con)
      	{
      	die('Could not connect: ' . mysql_error());
      	}
    
    mysql_select_db("uni", $con);
    
    $sql = "
        SELECT take.StudentID
              ,student.StudentName
              ,take.CourseID
              ,course.CourseName
        FROM take
            ,student
            ,course
        WHERE take.StudentID = student.StudentID
        AND take.CourseID = course.CourseID
        AND take.StudentID LIKE '$_POST[sid]%'
        ORDER BY take.StudentID ASC
    ";
    
    $result = mysql_query($sql) or trigger_error('MySQL Error: ' . mysql_error(), E_USER_ERROR);
    
    echo"<br>";
    
    echo "<center><table width=700 border=1>";
    echo "<tr><th>StudentID</th><th>StudentName</th><th>CourseID</th><th>CourseName</th></tr>";
    
    while($row = mysql_fetch_array ($result))
    echo mysql_error();
    {
    
    echo "<tr><td>";
    echo $row['StudentID'];
    echo "</td><td>";
    echo $row['StudentName'];
    echo "</td><td>";
    echo $row['CourseID'];
    echo "</td><td>";
    echo $row['CourseName'];
    echo "</td></tr>";
    
    }
    
    echo "</table>";
    
    mysql_close($con); 
    ?>

     

     

  2. hi guys how to fix this error. i have this query

    $sql = "
        SELECT take.StudentID
              ,student.StudentName
              ,take.CourseID
              ,course.CourseName
        FROM take
            ,student
            ,course
        WHERE take.StudentID = student.StudentID
        AND take.CourseID = course.CourseID
        AND StudentID LIKE '$_POST[sid]%'
        ORDER BY StudentID ASC
    ";
    
    $result = mysql_query($sql) or trigger_error('MySQL Error: ' . mysql_error(), E_USER_ERROR);

     

     

     

    error msg: Fatal error: MySQL Error: Column 'StudentID' in where clause is ambiguous in C:\wamp\www\dis_take.php on line 98

     

  3. could anyone please check this code for me. i get the error msg like...

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\dis_study.php on line

     

     

    <?php 
    
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    
    mysql_select_db("uni", $con);
    
    $result = mysql_query("SELECT study.StudentID,student.StudentName,study.ProgrammeName FROM study,student WHERE study.StudentID = student.StudentID AND StudentID LIKE '$_POST[sid]%' ORDER BY StudentID ASC");
    
    echo"<br>";
    
    echo "<center><table width=700 border=1>";
    echo "<tr><th>StudentID</th><th>StudentName</th><th>ProgrammeName</th></tr>";
    
    while($row = mysql_fetch_array ($result))
    
    {
    
    echo "<tr><td>";
    echo $row['StudentID'];
    echo "</td><td>";
    echo $row['StudentName'];
    echo "</td><td>";
    echo $row['ProgrammeName'];
    echo "</td></tr>";
    
    }
    
    echo "</table>";
    mysql_close($con);
    
    ?>

  4. Hi guys, i have to create a drop-down menu for database data,  when i select one data  from that then next drop-down menu has to create automatically with related data of  the 1st selection.

    could anyone please give me some help to do this?

     

    NB: i have 3 tables student(sid, sname), course (cid, cname) , take (sid, cid) so if i select one of the cid then another drop down list  has to create automatically with sid who is taking the cid .

  5. hi guys, i am  struggling with cross tab query in mysql. if you have any idea could you please help me? basically i have data into the table like...

     

    cid | Q# | marks

    c1 | 1| 50

    c1 | 2 | 50

    c1 | 3 | 50

     

    but i need to be the table like...

     

    cid | Q1 | Q2 | Q3

    c1 | 50 | 50 | 50

  6. basically im displaying a column field as drop-down list.

    then ask enter No of question'

    (if i enter 2 then 2 text field will be created automatically)

    after i enter data into it.

    then all data have to be stored into another table.

    Eg:

    cid, q#,marks

    c1,1,50

    c1,2,50.

     

    here evrything has been displayed well but when i click submit, the data doesn't insert into table

     

     

  7. Hi guys, basically here pull out the data from database then creating taxt field automatically and submit into anther table. everything works fine but data not inserting in to the table. could you guys check my code please?

     

     

     <?php
    
    $con = mysql_connect("localhost","root","");
    
    mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error());
    ?>
    <?php
    $result  = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error());
    
    
    echo '<select name ="cid[]">';
    
    while($row = mysql_fetch_array($result))
    {
    
        echo '<option value="' . $row['CourseID'] . '">'. $row['CourseID'] .'</option>';
    }
    
    echo '</select>';
    //------------------
    ?>
       
    <?php
    if(!empty($_POST["submit"]))
    {
    $value = empty($_POST['question']) ? 0 : $_POST['question'];
    ?>
    <form name="form1" method="post" action="result.php">
    <?php
    
    
    for($i=0;$i<$value;$i++)
    {
      echo 'Question NO: <input type="text" name="qno[]" size="2" maxlength="2" class="style10">    
            Enter Marks: <input type="text" name="marks[]" size="3" maxlength="3" class="style10"><br>';
      }
    
    
    ?>
      <label> <br />
      <br />
      <input type="submit" name="Submit" value="Submit" class="style10">
      </label>
    </form>
    <?php
    }
    else{
    ?>
    
    <form method="POST" action="#">
    
    
    
    <label>
    <span class="style10">Enter the Number of Question</span>
    <input name="question" type="text" class="style10" size="2" maxlength="2"> 
    </label>
    <input name="submit" type="submit" class="style10" value="Submit">
    
    
    </form>
    <?php }?>

     

     

    result.php

    <?php
    
    
    $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error());
    mysql_select_db("uni",$con) or die('Could not connect: ' . mysql_error());
    
    foreach ($_POST['cid'] as $c) {$cid [] = $c;}
    foreach($_POST['qno'] as $q){$qno[] = $q;}
    foreach($_POST['marks'] as $m){$marks[] = $m;}
    $ct = 0;
    for($i=0;$i<count($qno);$i++)
    {
    
    $sql="INSERT INTO examquesion (CourseID,QuesionNo,MarksAllocated) VALUES('$cid[$i]','$qno[$i]','$marks[$i]')";
    mysql_query($sql,$con) or die('Error: ' . mysql_error());
    $ct++;
    }
    echo "$ct record(s) added";
    mysql_close($con)
    ?>

     

  8. i did change as u said but still error.... im bit new & stupid with php things. :) could you check this for me pls?

    {
    echo "Question NO:";
    echo '<input type="text" name="qno[]">'."\t";
    
    echo "Enter Marks:";
    echo '<input type="text" name="marks[]">'."\t";
    echo "<br>";
    }

    $sql="INSERT INTO cell (QNO,MARKS)
    VALUES
    ('$_POST['qno']','$_POST['marks']')";

     

  9. Hi guys i have to create text field & enter data and store in the data base. here im able to create text field but couldn't insert the data. so could anyone please check this code for me.

     

    <body>
    <form method="POST" action="cell.php">
    Enter the number of question
    <input type="text" name="question">
    <input type="submit">
    
    
    
    
      <?php
    $value=$_POST['question'];
    
    for($i=0;$i<$value;$i++)
    {
    echo "Question NO:";
    echo '<input type="text" name="qno">'."\t";
    
    echo "Enter Marks:";
    echo '<input type="text" name="marks">'."\t";
    echo "<br>";
    }
    ?>
    </form>
    <form name="form1" method="post" action="cellresult.php">
      <label>
      <input type="submit" name="Submit" value="Submit">
      </label>
    </form>
    
    </body>

     

     

     

    cellresult.php

    <body>
    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("test", $con);
    
    $sql="INSERT INTO cell (QNO,MARKS)
    VALUES
    ('$_POST[qno]','$_POST[marks]')";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($con)
    ?>
    </body>

     

  10. Hi guys, im inserting data into the table using drop-down list & multi select list,well it works very well. but i need to make sure i should not insert same StudentID & CourseID twice. here my code for you could anyone tell me pls where should i write code to check existing data?

    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    
      mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error());
    $result  = mysql_query("SELECT * FROM student") or trigger_error('MySQL error: ' . mysql_error());
    
    
    echo '<select name="sid">';
    
    while($row = mysql_fetch_array($result))
    {
    
        echo '<option value="' . $row['StudentID'] . '">' . $row['StudentName'] . '</option>';
    }
    
    echo '</select>';
    
    // ----------------
    
    ?>
    </div>
    <div class="style41" id="Layer7">
    
    <?php
    $result  = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error());
    
    
    echo '<select name ="cid[]" multiple="multiple" size="10">';
    
    while($row = mysql_fetch_array($result))
    {
        echo '<option value="' . $row['CourseID'] . '">' . $row['CourseName'] . '</option>';
    }
    
    echo '</select>';
    mysql_close($con);
    ?>

     

     

    ------------------------------------

    <?php
    
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
      mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error());
       
    if (!empty($_POST['sid']) && !empty($_POST['cid'])) 
    {
        $ct = 0;
        $student = $_POST['sid'];
        foreach ($_POST['cid'] as $key => $course)
        {
         $sql = "INSERT INTO take (StudentID, CourseID) VALUES('".mysql_real_escape_string($student)."',
     '".mysql_real_escape_string($course)."')";
         $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error());
         if (mysql_affected_rows() > 0){$ct++;}
         }
        echo $ct . ' rows added.';
    }  
    
    mysql_close($con);
    
    ?>

     

     

  11. still i get error msg. im bit new & stupid with php. so i just post all of my coding so could any1 check this for me plss

    <?php
    
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
      mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error());
       try
       {
    $sql   = "SELECT StudentID,CourseID FROM take WHERE StudentID =" . $_POST['sid'] . " AND CourseID =" .$_POST['cid'] ;
        $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error());
    
        if (mysql_num_rows($query) > 0)
        {
            echo'StudentID already taken';
        }
    }
    if (!empty($_POST['sid']) && !empty($_POST['cid'])) //-------> error line
    {
        $ct = 0;
        $student = $_POST['sid'];
        foreach ($_POST['cid'] as $key => $course)
        {
         $sql = "INSERT INTO take (StudentID, CourseID) VALUES('".mysql_real_escape_string($student)."','".mysql_real_escape_string($course)."')";
         $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error());
         if (mysql_affected_rows() > 0){$ct++;}
         }
        echo $ct . ' rows added.';
    }  
    
    mysql_close($con);
    
    ?>

     

  12. try
       {
    $sql   = "SELECT StudentID,CourseID FROM student,course WHERE StudentID =" . $_POST['sid']  AND CourseID =".$_POST['cid'] ; //-----> error line
    
        $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error());
    
        if (mysql_num_rows($query) > 0)
        {
            throw new Exception('StudentID already taken');
        }
    }

     

    NB: basicaly im inserting data into a table from another two table field.

  13. <body>
    
    <form  method="post" action="new.php"  name="submitted"   /> 
      <label>TYPE: 
      <select name="field"> 
        <option value ="sid">StudentID</option> 
        <option value ="sname">StudentName</option> 
      </select> 
      </label> 
      <label>WORD: 
      <input type="text" name="searchword" /> 
      </label> 
      
      <input type="submit" name ="submitted" /> 
      
    </form> 
    
    <?php 
    if (isset($_POST['submitted'])){ 
    $searchword = htmlentities(addslashes($_POST['searchword']));
    
    $con = mysql_connect("localhost","root",""); 
    
    mysql_select_db("uni", $con) or trigger_error('MySQL error: ' . mysql_error());  
    
    $field= $_POST['field'];
    $searchword = $_POST['searchword'];
    
    
    $result = mysql_query("SELECT* FROM student WHERE $field ='$searchword'") or trigger_error('MySQL error: ' . mysql_error());  
    
    //$result = mysql_query($query); 
    //$num_rows = mysql_num_rows($result); 
    
    //echo"num_rows results found."; 
    echo"<table>"; 
    echo "<tr><th>StudentID</th><th>StudentName</th></tr>"; 
    while($row = mysql_fetch_array($result)){ 
    
    echo "<tr><td>"; 
    echo "$row ['field']"; 
    echo "</td><td>"; 
    echo "$row ['searchword']"; 
    echo "</td></tr>"; 
    } 
    
    echo"</table>"; 
    
    
    } 
    
    mysql_close($con); 
    
    ?>
    </body>
    </html>

     

    Hi guys, i jst made some correction but still some error on it. could you pls check this code for me.

     

    NB: my error msg.....

    Notice: MySQL error: Unknown column 'sid' in 'where clause' in C:\wamp\www\new.php on line 37

     

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\new.php on line 45

×
×
  • 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.