0

I've tried and tried, but I can't get this to work. I use Joomla and I have 2 articles/pages, one for edit and one for posting the form. I have a database with all the matches for the World Cup coming up and I want my users to bet on the matches.

I have 2 tables - one with all matches like this (named vm_kampe):

|id |hhold   |uhold   |res  |
|1  |Rusland |Saudi   |NULL |
|2  |Egypten |Uruguay |NULL |
... and so on

and the other table is my coupon where my bets are stored(named vm_207 where 207 is my user-id, so every user gets its own table):

|id |resu |
|1  |2-1  |
|2  |1-3  |
... and so on.

So the id in vm_207 should connect to the id of the match in vm_kampe.

So I want a page, where I can update my bets, so I have this:

foreach($results as $row){     
echo '<div class="vm_kupon_row">     
<div class="vm_id"><input type="hidden" name="kampid[]" value="'.$row->id.'"></div>     
<div class="vm_kampe">'.$row->hhold.' - '.$row->uhold.'</div>     
<div class="vm_result"><input class="vm_resultat" type="text" name="resultat[]" placeholder="X-X" value="'.$row->resu.'"></div>

</div>';

};

echo '<input type="submit" class="godkend-vm-kupon" name="submit" value="Godkend">';

That calls out all matches with an input field where the value is selected from my table vm_207 and it works. Now, if I change something I want to update, the form action calls this page:

$jinput = JFactory::getApplication()->input;
$kampid = $jinput->get('$kampid');
$resultat = $jinput->get('$resultat', 'string');

$fields = array(
$db->quoteName('resu') . ' = ' . $db->quote($resultat)
);

$conditions = array(
$db->quoteName('id') . '=' . $kampid
);

$query->update($db->quoteName('vm_207'))->set($fields)->where($conditions);

But it won't update anything.

Please help me make this work. If you need any more details just say so :)

Thanks!

  • Please do not post links to code, include it in your question as text formatted as code. Make it easy for people to help you, few people will bother to follow a link to help you out. – Sloan Thrasher Apr 3 '18 at 18:47
  • Also, edit your question to show the schema of the tables involved. – Sloan Thrasher Apr 3 '18 at 18:48
  • @SloanThrasher So, I editted my question :) – Daniel Jensen Apr 4 '18 at 11:30
  • 1
    I would just like to say that generating a new table for each user seems like poor architecture. Why wouldn't you just create a single table and dedicate a column for the users' ids? This way you can write simple join queries. If there is a compelling reason to create a bunch of identically structured tables, I'd like to hear it. – mickmackusa Jun 11 '18 at 11:42
  • 1
    Hi @mickmackusa :) You're right - it was bad architecture. I ended up with a single table as you suggested :) I just forgot about this post again afterwards. But I now have one table containing all users bets :) – Daniel Jensen Jun 13 '18 at 10:55
0

It seems to me that you are missing the following lines (which effectively execute the update operation):

$db->setQuery($query);
$result = $db->execute();

Can you check?

  • Wow, I didn't execute the operation :D Jesus ... Thank you :) – Daniel Jensen Apr 12 '18 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.