database not inserting properly

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 359
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Sat Oct 18, 2014 4:41 pm

you're using isset() to set a variable. Isset() is a function that returns true (i.e. 1) if a variable is set. So if your variables are set, you're changing them all to 1. You probably don't even need to test if it's set, because if it's not, you'll just get nothing inserted into the field.

Also, the mysql extension is deprecated and you shouldn't be using it. Use mysqli (very similar) or PDO (much more secure) instead.

Code: Select all

error_reporting(E_ALL ^ E_DEPRECATED);
     $con = mysql_connect("localhost","root","");
   if (!$con)
     {
      die('Could not connect: ' . mysql_error());
     }
    mysql_select_db("whatchadoin", $con);
    
   //$f = "Heelo"; 
   
   $last_name = $_POST['lname'];
   $email = $_POST["email"];
   //$gender = $_POST['sel_gender'];
   if(isset($_POST['fname']) && isset($_REQUEST['submit']))
   {
   
   $f_name = $_POST['fname'];
   $sql="INSERT INTO participant (fname, lname,email) VALUES
   ('$f_name','$last_name','$email')";

   if (!mysql_query($sql,$con))
     {
     die('Error: ' . mysql_error());
     }else
   echo "1 record added";
   }
   

   mysql_close($con); 

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest