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
Error when updating table with 0
#1
Hi,
I'm having a weird issue and hoping to get some help on it.

I'm using a form to update a MySQL table with something like the code below, where I (1) get a posted value (2) validate it, and (3) update the table. It works great, but there's an issue. Whenever 0 (zero) is sent, it throws an error, in this case saying that "Chapter number is required". I have no problems inserting a 0 into the MySQL table when I do it manually. I assume I've done something wrong in the validation. Any suggestions?

(Couldn't figure out how to insert multi-line code in the forums?)

$chapternum = Input::get('chapternum');

$fields=array('chapternum'=>$chapternum);
$validation->check($_POST, array(
'chapternum' => array(
'display' => 'Chapter Number',
'required' => true
)
));
if($validation->passed()){
$db->update('comic_chapters',$id,$fields);
$successes[] = "Chapter Number Updated";
}else{
?><div id="form-errors">
<?=$validation->display_errors();?></div>
<?php
}
  Reply
#2
I've had this happen before to, and dropped my "required" value and it fixed it. Definitely something in particular to the validation class. @Mudmin @karsen - any thoughts?
  Reply
#3
Hmm. I've never come across this before.

Are you getting an error about the field being required?

Looking at users/classes/Valdidate.php I see that line 46 says
Code:
if ($rule==='required'  &&  $length==0) {

I'm wondering if that length needs to be changed to ===

Can you see if that fixes your problem?
Sorry for the delay. Power is out here in my part of Alaska so communications are minimal.
  Reply
#4
I have no qualms with removing the required field if need be, but of course would love to find the issue.

Thanks so much for the responses.

My users/classes/Validate.php doesn't have that line at 46. But I do have at line 38:
Code:
if ($rule === 'required' && empty($value))

Code:
$length
has not been defined in my script, so I can't change it to
Code:
$length===0

I just redownloaded 4.2.10 from the main site to be sure I have the right version, and yes, line 38 is what is in my current Validate.php

Good luck with the power outages and thanks again for the timely response.

-Gaius
  Reply
#5
Oooh. I forgot. I was looking at the new Validate.php from 4.3 alpha.

What about the latest Validate.php?
https://pastebin.com/yhbEyKYh

If that doesn't work...what about the line 46 change on the one I just sent you?

We've done extensive reworking of the validate class and may have already fixed the issue.
  Reply
#6
I replaced my Validate.php with the US 4.3 version of Validate.php given at https://pastebin.com/yhbEyKYh and the problem is now fixed. The line 46 change was not necessary.

Thanks so much! I'm almost ready for my project to go live. Thanks again for all the help and hard work.
  Reply
#7
Awesome! Glad it worked!
  Reply
#8
Function
Code:
empty
returns true if passed argument is "0". That's why I replaced it with
Code:
strlen
.

>I’m wondering if that length needs to be changed to ===
No. Actually why
Code:
$rule===required
is there? I'll replace identical with equal.
  Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)