PHP

php – How to create a form to save into sql, sort, retrieve and export to excel


I was just getting started with PHP, MySQL and phpmyadmin.

The reason I want to learn is to have a books database of my own.

I want to create a HTML / PHP form where I can enter the books entry (stock received). Then I want them to store in MySQL. Once I have enough books I want to export them into excel using PHP or HTML by sorting / filtering required data from the database and export them into excel.

They key thing is before all I have to save all my books titles in the database. Later by using the form I want to save the stock received into respective titles with a ability to even view and delete the stock whenever required for specific title (add stock / delete stock).

Any guidence is highly appreciated.

Regards
Narendra S



لینک منبع

php – Query not updating in the right column properly?


I was able to figure out my previous problem, but now I don’t this problem. When I go to update a column, it successfully updates. The problem is that it shows up on the incorrect image. I want to add a comment system for images. I feel like it has something to do with the name in the HTML.

$username = $_SESSION['username'];
        $db = mysqli_connect("localhost", "root", "", "db");
        $sql = "SELECT * FROM user_images WHERE username = '$username' ORDER BY id DESC";
        $result = mysqli_query($db, $sql);
            echo '<div class="hero">';
            echo '<div class="hero-content">';
            echo '<div class="row">';


    while ($row = mysqli_fetch_array($result)) {
        echo'
            <div class="social-img hide-750">
            <div class="social-content">
            <a href="http://stackoverflow.com/profiles/uploads/".$row["images"].'" data-caption="Uploaded by: '.$row["username"].'" data-fancybox="quote">
              <img src="http://stackoverflow.com/profiles/uploads/".$row["images"].'">
              </a>
              <p> '.$row["note"].'<br></p>
              <div class="share">
                        <form name="query" class="form1" id="query" enctype="multipart/form-data" action="update_note" method="post">
                        <a href="#" ><i class="fa fa-comment-o" aria-hidden="true"></i></a>
                        <textarea id="message" name="note" placeholder="Update your note..." rows="5" cols="10" name="message"></textarea>
                        <button name="submitOne"action="update_note" method="post"</button>
                        </form>
              </div>
              </div>
              </div>';

    }


    echo '</div>';
    echo '</div>';
    echo '</div>';

Here is the update_note.php. You may see something odd like how I named each one. I did that because I thought that may be the problem, but no.

    $username = $_SESSION['username'];
       $note = $_POST['note'];
       $dbh = mysqli_connect("localhost", "root", "", "db");
        $sqli = "SELECT * FROM user_images WHERE username = '$username' ORDER BY id DESC";
        $resultt = mysqli_query($dbh, $sqli);
        $roww = mysqli_fetch_array($resultt);
        $images = $roww['images'];
        $id = $roww['id'];
if (isset($_POST['submitOne'])) {
        $db = mysqli_connect("localhost", "root", "", "db");
        $sql = "UPDATE user_images SET note='$note' WHERE username='$username' AND id='$id' AND images='$images'";
        mysqli_query($db, $sql);
        header("Location: personal_profile?notesuccess");
    } else {
    }

So when I comment something it goes to update_note, finds where username = username, id = id, and images = images(Which is the name of the image.) This may not be the correct way to do this I believe. If so, I would like some help on that as well. Much appreciated for any support!



لینک منبع

php 7.1 – PHP 7.1 on Ubuntu with Attempted to load class “DOMDocument” from the global namespace


I am stuck with:

ClassNotFoundException in XmlUtils.php line 52:
Attempted to load class “DOMDocument” from the global namespace.
Did you forget a “use” statement?
in XmlUtils.php (line 52)

I am running a Symfony LTS application 2.8 in a docker container with Apache/2.4.18 (Ubuntu) and PHP 7.1.9-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Sep 2 2017 05:56:43) ( NTS )

and tried:

  • clearing cache
  • installing php7.1-xml and restarting
  • installing php-xml and restarting
  • installing php7.1-dom and restarting
  • installing php7.1-intl and restarting
  • removing xdebug and restarting

