Jump to content

Recommended Posts

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.

*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 😅
 

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.

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...

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.