logo
down
shadow

Need help, cannot save my data in db I use query and the server side I use php oop


Need help, cannot save my data in db I use query and the server side I use php oop

By : user2955942
Date : November 22 2020, 10:48 AM
I hope this helps . I use jquery saving my data in db but the problem of my code is when i click the submit button the page was loading and it back to the main page and also can't save the data in db.. i can't figure it out what was the problem of my code.. , The answer to my problem it should be like this:
jQuery:
code :
<script src="js/jquery-1.11.2.js"></script>
<script type="text/javascript">
$("#submit").click(function() {
    $.post( $("#nrForm").attr("action"), $("#nrForm :input").serializeArray(), function(save){ $("#result").html(save); } );
    clearInput();
});

$("#nrForm").submit(function(){
    return false;
});

function clearInput(){
    $('input[type="text"], textarea').val('');
}
</script> 
<form id="nrForm" action="dataentry/save_nr.php" method="post">
                <div class="col-lg-6">
                    <div class="form-group">
                        <label>Date of story</label>
                        <input type="date" name="date_story" id="date_story" class="form-control"  placeholder="Enter date">
                    </div>
                    <div class="form-group">
                        <label>Writer/Author</label>
                        <input type="text" name="writer" id="writer" class="form-control"  placeholder="Enter Name">
                    </div>
                    <div class="form-group">
                        <label>Headline</label>
                        <input type="text" name="headline" id="headline" class="form-control"  placeholder="Enter headline">
                    </div>
                    <div class="form-group">        
                        <label>Source</label>
                        <input type="text" name="source" id="source" class="form-control"  placeholder="Enter source">
                    </div>
                </div>
                <div class="col-lg-10">
                    <div class="form-group">
                        <label>Story</label>
                        <textarea name="story" id="story" class="form-control" rows="10"></textarea>
                    </div>
                    <div class="form-group">        
                        <label>Keywords</label>
                        <input type="text" name="keywords" id="keywords" class="form-control"  placeholder="Enter keywords separated by comma(,)">
                    </div>
                    <button id="submit" name="submit" class="btn btn-primary">Submit</button>
                </div>
            </form>
<?php
session_start();
include_once '../../include/CsppoAdmin.php';
$csppoAdmin = new CsppoAdmin();


    extract($_REQUEST);
    $register = $csppoAdmin->add_news_release($date_story,$writer,$headline,$source,$story,$keywords);
    if ($register) {
        echo '<p style="color:green">News release was successful!</p>';
    } else {
        echo '<p style="color:green">Failed. Inputted already exits please try again.  </p>';
    }
?>
public function add_news_release($date_story,$writer,$headline,$source,$story,$keywords){
            $query = "SELECT `news_id` FROM `news_release` WHERE `headline` = ?";
            if($stmt = $this->db->prepare($query)){
                $stmt->bind_param('s', $headline);
                $stmt->execute();

                $stmt->bind_result($id);
                while ($stmt->fetch()) {
                    printf("%s\n", $id);
                 } 
                if ($id == 0){
                    $stmt = $this->db->prepare("INSERT INTO `news_release` (`date_story`,`writer`,`headline`,`source`,`story`,`keywords`,`post_date`,`poi_id`)
                    VALUES (?,?,?,?,?,?,?,?)");
                    $post_date = date('Y-m-d');
                    $poi_id = $_SESSION['poi_id']; 
                    $stmt->bind_param('sssssssi', $date_story,$writer,$headline,$source,$story,$keywords,$post_date,$poi_id);
                    $stmt->execute();
                    return true;
                }else {return false;}
                $stmt->close();
            }           

            mysqli_close($db);
            $this->db = null;
    }


Share : facebook icon twitter icon
How to save a PNG image server-side, from a base64 data string

How to save a PNG image server-side, from a base64 data string


By : Racer X
Date : March 29 2020, 07:55 AM
To fix the issue you can do You need to extract the base64 image data from that string, decode it and then you can save it to disk, you don't need GD since it already is a png.
code :
$data = 'data:image/png;base64,AAAFBfj42Pj4';

list($type, $data) = explode(';', $data);
list(, $data)      = explode(',', $data);
$data = base64_decode($data);

file_put_contents('/tmp/image.png', $data);
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
if (preg_match('/^data:image\/(\w+);base64,/', $data, $type)) {
    $data = substr($data, strpos($data, ',') + 1);
    $type = strtolower($type[1]); // jpg, png, gif

    if (!in_array($type, [ 'jpg', 'jpeg', 'gif', 'png' ])) {
        throw new \Exception('invalid image type');
    }

    $data = base64_decode($data);

    if ($data === false) {
        throw new \Exception('base64_decode failed');
    }
} else {
    throw new \Exception('did not match data URI with image data');
}

file_put_contents("img.{$type}", $data);
How to save the confidential data at server side

How to save the confidential data at server side


By : jkd
Date : March 29 2020, 07:55 AM
seems to work fine You could take a look into the crypto library of node.
Here is a link to the documentation: Crypto Node.js
How to save a PNG image server-side, from a base64 data string javascript

How to save a PNG image server-side, from a base64 data string javascript


By : Eric W
Date : March 29 2020, 07:55 AM
To fix the issue you can do i have this code, either the ajax isn't transferring the data correctly or my php doesn't work properly. i know the canvass is saving to data png it writes to the page. Is there a way to just convert it to a file and save it from javascript? , changed the php to -------->
code :
define('UPLOAD_DIR', 'images/');
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . 'txtimg.png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';
Is it faster to POST data to a webmethod or dump client-side data to a server control and then get the data server-side?

Is it faster to POST data to a webmethod or dump client-side data to a server control and then get the data server-side?


By : Troy Matthews
Date : March 29 2020, 07:55 AM
This might help you Using AJAX will usually be faster than POST because less data is sent through in AJAX than POST.
Note: You shouldn't only base your solution on the speed of the call.
Is it possible to save data to a json file on local disk using $resource.save without using any server side implementati

Is it possible to save data to a json file on local disk using $resource.save without using any server side implementati


By : hurdygurdyman
Date : March 29 2020, 07:55 AM
To fix the issue you can do You can make use of HTML5 local browser storage, as this does not require folder access. Mode datails here http://diveintohtml5.info/storage.html
AngularJS has modules for local storage which you can use to access such storages like this https://github.com/grevory/angular-local-storage
Related Posts Related Posts :
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • What's wrong with my PHP Script? T_String issue
  • how to call a function of another file without including that file
  • is_rgb function in php
  • transform the numbers to letters using php
  • How to catch an exception from another class method PHP
  • PHP exec is blocked by ISP
  • PHP4 to PHP5 migration character encoding. latin1 vs utf8
  • Begin Transaction not defined
  • How much harm can a user do with xss on a page unique to them?
  • How to import data from a php file to javascript variable
  • PHP and Javascript - log complete workflow
  • When I echo !!! 0 it gives me a strange result
  • jquery ajax post dies after submit
  • How to upload file with curl on sftp server
  • Advanced search using a text input to search through only one category
  • Why do I get "Non-static method App\Models\Category::products() should not be called statically" in laravel
  • Stop notices from undefined indexes in arrays
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org