0

My index.php looks like this:

<body>
    <p id="message"></p>
    <form method="post" id="insert_form">
        <table cellpadding="5" cellspacing="5">
            <tr>
                <th>Enter Name</th>
                <td>
                    <input type="text" id="name" name="name">
                </td>
            </tr>
            <tr>
                <th>Enter Email</th>
                <td>
                    <input type="email" id="email" name="email">
                </td>
            </tr>
            <tr>
                <th>Enter Contact</th>
                <td>
                    <input type="text" id="contact" name="contact">
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="button" id="submit" name="insert" value="Insert">

                    <input type="button" id="load" name="insert" value="Load">
                </td>
            </tr>   
        </table>
    </form>

    <div id="result">

    </div>
</body>

So when I click on load, I display the data with the code from my select.php using ajax which looks like this:

<?php
    mysql_connect("localhost","root","");
    mysql_select_db("blackboard");
    $sqlstmt = "SELECT * FROM student";
    echo "<table><tr><th>ID</th><th>Name</th><th>Email</th><th>Contact</th></tr>";
    if( $data = mysql_query($sqlstmt)){
        while($row = mysql_fetch_assoc($data)){
            echo "<tr><td>$row[id]</td><td>$row[name]</td><td>$row[email]</td><td>$row[contact]</td><td><a href='../update/index.php?id=$row[id]&name=$row[name]&email=$row[email]&contact=$row[contact]'>Update</a></td>
                </tr>";
        }
    } else{
        echo mysql_error();
    }
?>

My ajax code in select.php looks like this:

<?php
    mysql_connect("localhost","root","");
    mysql_select_db("blackboard");
    $sqlstmt = "SELECT * FROM student";
    echo "<table><tr><th>ID</th><th>Name</th><th>Email</th><th>Contact</th></tr>";
    if( $data = mysql_query($sqlstmt)){
        while($row = mysql_fetch_assoc($data)){
            echo "<tr><td>$row[id]</td><td>$row[name]</td><td>$row[email]</td><td>$row[contact]</td><td><a href='../update/index.php?id=$row[id]&name=$row[name]&email=$row[email]&contact=$row[contact]'>Update</a></td>
                </tr>";
        }
    } else{
        echo mysql_error();
    }
?>

Up to now I can view the data as the image shows and I have the update button already:

enter image description here

My question is: Still using ajax, How can update a record when clicking on the update button?

I am trying my first CRUD application using ajax so I hope my question is clear enough and that you can help.

Thanks in advance.

Sidney Sousa
  • 3,378
  • 11
  • 48
  • 99
  • 1
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jun 16 '17 at 13:19
  • I do know bout PDOs. My major concern is just in making the function work becauseas you can see there is no even validation..later I will change. – Sidney Sousa Jun 16 '17 at 13:22
  • You are expected to try to **write the code yourself**. After [**doing more research**](https://meta.stackoverflow.com/q/261592/1011527) if you have a problem **post what you've tried** with a **clear explanation of what isn't working** and provide [a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Read [How to Ask](http://stackoverflow.com/help/how-to-ask) a good question. Be sure to [take the tour](http://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/q/347937/1011527). ***There is no AJAX code here.*** – Jay Blanchard Jun 16 '17 at 13:25

0 Answers0