post form queries(solved)

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
hi
the problem is name contain extra space from the begining and end so it will not fetch the same record again

it is happen due to mysql_real_escape_string function just remove that function and test it again


Code:
<?php
    if (isset($_POST['uName'])) {
          
           $con = mysql_connect("localhost","root","");
           mysql_select_db('test', $con);
 
           // $name = mysql_real_escape_string($_POST['uName']);   
         $name = $_POST['uName'];
         echo $sql = "SELECT * FROM users WHERE name='$name' limit 1" ;
      
            $query = mysql_query($sql) or die ("couldnt execute query");
       
            $numrows = mysql_num_rows($query);
            print_r($numrows);exit;
        if ($numrows == 1) {
            echo "nope";
            exit();
          }

       if($numrows == 0){
          
      mysql_query("INSERT INTO users (name)
            VALUES(' $name ')")or die (mysql_error());
            echo 'entered successfully';
        //exit();
       }
    }
    ?>

Thanks & Regards,
Prensil Technologies Pvt. Ltd.
php web development company
http://www.prensil.com
 
Change this:
PHP:
mysql_query("INSERT INTO users (name)
        VALUES(' $name ')")or die (mysql_error());
 

to this:
PHP:
mysql_query("INSERT INTO users (name) VALUES('$name')") or die (mysql_error());
 
 
Back
Top