Jump to content

PHP - Ajax Passing value to another php file


aveeva

Recommended Posts

@Barand    That line okay, i got it, no confusion.  My confusion about how can i use in below code,

 

        <?php
       session_start();
      foreach ($_SESSION['playlist'] as $key => $value) {
        echo "<tr>";
        echo "<td>" . $key . "</td>\n<td>" . $value . "</td>";

            //  code....

        echo "</tr>";    
        }
        ?>

 

Link to comment
Share on other sites

@Barand   If i ask any stupid question, make me a pardon, i am learning in php.

 

        <?php
       session_start();
      foreach ($_SESSION['playlist'] as $key => $value) {
        echo "<tr>";
        echo "<td>" . $key . "</td>\n<td>" . $value . "</td>";

        echo "<td>" ."<button class='delbtn' data-id='"+ k +"'>Delete</button>" . "<td>";


        echo "</tr>";    
        }

        ?>

Pls correct me?

Link to comment
Share on other sites

On 7/2/2019 at 12:25 PM, aveeva said:

$statement = $connect->prepare($query);

$statement->execute();

$result = $statement->fetchAll();

$total_row = $statement->rowCount();

$output = '';

In this excerpt from your code, all lines except the execute() are assigning values - you know how to assign in PHP.

Link to comment
Share on other sites

How is this button going to work?  What is it calling? How is the current row of data being passed to whatever script is going to do the delete?

I suggest a form around each row and a proper Submit button (<input type='submit'>) that will do what you need.  Using the <button> tag is just not that useful even though people love to use it.  I don't get it.

Link to comment
Share on other sites

27 minutes ago, ginerjm said:

How is this button going to work?  What is it calling? How is the current row of data being passed to whatever script is going to do the delete?

If you read the previous posts and code in this topic before jumping in, all those questions will be answered.

Link to comment
Share on other sites

@Barand    If i click delete button whole list will be deleted,  how to delete by single,

 

<html>
<head>

    <style type="text/css">
        table {
            border-collapse: collapse;
            border: 1px solid black;
        }
        table td,th {
            border: 1px solid black;
        }
        td {
            text-align: center;
        }
    </style>
</head>

<body>

    <h2>Play Lists</h2>

    <table id="table">
        <th>Voice SKU</th>
        <th>Voice Name</th>
        <th>Action</th>
    

        <?php
       session_start();
      foreach ($_SESSION['playlist'] as $key => $value) {
        echo "<tr>";
        echo "<td>" . $key . "</td>\n<td>" . $value . "</td>";
        echo "<td>". "<button id='btn'>Delete</button>"."</td>";
        echo "</tr>";    
        }

        ?>
    </table>
    <script>

     var btn = document.getElementById('btn');
    btn.onclick = function () {
    document.getElementById('table').remove();
    this.remove();
};
    
        </script>
</body>
</html>

 

Link to comment
Share on other sites

help me with my workout :  

my_cart.php: 

    <?php
    header('Content-Type: text/html; charset=utf-8');
    session_start();
    session_regenerate_id();

    echo '
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <metaname="viewport"content="width=device-width,height=device-height,initial-scale=1">
            <title>Playlist</title>
        </head>

        <body>
            <form id="playlist" action="playlist_action.php" method="post">
                <table id="playlist">
                    <caption>Play List</caption>
                    <thead>
                        <tr>
                            <th scope="col">Voice SKU</th>
                            <th scope="col">Voice Name</th>
                            <th scope="col">Action</th>
                        </tr>
                    </thead>

                    <tbody>';
                        foreach ($_SESSION['playlist'] as $key => $value) 
                        {
                            $key = htmlspecialchars($key);
                            echo '
                            <tr>
                                <th scope="row">', $key, '</th>
                                <td>', htmlspecialchars($value), '</td>
                                <td><button name="delete" value="', $key, '">Delete</button></td>
                            </tr>';
                        }
                        echo '
                    </tbody>
                </table>
            </form>
        </body>
    </html>

 

 

playlist_action.php

 

<?php
header('Content-Type: text/html; charset=utf-8');
session_start();
session_regenerate_id();

if (array_key_exists('playlist_action', $_POST)) {
	switch ($_POST['playlist_action']) {
		case 'delete':
			if (array_key_exists($_POST['delete'], $_SESSION['playlist']) {
				unset($_SESSION['playlist'][$_POST['delete']]);
                // notify user of successful delete
			} else {
				// notify user of non-existent key in the playlist
			}	
		default:
			// handle invalid/unknown action here.
	}
}
?>

my output:

|Parse error: syntax error, unexpected 'unset' (T_UNSET) in C:\wamp\www\voice_bank\playlist_action.php on line  *10*|

Edited by aveeva
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.