S
S
Sergey2020-12-30 18:08:48
PHP
Sergey, 2020-12-30 18:08:48

How to write 0 to database in float from input value?

Good afternoon, there is a field for entering numbers

<input name="c_score" value="<?php echo $data['lists']['c_score'];?>" type="text" class="inputbox" />

also button
<input type="button" value="Apply" onclick="javascript: document.adminForm.id.value='<?php echo $data['lists']['id']; ?>'; document.adminForm.stu_id.value='<?php echo $data['lists']['qid']; ?>'; submitbutton('quest_reportA');" />

there is also update tables

$mainframe = JFactory::getApplication();
    $database = JFactory::getDBO();
    $jinput = $mainframe->input;
    $c_score = $jinput->get('c_score', 0, 'INT');
......

 $remark = JFactory::getApplication()->input->getRaw('remark', '');

            $c_score = (float)$c_score;


      $query = "UPDATE #__quiz_r_student_question SET c_score = '".$c_score."', `remark` = ".$database->Quote($remark).", reviewed = 1 WHERE c_id = '".$data['id']."'";
      $database->SetQuery( $query );
      $database->execute();

The question is, when entering manually into input 0,0, the value will be saved to the base as 0. But if you enter just 0 (without a comma), then it does not save. Tried removing $c_score = (float)$c_score;
but nothing changes also does not save. Can anyone come across types or transformations?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Makhov, 2020-12-30
@Igorgro

Learn to use prepared statement(parameterized query)

N
nokimaro, 2020-12-30
@nokimaro

$c_score = $jinput->get('c_score', 0, 'STRING');
$c_score = str_replace(',', '.', $c_score);
//...
$c_score = (float)$c_score;
//$query = "UPDATE ...

S
Sergei Tolkachev, 2021-01-06
@sergeytolkachyov

Read https://cmscafe.ru/docs/joomla/developer/api/627-j...
Should help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question