Web Application Help needed

SohaibArif

Proficient
Apr 10, 2008
666
0
21
Karach,i Pakistan
Salams,
I am making an inventory management web app as a personal project and I need help with deciding on the back end.

Firstly, I have no formal training in web development, I used the missing manual php book and Rob Percival's udemy course to make my FYP and am only using free online resources, mostly Youtube, to continue the learning parts of this.

I am currently using a kind of fake REST api as PUT and DELETE requests give a 405 "Request not allowed" error. So I did used POST and some flags( I don't know the proper term if there is one) like this instead:

PHP:
if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        require_once('../../../scripts/database_connection.php');
        if(isset($_POST["edit_id"]) && isset($_POST["name"]) && isset($_POST["description"]))
        {
            $id = trim(mysqli_real_escape_string($link, $_POST["edit_id"]));
            $name = trim(mysqli_real_escape_string($link, $_POST["name"]));
            $description = trim(mysqli_real_escape_string($link, $_POST["description"]));
            
            $data = edit_item($link, $id, $name, $description);
            deliver_response(200,"item edited", $data);            
        }
        else if(!isset($_POST["edit_id"]) && isset($_POST["name"]) && isset($_POST["description"]))
        {            
            $name = trim(mysqli_real_escape_string($link, $_POST["name"]));
            $description = trim(mysqli_real_escape_string($link, $_POST["description"]));
            
            $data = add_item($link, $name, $description);
            deliver_response(200,"item added", $data);
            
        }
        else if(isset($_POST['delete_id']))
        {
            $id = trim(mysqli_real_escape_string($link, $_POST["delete_id"]));
            $data = delete_item($link, $id);
            deliver_response(200,"item deleted", $data);
        }
        else
        {
            deliver_response(200,"NO DATA ENTERED",NULL);
        }
    }
It is working perfectly but he problem is, more complex data is to be retrieved and sent later and I am not sure I should continue with this messy kind of solution.

Error handling is also a mess for me in PHP/javascript as I don't know any if tools exist for it. I mistakenly used mysql_query instead of mysqli_query due to notepad++'s built in suggessions and spent almost an hour before figuring out why the edit_item function was not working. I really don't want to run into that kind of stupidity again.

Writing so much code to just get some simple data also seems like I am doing something wrong.

I could abandon the PHP version and start on ASP.net or Java or even learn Ruby but then the problem is with hosting the back end but then hosting may become a problem.

Can someone suggest how I continue this?
 

gullfounder

Phoenix Dawn
Supervisor
Aug 25, 2008
970
3
24
Khanpur
Salams,
I am making an inventory management web app as a personal project and I need help with deciding on the back end.

Firstly, I have no formal training in web development, I used the missing manual php book and Rob Percival's udemy course to make my FYP and am only using free online resources, mostly Youtube, to continue the learning parts of this.

I am currently using a kind of fake REST api as PUT and DELETE requests give a 405 "Request not allowed" error. So I did used POST and some flags( I don't know the proper term if there is one) like this instead:

PHP:
if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        require_once('../../../scripts/database_connection.php');
        if(isset($_POST["edit_id"]) && isset($_POST["name"]) && isset($_POST["description"]))
        {
            $id = trim(mysqli_real_escape_string($link, $_POST["edit_id"]));
            $name = trim(mysqli_real_escape_string($link, $_POST["name"]));
            $description = trim(mysqli_real_escape_string($link, $_POST["description"]));
            
            $data = edit_item($link, $id, $name, $description);
            deliver_response(200,"item edited", $data);            
        }
        else if(!isset($_POST["edit_id"]) && isset($_POST["name"]) && isset($_POST["description"]))
        {            
            $name = trim(mysqli_real_escape_string($link, $_POST["name"]));
            $description = trim(mysqli_real_escape_string($link, $_POST["description"]));
            
            $data = add_item($link, $name, $description);
            deliver_response(200,"item added", $data);
            
        }
        else if(isset($_POST['delete_id']))
        {
            $id = trim(mysqli_real_escape_string($link, $_POST["delete_id"]));
            $data = delete_item($link, $id);
            deliver_response(200,"item deleted", $data);
        }
        else
        {
            deliver_response(200,"NO DATA ENTERED",NULL);
        }
    }
It is working perfectly but he problem is, more complex data is to be retrieved and sent later and I am not sure I should continue with this messy kind of solution.

Error handling is also a mess for me in PHP/javascript as I don't know any if tools exist for it. I mistakenly used mysql_query instead of mysqli_query due to notepad++'s built in suggessions and spent almost an hour before figuring out why the edit_item function was not working. I really don't want to run into that kind of stupidity again.

Writing so much code to just get some simple data also seems like I am doing something wrong.

I could abandon the PHP version and start on ASP.net or Java or even learn Ruby but then the problem is with hosting the back end but then hosting may become a problem.

Can someone suggest how I continue this?
Well, I am not the the pro in PHP. but i can tell you this is that, you need to create objects. Like Functions in C that should do the repeated task. and Group then in a Class. So, you wont have to write the code again and again. This will help you alot in Long run. But in start yes that will take time. But Once the foundation are built. Its easy to create anything on it.

For Example.

You could create a function that will insert data into any given table. So, when ever u need to insert data just call that Function and Done.
 

SohaibArif

Proficient
Apr 10, 2008
666
0
21
Karach,i Pakistan
Php is not an object oriented language as far as I know, it can only be forced to kind of act like them.
And I already have functions for fetching, editing and deleting data in a different file as seen in the given snippet.
 

furball

Well-known member
Nov 18, 2008
2,074
0
41
34
Lahore
Php is not an object oriented language as far as I know, it can only be forced to kind of act like them.
And I already have functions for fetching, editing and deleting data in a different file as seen in the given snippet.
php is an object oriented language not advance like java c#. But mvc based frame work are very popular and complex products can be made using php oop.. And use net beans or any good ide for development. Put support is not that good in php .To avoid these long flags check u can put specified parameter based on request type. u can use jquery for that...
 

SohaibArif

Proficient
Apr 10, 2008
666
0
21
Karach,i Pakistan
php is an object oriented language not advance like java c#. But mvc based frame work are very popular and complex products can be made using php oop.. And use net beans or any good ide for development. Put support is not that good in php .To avoid these long flags check u can put specified parameter based on request type. u can use jquery for that...
Thanks.
As I had no formal training in web development, I did not know Netbeans could be used with anything other than Java and maybe C++ or that MVC is supported in PHP.

Will I have to use WAMP even with Netbeans? I am currently uploading my PHP code directly to the live server instead because I kind of find WAMP to be too much of a hassle if a project is non-critical.
 

furball

Well-known member
Nov 18, 2008
2,074
0
41
34
Lahore
yes net beans has good support of php. Download netbeans complete package. It even support's javascript. Yes u need to use WAMP with netbeans. WAMP sometimes create problems during installation on some pc's . SO u can use xamp.
 
General chit-chat
Help Users
We have disabled traderscore and are working on a fix. There was a bug with the plugin | Click for Discord
  • No one is chatting at the moment.
    NaNoW NaNoW: so Baldurs Gate 3 is pretty great!"