0

I am trying pass some value from a HTML form to another PHP file via GET method. But when i click submit it show me the code of that PHP file instead of running the file in browser. Se my Snapshot please

enter image description here

I am also attaching my code: For Form:

    <form action="input.php" method="GET">
        <div id="form">
            <h2>REGISTRATION NO.<br> <inenter code hereput type="text" name="reg_no"><br></h2>
            <h2>BOARD<br> <input type="text" name="board"><br></h2>
            <h2>YEAR<br> <input type="text" name="year"><br></h2>
            Choose Type <select name="type">
                <option value="hsc">H.S.C</option> 
                <option value="A level">A Level</option>
                <option value="Foreigner">Foreigner</option>
            </select><br/><br/>
            <input type="submit" value="Submit"><br /><br>
        </div>
    </form>

For the Receiver php file:

<?php
    $reg_no =(int) $_GET['reg_no'];
    $board =  $_GET['board'];
    $year = (int)$_GET['year'];
    $type = (int) $_GET['type'];
    //$student_type =(char) $_GET['type'];
    $con = mysql_connect("localhost","root");

    if (!$con) 
        {           
            die('Could not connect' . mysql_error());
        }
    else
    {
        printf("Database Connection succed");
    }

    mysql_select_db("dblabproject",$con);

     function checkRegistration()
    {

    }

    mysql_query
    ("INSERT INTO`student_reg` (`reg_no`, `board`, `year`)
     VALUES ('$reg_no', '".$_GET['board']."', '$year')
     ");

?>
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Md. Sulayman
  • 781
  • 8
  • 30
  • Does the file ends with : `*.php` and do you have php on your web server installed? Is the web server turned on and do you call the file over the web server? (You call the file over the file system! Do you have even a server?) – Rizier123 Jan 07 '15 at 10:39
  • 2
    Looking at the URL I see that you are using file:///etc to access that page. That will never work because you are skipping apache this way. You need to use http:// localhost/etc to execute php code. – ToX 82 Jan 07 '15 at 10:41
  • 1
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Jan 07 '15 at 10:43

1 Answers1

3

It is because you are trying to access the file in your browser via the path and not via a server.

XAMPP should be reached via localhost, not C://xampp.

here is a simple tutorial on php and xamp

atmd
  • 7,430
  • 2
  • 33
  • 64