Modules installed:
php -m

PHP Modules
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    imap
    intl
    json
    libxml
    mbstring
    mysqli
    mysqlnd
    openssl
    pcntl
    pcre
    PDO
    pdo_myser
    wddx
    xml
    xmlreader
    xmlrpc
    xmlwriter
    xsl
    Zend OPcache
    zip
    zlib

    [Zend Modules]
    Zend OPcache



لینک منبع

php – YII2 create function doesn’t send data to database


after my last question I’ve been working on an invoice in yii2 and came accross a new problem. after you fill in the form and click create it doesn’t really do anything except refreshing the page and clearing the product fields, however the personal info like company name and date ect is after the refresh still filled in… also when i check the database nothing happened. could you please take a look at the code below?

the invoice form

    <?php

use yiihelpersHtml;
use yiiwidgetsActiveForm;
use wbragancadynamicformDynamicFormWidget;
use kartikdatecontrolModule;
use kartikdatecontrolDateControl;
use kartikselect2Select2;
use yiihelpersArrayHelper;
use appmodelsCompanies;
use appmodelsSpokepersons;



/* @var $this yiiwebView */
/* @var $model appmodelsFacturen */
/* @var $form yiiwidgetsActiveForm */
?>

<div class="facturen-form">

    <?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>

    <?= $form->field($model, 'company_name')->widget(Select2::classname(), [
    'data' => ArrayHelper::map(Companies::find()->all(), 'company_id', 'company_name'),
    'language' => 'nl',
    'options' => ['placeholder' => 'Selecteer een bedrijf'],
    'pluginOptions' => [
        'allowClear' => true
    ],
])?>

    <?= $form->field($model, 'spokes_person')->widget(Select2::classname(), [
    'data' => ArrayHelper::map(Spokepersons::find()->all(), 'person_id', 'first_name'),
    'language' => 'nl',
    'options' => ['placeholder' => 'Selecteer een contactpersoon'],
    'pluginOptions' => [
        'allowClear' => true
    ],
])?>

    <?= $form->field($model, 'date')->widget(DateControl::classname(), [
    'type' => 'date',
    'ajaxConversion' => true,
    'autoWidget' => true,
    'widgetClass' => '',
    'displayFormat' => 'php:d-F-Y',
    'saveFormat' => 'php:Y-m-d',
    'saveTimezone' => 'UTC',
    'displayTimezone' => 'Europe/Amsterdam',
    'saveOptions' => [
        //'label' => 'Input saved as: ',
       // 'type' => 'text',
        'readonly' => true,
        'class' => 'hint-input text-muted'
    ],
    'widgetOptions' => [
        'pluginOptions' => [
            'autoclose' => true,
            'format' => 'php:d-F-Y'
        ]
    ],
    'language' => 'nl'
]) ?>

    <div class="row"> 
        <div class="panel-body">
             <?php DynamicFormWidget::begin([
                'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
                'widgetBody' => '.container-items', // required: css class selector
                'widgetItem' => '.item', // required: css class
                'limit' => 999, // the maximum times, an element can be cloned (default 999)
                'min' => 1, // 0 or 1 (default 1)
                'insertButton' => '.add-item', // css class
                'deleteButton' => '.remove-item', // css class
                'model' => $modelProducten[0],
                'formId' => 'dynamic-form',
                'formFields' => [
                    'product_id',
                    'product_name',
                    'amount',
                    'price',
                ],
            ]); ?>

            <div class="container-items"><!-- widgetContainer -->
            <?php foreach ($modelProducten as $i => $modelProduct): ?>
                <div class="item panel panel-default"><!-- widgetBody -->
                    <div class="panel-heading">
                        <label class="panel-title pull-left">Product</label>
                        <div class="pull-right">
                            <button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
                            <button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="panel-body">
                        <?php
                            // necessary for update action.
                            if (! $modelProduct->isNewRecord) {
                                echo Html::activeHiddenInput($modelProduct, "[{$i}]id");
                            }
                        ?>
                        <div class="row">
                            <div class="col-sm-3">
                        <?= $form->field($modelProduct, "[{$i}]product_id")->textInput(['maxlength' => true]) ?>
                            </div>
                            <div class="col-sm-3">
                                <?= $form->field($modelProduct, "[{$i}]product_name")->textInput(['maxlength' => true]) ?>
                            </div>
                            <div class="col-sm-3">
                                <?= $form->field($modelProduct, "[{$i}]amount")->textInput(['maxlength' => true]) ?>
                            </div>
                            <div class="col-sm-3">
                                <?= $form->field($modelProduct, "[{$i}]price")->textInput(['maxlength' => true]) ?>
                            </div>
                        </div><!-- .row -->
                    </div>
                </div>
            <?php endforeach; ?>
            </div>
            <?php DynamicFormWidget::end(); ?>
        </div>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
</div>

i figured this wasn’t the problem because the form works but still it might be handy.

the create function

public function actionCreate()
    {
        $model = new Facturen();
        $modelProducten = [new Producten];
        if ($model->load(Yii::$app->request->post()) && $model->save()) 
        {
            $modelProducten = Model::createMultiple(Producten::classname());
            Model::loadMultiple($modelProducten, Yii::$app->request->post());

            // validate all models
            $valid = $model->validate();
            $valid = Model::validateMultiple($modelProducten) && $valid;

            if ($valid) {
                $transaction = Yii::$app->db->beginTransaction();
                try {
                    if ($flag = $model->save(false)) {
                        foreach ($modelProducten as $modelProduct) 
                        {
                            $modelProduct->factuur_id = $model->id;
                            if (! ($flag = $modelProduct->save(false))) {
                                $transaction->rollBack();
                                break;
                            }
                        }
                    }
                    if ($flag) {
                        $transaction->commit();
                        return $this->redirect(['view', 'id' => $model->id]);
                    }
                } catch (Exception $e) {
                    $transaction->rollBack();
                }
            }
        } 
        else {
            return $this->render('create', [
                'model' => $model,
                'modelProducten' => (empty($modelProducten)) ? [new Producten] : $modelProducten
            ]);
        }
    }

and finally the Model.php

<?php

namespace appmodels;
use Yii;
use yiihelpersArrayHelper;

class Model extends yiibaseModel
{
    /**
     * Creates and populates a set of models.
     *
     * @param string $modelClass
     * @param array $multipleModels
     * @return array
     */
    public static function createMultiple($modelClass, $multipleModels = [])
    {
        $model    = new $modelClass;
        $formName = $model->formName();
        $post     = Yii::$app->request->post($formName);
        $models   = [];

        if (! empty($multipleModels)) {
            $keys = array_keys(ArrayHelper::map($multipleModels, 'id', 'id'));
            $multipleModels = array_combine($keys, $multipleModels);
        }

        if ($post && is_array($post)) {
            foreach ($post as $i => $item) {
                if (isset($item['id']) && !empty($item['id']) && isset($multipleModels[$item['id']])) {
                    $models[] = $multipleModels[$item['id']];
                } else {
                    $models[] = new $modelClass;
                }
            }
        }

        unset($model, $formName, $post);

        return $models;
    }
}

I hope you guys can spot the probelm in my code, and please tell me what I did wrong when you find a probelem. I’m trying to learn this framework and don’t really want to give up



لینک منبع

php – get the session array value


I have created a session in a module and debug using watchdog in drupal 7

In module file I have created as

$_SESSION["celeType"] = $cele;
$_SESSION["count"] = $count;
watchdog('popup',print_r($_SESSION,TRUE));

In my dblog I got value as
Array ( [celeType] => Birthday [count] => 1 )

In my tpl I have printed as
echo $cele=$_SESSION[“celeType”];
echo $count=$_SESSION[“count”];

This doesn’t print any value.What I did wrong.



لینک منبع

While Updating database using PHP white screen display


I have been working on a project and i am at the final stages of the project. My problem is whenever i try to update data in my database table into returns a blank screen with no error messages. Please find the php script and html form (the form responsible for updating the database table) below, i have divided it

<?php
Session_start();
if(!isset($_SESSION['username'])){
header('Location: login.php');
}
?>


<!DOCTYPE html>
<html lang="en">
    <head>
        <?php include('config/mm.php')?>
        <?php include('config/db.php')?>
        <?php include('config/function.php')?>
        <?php include('config/setup.php')?>
        <?php include('config/head.php')?>


    <?php
    mysqli_set_charset ($dbc,'utf8');
    if(isset($_GET['edit'])) {

        $edit_id = $_GET['edit'];

        $edit_query = "select * from contact where id='$edit_id'";

        $run_edit = mysqli_query($dbc, $edit_query); 

        while ($edit_row = mysqli_fetch_array($run_edit)){


            $id = $edit_row['id'];
            $title = $edit_row['title'];
            $header = $edit_row['header'];
            $header1 = $edit_row['header1'];
            $body = $edit_row['body'];
            $body1 = $edit_row['body1'];
            $body2 = $edit_row['body2'];
            $body3 = $edit_row['body3'];
            $body4 = $edit_row['body4'];
            $body5 = $edit_row['body5'];
    }
    }
    ?>


</head>
<body class="nav-md">
    <!-- Side Nav Bar -->
    <div class="container body">
        <?php include('config/sidenav.php')?>
    </div>
    <!-- top navigation -->
    <?php include('config/topnav.php')?>
    <!-- /top navigation -->

    <!-- page content -->
    <div class="right_col" role="main">
        <div class="container">
        <form action="updatecontactus.php?edit_form=<?php echo $id; ?>" method="post" enctype="multipart/form-data">
          <h2>Table</h2>                                                                                      
          <div class="table table-bordered table-responsive">          
          <table class="table">
            <thead>
              <tr>
                <th>#</th>
                <th>Name</th>
                <th>Content</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>3</td>
                <td>header</td>
                <td><textarea class="form-control" type="text" name="header" rows="2"><?php echo $header; ?></textarea></td>
              </tr>
              <tr>
                <td>4</td>
                <td>header1</td>
                <td><textarea class="form-control" type="text" name="header1" rows="2"><?php echo $header1; ?></textarea></td>
              </tr>
              <tr>
                <td>5</td>
                <td>body</td>
                <td><textarea class="form-control" type="text" name="body" rows="2"><?php echo $body; ?></textarea></td>
              </tr>
              <tr>
                <td>6</td>
                <td>body1</td>
                <td><textarea class="form-control" type="text" name="body1" rows="2"><?php echo $body1; ?></textarea></td>
              </tr>
              <tr>
                <td>7</td>
                <td>body2</td>
                <td><textarea class="form-control" type="text" name="body2" rows="2"><?php echo $body2; ?></textarea></td>
              </tr>
              <tr>
                <td>8</td>
                <td>body3</td>
                <td><textarea class="form-control" type="text" name="body3" rows="2"><?php echo $body3; ?></textarea></td>
              </tr>
              <tr>
                <td>9</td>
                <td>body4</td>
                <td><textarea class="form-control" type="text" name="body4" rows="2"><?php echo $body4; ?></textarea></td>
              </tr>
              <tr>
                <td>10</td>
                <td>body5</td>
                <td><textarea class="form-control" type="text" name="body5" rows="2"><?php echo $body5; ?></textarea></td>
              </tr>
              <tr>
                    <td align="center" colspan="6"><input type="submit" name="update" value="Update Now"></td>
                </tr>
            </tbody>
          </table>
          </div>
          </form>
        </div>
    </div>  

    <!-- /page content -->

    <!-- footer content -->
    <?php include('config/footer.php')?>
    <!-- /footer content -->
    </div>  
    </div>          
    <!-- jQuery -->
    <script src="http://stackoverflow.com/vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="vendors/nprogress/nprogress.js"></script>
    <!-- bootstrap-wysiwyg -->
    <script src="vendors/bootstrap-wysiwyg/js/bootstrap-wysiwyg.min.js"></script>
    <script src="vendors/jquery.hotkeys/jquery.hotkeys.js"></script>
    <script src="vendors/google-code-prettify/src/prettify.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="build/js/custom.min.js"></script>
</body>

update code:

<?php

        include("config/db.php");
        mysqli_set_charset ($dbc,'utf8');
            if(isset($_POST['update'])){

            $update_id = $_GET['edit_form'];


            $header = $_POST['header'];
            $header1 = $_POST['header1'];
            $body = $_POST['body'];
            $body1 = $_POST['body1'];
            $body2 = $_POST['body2'];
            $body3 = $_POST['body3'];
            $body4 = $_POST['body4'];
            $body5 = $_POST['body5'];

            if($header=='' or $header1=='' or $body=='' or $body1=='' or $body2=='' or $body3=='' or $body4=='' or $body5==''

            )
            {

            echo "<script>alert('Any of the fields is empty')</script>";
            exit();
            }

            else {

                $update_query = "update contact set header='$header',header1='$header1', body='$body', body1='$body1', body2='$body2', body3='$body3', body4='$body4', body5='$body5' where id='$update_id'";

                if(mysqli_query($dbc, $update_query)){

                echo "<script>alert('Post has been updated')</script>";

                echo "<script>window.open('contactus.php','_self')</script>";

                }

            }
            }



        ?>



لینک منبع

php – Invisible ReCaptcha missing-input-response


I’ve been struggeling with the integration of the Invisible ReCaptcha by Google for quite some time even after using the search function and looking up similar cases. All my Code is located in one page.

The Problem is when I send the Form i will get following error (without the challenge popping up):

Array ( [success] => [error-codes] => Array ( [0] => missing-input-response ) )

Does anyone know why this happens?

<?php
    if (isset( $_POST['g-recaptcha-response'] ))
    {
        $secretKey = 'MYSECRETKEY';
        $response = $_POST['g-recaptcha-response'];     
        $remoteIp = $_SERVER['REMOTE_ADDR'];


        $reCaptchaValidationUrl = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$response&remoteip=$remoteIp");
        $result = json_decode($reCaptchaValidationUrl, TRUE);

        print_r($result);

        if($result['success'] == 1) {
            $userMessage = '<div>Success</div>';
        } else {
            $userMessage = '<div>Fail</div>';
        }


    }
?>

<script>
    function onSubmit(token) {
        document.getElementById('reCaptchaForm').submit();
    }
</script>

<form action="" id="reCaptchaForm" method="post" enctype="multipart/form-data">
    <fieldset class="kontaktformular">
        <label class="contactform-label-text"><span class="contact_form_span">Bemerkungen</span></label>
        <textarea class="contactform-input" name="text" placeholder="Haben Sie Bemerkungen?" id="contactform-text"></textarea>
        <button name="submitbutton" id="submitbutton" class="g-recaptcha contactform-button" data-sitekey="MYSITEKEY" onclick="onSubmit()">Submit</button>
    </fieldset>
</form>



لینک منبع

php – Updating Multiple User Interfaces on Data Updation


My app is Php/CodeIgniter/JQuery based and In my web application i have multiple users logged into the app. Each user has its own User Interface.

Now, all users perform their work and there is an Admin Panel. I want that when some user perform some work the Admin Panel be updated.

Currently i m constantly fetching the data through AJAX and updating the UI. My intent is if data is updated then the User Interfaces be updated without constantly fetching data through AJAX.



لینک منبع