php - html sign up form not saving data in mysql -


i have written basic html sign-up form:

<!doctype html> <html lang="en"> <head>   <meta charset="utf-8">   <title>registration</title> </head> <body>  <form name="reg" action="code_exec.php" onsubmit="return validateform()" method="post">   <table width="274" border="0" align="center" cellpadding="2" cellspacing="0">     <tr>       <td colspan="2">         <div align="center">           <?php            // $remarks=$_get['remarks'];           if (!isset($_get['remarks']))           {             echo 'register here';           }           if (isset($_get['remarks']) && $_get['remarks']=='success')           {             echo 'registration success';           }           ?>           </div></td>       </tr>       <tr>         <td width="95"><div align="right">first name:</div></td>         <td width="171"><input type="text" name="fname" /></td>       </tr>       <tr>         <td><div align="right">last name:</div></td>         <td><input type="text" name="lname" /></td>       </tr>       <tr>         <td><div align="right">gender:</div></td>         <td><input type="text" name="gender" /></td>       </tr>       <tr>         <td><div align="right">address:</div></td>         <td><input type="text" name="address" /></td>       </tr>       <tr>         <td><div align="right">contact no.:</div></td>         <td><input type="text" name="contact" /></td>       </tr>       <tr>         <td><div align="right">username:</div></td>         <td><input type="text" name="username" /></td>       </tr>       <tr>         <td><div align="right">password:</div></td>         <td><input type="text" name="password" /></td>       </tr>       <tr>         <td><div align="right"></div></td>         <td><input name="submit" type="submit" value="submit" /></td>       </tr>     </table>   </form> </body> </html> 

i using php connect html page mysql database on xampp server installed/configured locally.

i have divided connection, , data storage logic across 2 different .php files:

connection.php

<?php $mysql_hostname = "localhost"; $mysql_user = "amitesh"; $mysql_password = "amitesh"; $mysql_database = "sign_up_form"; $prefix = "";  $bd = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password) or die("could not connect database"); mysqli_select_db($mysql_database,$bd) or die("could not select database"); ?> 

code_exec.php

<?php session_start();  include('connection.php');  $fname=$_post['fname']; $lname=$_post['lname']; $mname=$_post['mname']; $address=$_post['address']; $contact=$_post['contact']; $username=$_post['username']; $password=$_post['password'];  mysqli_query($bd, "insert member(fname, lname, gender, address, contact, username, password)values('$fname', '$lname', '$mname', '$address', '$contact','$username', '$password')");  header("location: index.php?remarks=success");  mysqli_close($bd); 

after insert data in page, when click on "submit" button, shows me code of code_exec.php file instead of storing data in mysql.

i did see couple of stackoverflow posts this, none of them seem offer working solution problem.

why happening?

introduction

if <?php tags , actual website code being displayed on page, there 2 scenarios:

  1. xampp not working, or;
  2. you not navigating file @ web address 127.0.0.1.

since have confirmed xampp running, cover scenario two, likely.

you not navigating file @ web address 127.0.0.1

inside of xampp installation, should find folder called htdocs. folder should contain any websites make, , all of php code - acts root directory of web server (if using dedicated server, equivalent of /var/www/html/). server processes files contained within folder.

if files not inside of folder, move them (and delete / move different folder files in directory).

next, can't open files in web browser once in folder - have navigate them via locally hosted website.

go url 127.0.0.1 or localhost visit locally hosted website. accessible you, on computer, while xampp running, , displays documents in htdocs folder. can choose file in list visit it, , should run on web server.

summary

from on, should easy work files on local web server. of course, there still php error in code (i checked on - appears fine, have missed something) - if case , stuck debugging, can ask question here on stackoverflow!

as bonus, should able visit 127.0.0.1/phpmyadmin/ xampp running manage mysql tables , databases via web interface.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -