0
 <?php
 if(isset($_POST['Search']))
  {
    $num = $_POST['num'];
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    $dbname = 'vasuki';
    mysql_select_db($dbname);
    $Result = mysql_query("SELECT id, name, age FROM details WHERE id = '$num'");
        while($row = mysql_fetch_array($Result)) {
                    $name = $row['name'] ;
        $age = $row['age'];

        echo "<div style='top: 273px;
                margin-left: 60px;
                position: absolute;left: 30px;'>
                <table border='1'><tr><th>Name</th>
                <th> Age </th></tr>
                <tr><td>".$name."</td>
                <td>".$age."</td>
                <td>Edit</td></tr>
                </table></div>";
        }

I will explain the concept first :

In first page I insert the person details. and In second page in need to update the details. The above program is for my second page. To update I am searching data using the name and age. If I get the particular person data I need to click Edit and It should go to my 1st page and I need to Update the data.

I completed my html codes. I need to know php code to connect SQL.

Can anyone help on this ?

Sukki
  • 23
  • 4
  • I don't think that's enough information if you want to update? – Gynteniuxas Sep 04 '16 at 09:53
  • Ok let me explain: In first page I insert the person details. and In second page in need to update the details. The above program is for my second page. To update I am searching data using the name and age. If I get the particular person data I need to click Edit and It should go to my 1st page and I need to Update the data. – Sukki Sep 04 '16 at 09:59
  • 2
    `mysql_*` functions are deprecated as of PHP 5.5 and are removed altogether in PHP 7.0. Use [`mysqli`](http://php.net/manual/en/book.mysqli.php) or [`pdo`](http://php.net/manual/en/book.pdo.php) instead. [And this is why you shouldn't use mysql_* functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). – Rajdeep Paul Sep 04 '16 at 10:15
  • **WARNING**: If you're just learning PHP, please, do not use the [`mysql_query`](http://php.net/manual/en/function.mysql-query.php) interface. It’s so awful and dangerous that it was removed in PHP 7. A replacement like [PDO is not hard to learn](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/) and a guide like [PHP The Right Way](http://www.phptherightway.com/) explains best practices. Your user parameters are **not** [properly escaped](http://bobby-tables.com/php) and there are [SQL injection bugs](http://bobby-tables.com/) that can be exploited. – tadman Sep 04 '16 at 10:18
  • First I need to click edit and IT will be re diracted to my firstpage. Normail html code I tried IT is not helping becoz in program inside echo I wrote HTML – Sukki Sep 04 '16 at 10:21

1 Answers1

3

If you want to redirect to another page, in form you need to add action="otherpage.php" and in that other file you need to write something like:

if (!empty($_GET['newValue']) {
    mysql_query("update details set name='".$_GET['name']."', age='".$_GET['age']."' WHERE id=".$_GET['id']."");
    header("location: index.php");
    exit;
}

This is approximate approach and there a few things you should change like mysql to mysqli or PDO (because deprecated) with prepared statements and escape all inputs.

Qirel
  • 25,449
  • 7
  • 45
  • 62
  • First I need to click edit and IT will be re diracted to my firstpage. Normail html code I tried IT is not helping becoz in program inside echo I wrote HTML – Sukki Sep 04 '16 at 10:19
  • 1
    @Sukki Sorry, I'm having trouble with understanding how to solve you problem. You may need to post nearly entire code (but only parts where the problem is and covering any sensitive data) so that I could find solution that fits you. (or maybe Yagami's solution is fine too?) – Gynteniuxas Sep 04 '16 at 11:47