The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
problems using db->update - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: problems using db->update (/showthread.php?tid=938)



problems using db->update - s.farg - 02-07-2018

Hi,

I'm new to web development, but in the last couple of days I learned a lot with the help of this forum and the documentations. Thanks!

Currently I'm encountering a problem when I try to use the $db->update() method. The table which I want to update is called u_schueler. The first column in my table is called 'id'. I want to update the column 'attestpflicht' and change the value from 0 to 1.

Here is a picture of the table u_schueler viewed with phpMyadmin: [Image: unbenanntavknv.jpg]

I'm using the following code:




<pre>
Code:
<?php
require_once 'users/init.php';

$i=1;
$fields = ['attestpflicht' => 1];
$db->update("u_schueler",$i,$fields);?>
</pre>





When I reload the .php page I don't get an error message but the database is not updated.

Do you have any suggestions?

Simon Smile

Edit: I tried the same with the "users" datatable but nothing happened either:
<pre>
Code:
$i=7;
$fields = [
  'logins' => 4];
$update = $db->update('users',$i,$fields);
</pre>



problems using db->update - mudmin - 02-07-2018

That code works fine for me. Note that the $i=1 is the row of the database, so your example above would fail if you didn't have a user with the id of 7.

Does your table u_schueler have a column called id that is set to int(11) and set to auto_increment the value every time a new row is in? Is there a row in u_schueler with an id of 1?


problems using db->update - s.farg - 02-07-2018

Shame on me, it works like a charm. I started php with <? instead of <?php which obviously won't work. Hrm hrm, sorry for messing with your time!

Edit: I didn't see the error messages because they were hidden behind the navbar. I didn't do any html tags in my test-file.


problems using db->update - mudmin - 02-07-2018

ahh. Yeah. I always test php in the body if I'm not sure what's going on. Or put a couple of



Glad you got it figured out!



problems using db->update - s.farg - 02-07-2018

Thanks Smile Yeah you're right! Gonna test things with a complete html body now. Thanks to the db-class and the useful dump()-feature I made huge steps on how to read/write databases. I even managed to add a little Javascript for suggestions while you type in an input-form based on database entrys (I think this usually called typeahead).

With the brandnew 4.3.13 update I can now disable registration Smile I'm really looking forward to the 2FA-feature. Then my project even meets the harsh german data protection requirements for dealing with student data (btw: I don't know any school that does that with their online module). Thank you for your massive commitment!