The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problems using db->update
#1
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>
  Reply
#2
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?
  Reply
#3
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.
  Reply
#4
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!
  Reply
#5
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!
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)