Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
Like Tree2Likes

Thread: XML using as database with PHP !

  1. #1
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation XML using as database with PHP !

    Hi guys

    I want to try to creating STUDENT EXAM RESULT SYSTEM with XML and PHP.

    And i just want to help from you for creating to STUDENT EXAM RESULT SYSTEM.

    I hope, you'll get help me


    So we'll get start with an example :

    XML DOCUMENT

    <?xml version="1.0" encoding="UTF-8"?>
    <users>
    <user>
    <schoolnumber>1</schoolnumber>
    <Name_Surname>Adam Williams</Name_Surname>
    <Date_of_Exam>2014/21/10</Date_of_Exam>
    <Result>70</Result>
    <Foreign_Lang>English</Foreign_Lang>
    </user>

    <user>
    <schoolnumber>2</schoolnumber>
    <Name_Surname>Mark Tuts</Name_Surname>
    <Date_of_Exam>2014/21/10</Date_of_Exam>
    <Result>80</Result>
    <Foreign_Lang>German</Foreign_Lang>
    </user>


    <user>
    <schoolnumber>3</schoolnumber>
    <Name_Surname>Steve Conney</Name_Surname>
    <Date_of_Exam>2014/21/10</Date_of_Exam>
    <Result>90</Result>
    <Foreign_Lang>French</Foreign_Lang>
    </user>


    <user>
    <schoolnumber>4</schoolnumber>
    <Name_Surname>Eric Morris</Name_Surname>
    <Date_of_Exam>2014/21/10</Date_of_Exam>
    <Result>60</Result>
    <Foreign_Lang>English</Foreign_Lang>
    </user>

    </users>


    thats our XML File.

    I create login form now but i think how i will create login form with php such as using a xml file as database.

    so i want, student entry own schoolnumber to login form afterthat student can see own exam results.

    i show you with an example now;


    XML using as database with PHP !-untitled-2.jpg

    Thanks for your helps....

  • #2
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Please reply guys

  • #3
    New Coder
    Join Date
    Jun 2013
    Posts
    28
    Thanks
    2
    Thanked 2 Times in 2 Posts
    $school_num = $_REQUEST['school_number'];
    $xml = simplexml_load_file("student_info.xml");
    $student_info = $xml->xpath("/users/user[schoolnumber ='$school_num']");
    if($student_info)
    {
    echo $student_details->Name_Surname;
    echo $student_details->Date_of_Exam;
    echo $student_details->Result;
    echo $student_details->Foreign_Lang;
    }

    In this Simplexml and xpath is used.
    wustafa likes this.

  • #4
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you for reply sathish-wd. But i want to say something about this code. I have two php pages for this project. Login.php and show.php. Which page can i put this code ? Login.php or show.php ? I try to put this code to show.php and this code successfully working in show.php but I just view schoolnumber not others. Please help me about this. Thank you.

  • #5
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Login.php

    XML using as database with PHP !-12312.jpg

    show.php

    XML using as database with PHP !-222.jpg

  • #6
    New Coder
    Join Date
    Jun 2013
    Posts
    28
    Thanks
    2
    Thanked 2 Times in 2 Posts
    You are trying to print directly without the use of object($student_info) ,Use object before the xml node

    if($student_info)
    {
    echo $student_info->Name_Surname;
    echo $student_info->Date_of_Exam;
    echo $student_info->Result;
    echo $student_info->Foreign_Lang;
    }

    This will work,...

  • #7
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
     <?php
    $school_num 
    $_REQUEST['school_number'];
    $xml simplexml_load_file("student_info.xml");
    $student_info $xml->xpath("/users/user[schoolnumber ='$school_num']");
    if(
    $student_info)
    {
     
      echo    
    '
              <td class="total" style="width:200px;">'
    $student_info->Name_Surname .'</td>
                <td class="total">'
    $student_info->Date_of_Exam .'</td>
                <td class="total">'
    $student_info->Result .'</td>
                <td class="total">'
    $student_info->Foreign_Lang .'</td>';

        
    ?>

  • #8
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I added to up message php code inside show.php but i can't view students' informations on show.php file. How should i put the code in login.php and show.php ?

  • #9
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    please reply guys

  • #10
    New Coder
    Join Date
    Jun 2013
    Posts
    28
    Thanks
    2
    Thanked 2 Times in 2 Posts
    You want to check whether the xpath is getting the values

    Try all these steps to find whether the xml(xpath) is working

    1.// Check whether the xpath object is having value in it , before if condition
    print_r($student_info);

    2.// Check whether if condition is processing
    if($student_info)
    {
    echo "Student info";
    }
    3. // Above both steps dont work try this one,
    if($student_info)
    {
    foreach($student_info as $student_det)
    {
    echo '
    <td class="total" style="width:200px;">'. $student_det->Name_Surname .'</td>
    <td class="total">'. $student_det->Date_of_Exam .'</td>
    <td class="total">'. $student_det->Result .'</td>
    <td class="total">'. $student_det->Foreign_Lang .'</td>';
    }
    }
    .........

  • #11
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    http://www.codingforums.com/attachme...untitled-2.jpg

    My friend, the code is working now, thanks. But I have a another problem again... I added one more informations of new persons about result system in xml file. When I wrote schoolnumber on login, I view another person's all informotions on same table with together.

    How can i fix this problem ?

  • #12
    New Coder
    Join Date
    Jun 2013
    Posts
    28
    Thanks
    2
    Thanked 2 Times in 2 Posts
    I can't able to get your question , can you post your code snippet .
    Then only i can able to find the problem.

  • #13
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Firstly, thanks for your helps...

    I put photos about my problem. I explained my problem with photos...

    login.php

    XML using as database with PHP !-1.jpg

    show.php

    XML using as database with PHP !-2.jpg

    student_info.xml

    XML using as database with PHP !-3.jpg


    I wait your helps...

  • #14
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    CODE

    login.php

    PHP Code:
    <div class="form">
    <
    form id="form-doc" name="form-doc" action="show.php" method="post">


    <
    input type="text" class="snum" name="snum" id="snum" onblur="if (value =='') {value = 'snum'}" onfocus="if (value == 'snum') {value =''}" type="text" value="School Number" />


    <
    input type="submit" name="login" class="login" id="login" value="RESULT" />
    </
    form>
    </
    div



    PHP Code:
                      <table>
                        <tr>
                          <th>SCHOOL NUMBER</th>
                          <th>NAME - SURNAME</th>
                          <th>DATE</th>
                          <th>RESULT</th>
                          <th>FOREIGN LANGUAGE</th>
                        </tr>

     <?php
    $school_num 
    $_REQUEST['school_number'];
    $xml simplexml_load_file("users/sonuc.xml");
    $student_info $xml->xpath("/users/user[school_number ='$school_num']");
    $student_info $xml->xpath("/users/user[Name_Surname]");
    $student_info $xml->xpath("/users/user[Date_of_Exam]");
    $student_info $xml->xpath("/users/user[Result]");
    $student_info $xml->xpath("/users/user[Foreign_Lang]");
    if(
    $student_info)
    {
        foreach(
    $student_info as $student_det){
     
      echo    
    '
                  <td class="total" style="width:200px;">'
    $student_det->school_number .'</td>
                <td class="total">'
    $student_det->Name_Surname .'</td>
                <td class="total">'
    $student_det->Date_of_Exam .'</td>
                <td class="total">'
    $student_det->Result .'</td>
                <td class="total">'
    $student_det->Foreign_Lang .'</td> ';

    }
        
    ?>   
                
                      </table>
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <users>
    <user>
    <school_number>11111111111111</school_number>
    <Name_Surname>Tim Warners</Name_Surname>
    <Date_of_Exam>24.7.2014</Date_of_Exam>
    <Result>90</Result>
    <Foreign_Lang>ENGLISH</Foreign_Lang>
    </user>
    
    <user>
    <school_number>22222222222222</school_number>
    <Name_Surname>Mark Koll</Name_Surname>
    <Date_of_Exam>24.7.2014</Date_of_Exam>
    <Result>90</Result>
    <Foreign_Lang>ENGLISH</Foreign_Lang>
    </user>
    
    <user>
    <school_number>333333333333333</school_number>
    <Name_Surname>Ronald Hull</Name_Surname>
    <Date_of_Exam>24.7.2014</Date_of_Exam>
    <Result>90</Result>
    <Foreign_Lang>ENGLISH</Foreign_Lang>
    </user>
    
    <user>
    <school_number>444444444444444</school_number>
    <Name_Surname>Richard Watson</Name_Surname>
    <Date_of_Exam>24.7.2014</Date_of_Exam>
    <Result>90</Result>
    <Foreign_Lang>ENGLISH</Foreign_Lang>
    </user>
    
    </users>

  • #15
    New Coder
    Join Date
    Jun 2013
    Posts
    28
    Thanks
    2
    Thanked 2 Times in 2 Posts
    - You are getting the $_REQUEST['school_number'] from value('school_number') , you should get $_REQUEST['snum'] from name('snum'),
    - Remove the extra fetching from xml
    Code:
     $student_info = $xml->xpath("/users/user[Name_Surname]"); 
    $student_info = $xml->xpath("/users/user[Date_of_Exam]"); 
    $student_info = $xml->xpath("/users/user[Result]"); 
    $student_info = $xml->xpath("/users/user[Foreign_Lang]");
    The following working code works perfectly try this,

    login.php
    Code:
    <div class="form"> 
    <form id="form-doc" name="form-doc" action="show.php" method="post">
    <input type="text" class="snum" name="snum" id="snum" onblur="if (value =='') {value = 'snum'}" onfocus="if (value == 'snum') {value =''}" type="text" value="School Number" /> 
    <input type="submit" name="login" class="login" id="login" value="RESULT" /> 
    </form> 
    </div>
    show.php
    Code:
                      <table> 
                        <tr> 
                          <th>SCHOOL NUMBER</th> 
                          <th>NAME - SURNAME</th> 
                          <th>DATE</th> 
                          <th>RESULT</th> 
                          <th>FOREIGN LANGUAGE</th> 
                        </tr> 
    
     <?php 
    $school_num = $_REQUEST['snum']; 
    $xml = simplexml_load_file("users/sonuc.xml"); 
    $student_info = $xml->xpath("/users/user[school_number ='$school_num']"); 
    if($student_info) 
    { 
        foreach($student_info as $student_det){ 
      
      echo    ' 
                  <td class="total" style="width:200px;">'. $student_det->school_number .'</td> 
                <td class="total">'. $student_det->Name_Surname .'</td> 
                <td class="total">'. $student_det->Date_of_Exam .'</td> 
                <td class="total">'. $student_det->Result .'</td> 
                <td class="total">'. $student_det->Foreign_Lang .'</td> '; 
    }  
    } 
        ?>    
                 
                      </table>
    Xml file has no change,..........
    .......
    wustafa likes this.

  • Users who have thanked sathish-wd for this post:

    wustafa (08-09-2014)


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •