window.addEventListener( 'DOMContentLoaded', function() {
var form = document.getElementById( 'form_id' );
Array.from( document.getElementsByTagName( 'input' ) ).map( function( el ) {
if ( el.type == 'radio' && el.parentNode == form ) {
el.addEventListener( 'change', function() {
form.submit();
} );
}
} );
} );
$products = json_decode( '[{"value":"1000 рублей"},{"value":"500 рублей"},{"value":"5000 рублей"}]', true );
// или
$products = [ [ 'value' => '1000 рублей' ], [ 'value' => '500 рублей' ], [ 'value' => '5000 рублей' ] ];
$total_price = array_reduce( $products, function( $v, $i ) {
$v += intval( $i[ 'value' ], 10 );
return $v;
} );
echo $total_price; // 6500
$mysqli = new mysqli( 'localhost', 'user', 'password', 'database' );
if ( $stmt = $mysqli->prepare( 'INSERT INTO comments( `note`, `name`, `text`, `date` ) VALUES( ?, ?, ?, ? )' ) ) {
$id = 1;
$name = $_POST[ 'namecomment' ];
$text = $_POST[ 'inputcomment' ];
$date = date( 'Y-m-d H:i:s' );
$stmt->bind_param( 'isss', $id, $name, $text, $date );
$stmt->execute();
} else {
echo $mysqli->error . PHP_EOL;
}
$mysqli->close();