lostinthemessycode Posted May 27, 2023 Share Posted May 27, 2023 Hi people. I'm a total beginner trying to put together a small project, required to be done in MVC. I have a dropdown (in fact I have two, but I'm trying to tackle down this one first). This dropdown gets its options from the database (which I've managed to get it working just fine). So, the idea is to execute an sql query when the button is pressed... nothing fancy really, but since I have all this code scattered through all these files, it's just a mess altogether. This is the code I have now related to this: This function it's inside class TCars from cars.php file: public function selectCitizen() { $this->abd->query("UPDATE car SET nCitizen = '1000' WHERE ID = (SELECT MIN(ID) FROM car)"); $this->abd->close_query(); } This function it's in the class TControl, in the controller.php file: public function selectCitizen($citizen) { echo "please work"; $citizen = new TCitizen("", "", "", "", "", $citizen, $this->host, $this->user, $this->pass, $this->db); } And this is the case for this particular submit button in view.php: case "Rent": if (isset($_POST["citizen"])) { $ciudadano = $_POST["citizen"]; $c = new TControl(); $res = $c->selectCitizen($citizen); if ($res) { echo ('<html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <body> <center> <h1>Selected Citizen succesfully: <br>'.$ciudadano.' <br></h1> <br> <br>'); echo ($res); echo ('<br><a href="index.html"> Back to index </a></center></body></html>'); } else { showError("Citizen couldn't be selected: $ciudadano"); } } break; The more I've managed until now has been to get showError to show, beyond that it's just a lot of undefined, fatal and warning errors, as expected. I'd really appreciate any insight on this. Thank you for reading me. Quote Link to comment Share on other sites More sharing options...
lostinthemessycode Posted May 27, 2023 Author Share Posted May 27, 2023 *My code is in my native language, I translated it to post it here and made a mistake here: <h1>Selected Citizen succesfully: <br>'.$ciudadano.' <br></h1> So please read it as $citizen instead of $ciudadano. I can't seem to edit the post now, sorry. Please don't count it as a mistake in the code. I have 99 problems, but that's not one of them 😅 Quote Link to comment Share on other sites More sharing options...
requinix Posted May 28, 2023 Share Posted May 28, 2023 What are you trying to execute? When what button is pressed? And what is your question that we can help you with? Quote Link to comment Share on other sites More sharing options...
lostinthemessycode Posted May 28, 2023 Author Share Posted May 28, 2023 What I was trying to execute is the sql query, as I said above, that can be seen in the first code. The button is working fine, but it's connected to the case I'm showing, which wasn't working. And the question I thought it was obvious, sorry, was to help me get out of the mess of those three codes in three different files that weren't comunicating between each other properly. I somehow managed yesterday to get it to work. Not perfectly and not what I need yet, but at least executing the query well. So if there's a way to close this thread, I would appreciate it. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 28, 2023 Share Posted May 28, 2023 Do you mean that you have it outputting "please work" at the moment you want to? The only things wrong with that second piece of code are (1) it doesn't call $citizen->selectCitizen() and (2) it's supposed to return a value ($res) that you can use to determine if it worked. You haven't really shown very much of your code, but it doesn't feel like standard MVC so far... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.