php - Data not getting saved to Mysql database after adding a column -


i created simple registration form using tutorial

since added column last name form not saving data in sql database

here code files

registration.php

<html>     <head>         <title> registration form</title>     </head>  <body> <form method='post' action='registration.php'>     <table width='400' border='5' align='center'>      <tr>             <td align='center' colspan='5'><h1>registation form</h1></td>     </tr>      <tr>             <td align='center'>first name:</td>         <td><input type='text' name='fname' /></td>     </tr>      <tr>          <td align='center'>last name:</td>         <td><input type='text' name='lname' /></td>     </tr>       <tr>             <td align='center'>user password:</td>         <td><input type='password' name='pass' /></td>     </tr>      <tr>             <td align='center'>email:</td>         <td><input type='text' name='email' /></td>     </tr>      <tr>             <td colspan='5' align='center'><input type='submit' name='submit' value='sign up' /></td>     </tr>       </table> </form> <center><b>already registered</b><br><a href='login.php'>login here</a></center> </body> </html> <?php  mysql_connect("localhost","root",""); mysql_select_db("users_db");      if(isset($_post['submit'])){       $user_fname = $_post['fname'];      $user_lname = $_post['lname'];       $user_pass = $_post['pass'];      $user_email = $_post['email'];      if($user_fname==''){     echo "<script>alert('please enter first name!')</script>";     exit();     }      if($user_lname==''){     echo "<script>alert('please enter last name!')</script>";     exit();     }      if($user_pass==''){     echo "<script>alert('please enter password!')</script>";     exit();     }      if($user_email==''){     echo "<script>alert('please enter email!')</script>";     exit();     }      $check_email = "select * users user_email='$user_email'";      $run = mysql_query($check_email);      if(mysql_num_rows($run)>0){      echo "<script>alert('email $user_email exist in our database, plz try one!')</script>";     exit();     }      $query = "insert users (user_fname,user_lname,user_pass,user_email) values ('$user_fname','$user_lname',$user_pass','$user_email')";     if(mysql_query($query)){      echo "<script>window.open('welcome.php','_self')</script>";      }        }  ?> 

when run show columns users output

field type null key default id int(10) no pri null auto_increment user_fname varchar(100) no null user_lname varchar(100) no null user_pass varchar(50) no null user_email varchar(100) no null 

i have created insert record you. try change db settings. goes thanks.php show thank or successfull.

<?php # filename="connection_php_mysql.htm" # type="mysql" # http="true" $hostname_localhost2 = "localhost"; $database_localhost2 = "users_db"; $username_localhost2 = "username"; $password_localhost2 = "password"; $localhost2 = mysql_pconnect($hostname_localhost2, $username_localhost2, $password_localhost2) or trigger_error(mysql_error(),e_user_error);  ?> <?php if (!function_exists("getsqlvaluestring")) { function getsqlvaluestring($thevalue, $thetype, $thedefinedvalue = "", $thenotdefinedvalue = "")  {   if (php_version < 6) {     $thevalue = get_magic_quotes_gpc() ? stripslashes($thevalue) : $thevalue;   }    $thevalue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($thevalue) : mysql_escape_string($thevalue);    switch ($thetype) {     case "text":       $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null";       break;         case "long":     case "int":       $thevalue = ($thevalue != "") ? intval($thevalue) : "null";       break;     case "double":       $thevalue = ($thevalue != "") ? doubleval($thevalue) : "null";       break;     case "date":       $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null";       break;     case "defined":       $thevalue = ($thevalue != "") ? $thedefinedvalue : $thenotdefinedvalue;       break;   }   return $thevalue; } }  $editformaction = $_server['php_self']; if (isset($_server['query_string'])) {   $editformaction .= "?" . htmlentities($_server['query_string']); }  if ((isset($_post["mm_insert"])) && ($_post["mm_insert"] == "form1")) {   $insertsql = sprintf("insert users (id, user_fname, user_lname, user_pass, user_email) values (%s, %s, %s, %s, %s)",                        getsqlvaluestring($_post['id'], "int"),                        getsqlvaluestring($_post['user_fname'], "text"),                        getsqlvaluestring($_post['user_lname'], "text"),                        getsqlvaluestring($_post['user_pass'], "text"),                        getsqlvaluestring($_post['user_email'], "text"));    mysql_select_db($database_localhost2, $localhost2);   $result1 = mysql_query($insertsql, $localhost2) or die(mysql_error());    $insertgoto = "thanks.php";   if (isset($_server['query_string'])) {     $insertgoto .= (strpos($insertgoto, '?')) ? "&" : "?";     $insertgoto .= $_server['query_string'];   }   header(sprintf("location: %s", $insertgoto)); }  ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head>  <body> <form action="<?php echo $editformaction; ?>" method="post" name="form1" id="form1">   <table align="center">     <tr valign="baseline">       <td nowrap="nowrap" align="right">id:</td>       <td><input type="hidden" name="id" value="" size="32" /></td>     </tr>     <tr valign="baseline">       <td nowrap="nowrap" align="right">user_fname:</td>       <td><input type="text" name="user_fname" value="" size="32" /></td>     </tr>     <tr valign="baseline">       <td nowrap="nowrap" align="right">user_lname:</td>       <td><input type="text" name="user_lname" value="" size="32" /></td>     </tr>     <tr valign="baseline">       <td nowrap="nowrap" align="right">user_pass:</td>       <td><input type="text" name="user_pass" value="" size="32" /></td>     </tr>     <tr valign="baseline">       <td nowrap="nowrap" align="right">user_email:</td>       <td><input type="text" name="user_email" value="" size="32" /></td>     </tr>     <tr valign="baseline">       <td nowrap="nowrap" align="right">&nbsp;</td>       <td><input type="submit" value="insert record" /></td>     </tr>   </table>   <input type="hidden" name="mm_insert" value="form1" /> </form> <p>&nbsp;</p> </body> </html> 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -