I am developing a web-app in
1 | Visual Studio code |
1 | MYSQL |
HTML code (basically fetching the values from a form and sending them to the php script):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | function submit(n,i,p,e,img){ alert(n+ "" +i+ "" +p+ "" + "" +e+ "" +img); $.ajax({ type : "POST" , //type of method url : "/database_registration.php" , data : { name_1 : n, email_1 : e, image : img, org_number_1: i, ph_number_1: p }, success: function (){ alert( "success!!" ); } }); } const dForm = document.getElementById( 'details' ); dForm.addEventListener( 'submit' , function (e) { e.preventDefault() submit(nme,id,phone,email,img); }); var arr=document.cookie.split( ';' ) for ( var i=0; i<arr.length; i++){ var c=arr[i].split( '=' ); if (c[0].trim()== 'name' ){ var nme=c[1]; document.getElementsByName( "name_1" )[0].innerHTML=nme; } else if (c[0].trim()== 'ID No' ){ var id=c[1]; document.getElementsByName( "org_number_1" )[0].innerHTML=id; } else if (c[0].trim()== 'Mobile No' ){ var phone=c[1]; document.getElementsByName( "ph_number_1" )[0].innerHTML=phone; } else if (c[0].trim()== 'Email' ){ var email=c[1]; document.getElementsByName( "email_1" )[0].innerHTML=email; } } const image = localStorage.getItem( "Image" ); var img=image; document.getElementsByName( "image" )[0].src=image; |
php script (Storing the values into a MYSQL database):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <?php header( "Access-Control-Allow-Origin: *" ); header( "Access-Control-Allow-Methods: GET, POST, OPTIONS" ); $servername = "localhost" ; $username = "root" ; $password = "" ; $date = date ( "Y-m-d" ); echo 'Post variables:<br />' ; print_r( $_POST ); if (isset( $_POST [ "name_1" ])) $name = $_POST [ 'name_1' ]; if (isset( $_POST [ "org_number_1" ])) $org_number = $_POST [ 'org_number_1' ]; if (isset( $_POST [ "ph_number_1" ])) $ph_number = $_POST [ 'ph_number_1' ]; if (isset( $_POST [ "email_1" ])) $email = $_POST [ 'email_1' ]; if (isset( $_POST [ "image" ])) $image = $_POST [ 'image' ]; $conn = new mysqli( $servername , $username , $password , "Employee_information" ); if ( $conn ->connect_error) { die ( "Connection failure: " . $conn ->connect_error); } $sql ="CREATE TABLE IF NOT EXISTS Employees(Sl_no int AUTO_INCREMENT PRIMARY KEY, Full_name varchar(30) NOT NULL, ID_no INT(2) NOT NULL UNIQUE, Contact INT(10) NOT NULL UNIQUE, Email varchar(30) NOT NULL UNIQUE, registration_date DATE , ID_preview blob(10M))"; $conn -> query( $sql ); $stmt = $conn ->prepare("INSERT INTO Employees (Full_name, ID_no, Contact, Email, registration_date, ID_preview) VALUES (?, ?, ?, ?, ?, ?)"); $stmt ->bind_param( "siissb" , $name , $org_number , $ph_number , $email , $date , $image ); $stmt ->execute(); if ( $stmt ->execute()) echo "records inserted" ; else echo $stmt ->error; $stmt ->close(); $conn ->close(); ?> |
Error:
Failed to load resource: the server responded with a status of 405 (Method not allowed)
0 comments:
Post a Comment
Thanks