Jump to content

not sure what to do with action equals index.php


Go to solution Solved by Barand,

Recommended Posts

Recently I retired and decided to start learning a little about my computer and webpages. I'm doing ok with html and css so I thought I'd look at php.

I seem to learn best by examples and then deconstructing those examples, so I asked the openai for a number randomiser based on the user providing a list of numbers, and it spat out some code, but it references an index.php file, and I don't know what to do.

Can someone guide me to a solution?

Here's my openai prompt:

Create a basic webpage with a text box to accept input from the user, and a button to perform the action. Use HTML & PHP, don't use JS or CSS, to allow the user to input a list of numbers, strip out & remove any and all non-number characters, mix and randomise the numbers, then output the numbers in groups of 5 numbers, separated by a single space, sorted from lowest to highest, each group of 5 numbers is to be on its own line, each group separated by a blank line.

Here's the provided code:

<html>
<head>
    <title>Number Sorter</title>
</head>
<body>
    <form action="index.php" method="post">
        <input type="text" name="numbers" placeholder="Enter numbers here...">
        <input type="submit" name="submit" value="Sort">
    </form>
    <?php
        if(isset($_POST['submit'])) {
            $numbers = $_POST['numbers'];
            $numbers = preg_replace('/[^0-9]/', '', $numbers);
            $numbers = str_split($numbers);
            shuffle($numbers);
            sort($numbers);
            $numbers = array_chunk($numbers, 5);
            foreach($numbers as $number) {
                echo implode(' ', $number) . "<br><br>";
            }
        }
    ?>
</body>
</html>

 

  • Solution

It looks like it expects that code to be in "index.php". The posted data will be sent to that file (itself)

If you remove action="index.php" you can call your php file anything and, without the action, it will call itself.

55 minutes ago, Old_Dog_New_Tricks said:

I seem to learn best by examples and then deconstructing those examples,

That's good.

55 minutes ago, Old_Dog_New_Tricks said:

so I asked the openai

That's not good.

For example, let me point out something: this

shuffle($numbers);
sort($numbers);

randomly shuffles the $numbers and then sorts them in increasing order. It's nonsense, and not the sort of thing you should be trying to learn.

"AI" is good at stringing words together in a way that, according to some calculated probabilities, hopefully make sense. But that is all it does - and it is certainly not intelligent. Be very careful with anything it says or creates.

Thank you Barand, your suggestion worked and it printed the results to the same page.

It took me a bit of searching but I found I had to install apache and then put the file in my var/www/html folder and call it using localhost/filename.

The result from the script in the webpage is not what I expected, but that's another issue/topic and something to play with further before I give up, commence with the gnashing of teech, and beg for further assistance.

3 minutes ago, requinix said:

That's good.

That's not good.

For example, let me point out something: this

shuffle($numbers);
sort($numbers);

randomly shuffles the $numbers and then sorts them in increasing order. It's nonsense, and not the sort of thing you should be trying to learn.

"AI" is good at stringing words together in a way that, according to some calculated probabilities, hopefully make sense. But that is all it does - and it is certainly not intelligent. Be very careful with anything it says or creates.

I agree, the results from the script are not helpful and not what I expected. I used JS first, and it did what I wanted, but the number generation is far from truly being random - there's obvious patterns to the number order generated, so that's why I was looking at php.

This is a first experiment, so I have a bit to learn, obviously, both about php and about even how to correctly prompt the ai to obtain the results for which I'm searching.

I appreciate your words of caution, but it's worth noting I'm not trying to solve any world problems so anything I get from the ai is not going to be the cause of a catastrophe. I'm simply playing around and experimenting to obtain some code to take apart. But, again, I appreciate your cautionary warning.

Using sort will sort numbers. so I if enter 12345 into input box results will be 12345. If I do same thing again then result will be the same. Without using sort, the numbers will be returned in different orders each time using same input of 12345.

However entering more than 5 digits, lets say 1 through 9, then it will return 2 sets of numbers. the first set with 5 numbers and the second set with the remaining 4 numbers. So depending on what you are expecting for results depends on the code you use.

Edited by dodgeitorelse3
typo
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.