Can AI really write workable code for me? You bet! ...

A place to discuss anything off topic
Post Reply
User avatar
webtrekker
Posts: 2540
Joined: 06 Sep 2016, 13:02
Contact:

Re: Can AI really write workable code for me? You bet! ...

Post by webtrekker »

No doubt you've all heard of ChatGPT-4, the new, all-singing, all-dancing AI offering from Open AI.

It's claimed, amongst many other things, to be able to produce workable code in many different computer languages from a simple prompt by the user.

Pretty big claim that! So, of course, I had to try it out. Here's my prompt ...


'produce html js and php code for a web page with pin code protection'



And here is the AI's reply (in less than 30 seconds!!!) ...

[CENTER] ++++++++++++++++++++++
[/CENTER]

Sure, here's an example implementation of a web page with pin code protection using HTML, JavaScript, and PHP:

[ATTACH=CONFIG]7137[/ATTACH]

This code defines an HTML page with two sections: a PIN code form and a protected content section. The PIN code form consists of a password input field, a submit button, and an error message that is initially hidden. When the user submits the form, a JavaScript function called checkPin is called. This function sends an AJAX request to a PHP script called check_pin.php to verify the entered PIN code.


Here's an example implementation of the PHP script:

[ATTACH=CONFIG]7138[/ATTACH]


This code defines a PHP script that checks the entered PIN code against a correct PIN code stored in the script. If the entered PIN code matches the correct PIN code, the script outputs the string "true". If the entered PIN code does not match the correct PIN code, the script outputs the string "false".


When the JavaScript function checkPin receives the response from the PHP script, it checks if the response is "true". If the response is "true", the protected content section is displayed and the PIN code form is hidden. If the response is "false", an error message is displayed.


Note that this is just one example implementation of a web page with pin code protection, and there are many other ways to implement this feature using different technologies and programming languages.


[CENTER] ++++++++++++++++++++++
[/CENTER]
That's it!

So I uploaded those files to my server and here's the result [IMPORTANT: The password in this example is 1234 and anything else entered should produce an error - try it!] ...

https://webtrek.co.uk/protected_page.html

Obviously, this is a bare-bones implementation but can easily be enhanced if you can already write your own code or ......... why not ask ChatGPT-4 to enhance it for you to your own specifications!

Who knows where all of this is leading! I have already asked it to produce a couple of other code snippets: for a page that returns the current weather for any input location, and a routine to solve an equation using the Newton-Rhapson method, both of which work flawlessly. The time saved in writing code that works, even if you're a seasoned coder, is fantastic.

'Hey, Grandma! When you get a minute can you write me an ecommerce platform? Pretty please!' (Don't laugh, it's closer than you think!). :wink:
Attachments
vB_ID:7138
vB_ID:7138
2023-03-29_16-00-58.png (7.94 KiB) Viewed 11 times
vB_ID:7137
vB_ID:7137
2023-03-29_16-00-33.jpg (8.19 KiB) Viewed 11 times
User avatar
webtrekker
Posts: 2540
Joined: 06 Sep 2016, 13:02
Contact:

Re: Can AI really write workable code for me? You bet! ...

Post by webtrekker »

Notice that in the above example the password is server-side, in a PHP script, so visitors to the page cannot access the password by simply right-clicking the page and selecting 'View Page Source.'

This is how things should be done. Well done ChatGPT-4!
pisquee
Posts: 4360
Joined: 05 Nov 2011, 17:33
Contact:

Re: Can AI really write workable code for me? You bet! ...

Post by pisquee »

I did see some posts about GPT 3.5 producing Wordpress plugins succesfully ... it's mind boggling that something I'd initially thought would be good for writing copy, can also code.

My kids like asking it to write them stories!
socialgiraffe
Posts: 4597
Joined: 16 Jun 2011, 23:40
Been thanked: 1 time
Contact:

Re: Can AI really write workable code for me? You bet! ...

Post by socialgiraffe »

Nothing to add except Italy has just banner CHATGPT, be interesting to see who else follows...
USING: Whatever it takes to get the job done...
User avatar
webtrekker
Posts: 2540
Joined: 06 Sep 2016, 13:02
Contact:

Re: Can AI really write workable code for me? You bet! ...

Post by webtrekker »

Since my OP I've had the chance to try out the coding efforts of ChatGPT-4 more extensively and it really does a good job of most things providing you ask the right questions. It wil even take a section of code pasted in from your project and tell you where you may have gone wrong and correct it!

At the moment, it's saving me hours of searching StackOverflow, SitePoint, W3Schools or any of the many other sites for answers to coding issues I'm having. Even if it can't supply workable code it will outline the steps you need to take to find a solution.

I might add though, that apart from this interesting aspect of AI, I'm very wary of the consequences should it ever be allowed to run amok and couldn't agree more that the developers should take breaks to discuss and test every aspect of AI development. AI needs power to survive and, at the moment, we control the on/off switches , but if ever that should change ...................................
pisquee
Posts: 4360
Joined: 05 Nov 2011, 17:33
Contact:

Re: Can AI really write workable code for me? You bet! ...

Post by pisquee »

I tried using GPT4 through MSBing to write a post for social for our brand - as I clicked send on the instructions for what I wanted it to write, I realised forgot to tell it which town our shop was in or the type of products we make ... but, no worries, it did an internet search and found out all that info itself and included it in the text it gave for the post.
Previously we've been using Chat GPT 3.5 (rather than 4) and it wouldn't have done that
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest