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.

3

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.