record not save after submit

Alles, was PHP betrifft, kann hier besprochen werden.

record not save after submit

Postby pkimran » 03. April 2015 14:28

hy
i am facing problem with my code
when i click on add record button page refresh but new record not saved in sql database
help me please
thanks


Code: Select all
<?php
//conenction file
include "connection.php";

//cleaning string
function cleanstring ($string)
{
   $string=htmlspecialchars (trim($string));
   return $string;
}
//function for new form
function print_Form() {
   //new form var
   $newform = "<form method=\"POST\"action=\"{$_SERVER['PHP_SELF']}\">
   <table border=1 cellpadding=3 cellspacing=3>
<tr><td> Complaint Number </td>
<td><input type=\"number\"name=\"Complaint number\"></td></tr>
<tr><td>Name</td>
<td><input type=\"text\"name=\"Name\"></td></tr>

<tr><td> Address </td>
<td><input type=\"text\"name=\"Address\"></td></tr>
<tr><td>CNIC</td>
<td><input type=\"number\"name=\"CNIC\"></td></tr>

<tr><td>Comments</td>
<td><input type=\"text\"name=\"Commetns\"></td></tr>


<tr><td colspan=2><input type=\"submit\"value=\"Add Record\">
<input type=\"hidden\"value=\"true\"name=\"POST\">






</td></tr></table></form>";


return $newform;
}
//saving record
function save_Record() {
$Complaint_Number =  cleanString ($_POST['Complaint Number']);
$Name =  cleanString ($_POST['Name']);
$Address =  cleanString ($_POST['Address']);
$CNIC = cleanString ($_POST ['CNIC']);
$Comments =  cleanString ($_POST['Comments']);
//checking for empty values
if(empty($Complaint_Number) || empty ($Name) || ($Address) || empty ($CNIC) || ($Comments)  ) {
   error_Message ("Cannot insert empty record");
}
//query
$query = "INSERT INTO complaint_cell(Complaint Number,Name,Address,CNIC,Comments)
VALUES ('$Complaint_Number','$Name','$Address','$CNIC','$Comments')";
//execute query
if(mysql_query ($query)) {
   print "<div style='background:#FFFFCC;border:dashed 1px #CCCCCC'>
   Record added successfully </div>";
   print print_Form(); //show form again
}else{
   error_Message (mysql_error()); //if error in query
   
}
}
//error message
function error_Message ($error) {
   $msg = "<div style='background:#FFFFCC;border:dashed 1px #CCCCCC'>
   $error <a href='javascript:history.go (-1) '> Back</a></div>";
   die($msg);
}
//what to do
if(isset($_POST
[
'post'])) {
   // if form is POSTED
   save_Record();
}else{
   //first time print the form
   print print_Form();
}

?>
pkimran
 
Posts: 10
Joined: 03. April 2015 14:21
Operating System: windows 7

Re: record not save after submit

Postby JJ_Tagy » 03. April 2015 15:27

You should try the query manually to debug. You can also add debug messages to see your final query. I'm pretty sure you will find that this part will not work with spaces:

$query = "INSERT INTO complaint_cell(Complaint Number,Name,Address,CNIC,Comments)
JJ_Tagy
 
Posts: 788
Joined: 30. January 2012 13:44
XAMPP version: 5.5.15
Operating System: Windows 10 Pro x64

Re: record not save after submit

Postby JJ_Tagy » 03. April 2015 15:30

And when your query does work, you might find that your comments will not populate because of this:

<td><input type=\"text\"name=\"Commetns\"></td></tr>

and possibly these spaces:

<td><input type=\"number\"name=\"Complaint number\"></td></tr>
$Complaint_Number = cleanString ($_POST['Complaint Number']);
JJ_Tagy
 
Posts: 788
Joined: 30. January 2012 13:44
XAMPP version: 5.5.15
Operating System: Windows 10 Pro x64

Re: record not save after submit

Postby HokuApps » 24. November 2017 07:05

JJ_Tagy wrote:You should try the query manually to debug. You can also add debug messages to see your final query. I'm pretty sure you will find that this part will not work with spaces:

$query = "INSERT INTO complaint_cell(Complaint Number,Name,Address,CNIC,Comments)

agree.
HokuApps
 
Posts: 22
Joined: 11. September 2017 07:23
XAMPP version: 1.8.0
Operating System: Windows


Return to PHP

Who is online

Users browsing this forum: No registered users and 57 guests