I can't insert data to database through this code.Data alredy exist part is working but after that data not insert to the database.

This is the PHP code.
<?php error_reporting(E_ERROR|E_WARNING);




$dblink = mysql_connect("localhost", "root", "") or die('Not able to connect to server : ' . mysql_error());
mysql_select_db("apperal",$dblink) or die('Not able to select Database : ' . mysql_error()); //hama ekakatama poduwe hadapu connection eka

$sql = "SELECT COUNT(*) AS Count FROM addnewbuyer WHERE styleno LIKE '".$no."'";
  $result = mysql_fetch_array(mysql_query($sql));
  if ($result['Count'] > 0) {
    die('alredy exist');

$sql1="INSERT INTO `addnewbuyer` (`id`, `styleno`, `buyername`, `buyeraddress`, `phoneno`) VALUES (NULL, '$no', '$refer', '$amount', '$state);";



echo "<font color='blue'>Data Added Successfully"; 


$msg="<font color='red'>Data Adding Failed";



This is my form.

<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


 <form id="form_322883" class="appnitro"  method="post" action="chkbyr.php">
    <div class="form_description">
     <h2> Add New Buyer</h2>


   <table width="102%">
       <td height="34"><label class="description" for="txtid" value="">BuyerID</label></td>
       <td>  <input id="txtid" name="txtid" class="hidden"  type="BuyerID "  value="" /></td></tr>

    <td height="40"><label class="description" for="txtno">Styleno </label></td>

           <td><input id="txtno" name="txtno"  type="styleno "  value=""/></td></tr>           

    <td height="40"><label class="description" for="txtrefer">BuyerName </label></td>

           <td><input id="txtrefer" name="txtrefer"  type="BuyerName "  value=""/></td></tr>           


      <td height="36"><label class="description" for="txtamount">BuyerAddress </label></td>

<td><input id="txtamount" name="txtamount"  type="BuyerAddress" maxlength="" value=""/></td></tr>

        <td height="42">

        <label class="description" for="txtstate">PhoneNo</label></td>

      <td><input id="txtstate" name="txtstate"  type="PhoneNo"  value=""/></td> 

   <li class="buttons">


   <td> </td>
          <td><input id="saveForm" class="button_text" type="submit" name="add" value="Add" />      <input type="submit"class="button_text" name="update" value="Update" />
            <a href="http://localhost/Apperal/vieww.php">
            <input  type="submit" class="button_text" name="search2" value="view" />    </a>
         <!--   <input type="submit" class="button_text" name="search" value="Search" />-->
            <input type="submit" class="button_text" name="delete" value="Delete" />
          <td> </td>
          <td> </td>

          <td> </td>     



<div id="box4">
 <p class="mar"><a href="viewadd.php">Back</a></p>
<p class="mar"><a href="index.php">Logout</a></p>


<div id="footer">




Recommended Answers

Line 32 is missing a single quote after $state.

Jump to Post

All 4 Replies

Line 32 is missing a single quote after $state.

or null is an odd value to put into the id. if autonumbering remove both the field and the null value. otherwise assign a real value

null is an odd value to put into the id

If auto numbering is on, passing NULL is accepted. Personally, I prefer removing it too, but both act the same.

Thnx..I edited the line 32 missing value and I add "mysql_real_escape_string" near to ($_POST['txtno']); in 12,13, & 14 line..It worked!!!Thanx lot...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.