0

something is wrong in this code because it not insert values in database

 /////////////////////////////code php start////////////////

 <body>

<div id="regform">
<h2> register form</h2>
<?php

 if(isset($_POST['submit'])){// Click on complete button

  $error=array();
  if(empty($_POST['uname']) || trim($_POST['uname'])=="")
   $error[]="خطأ : خانة اسم المستخدم فارغة";
  if(empty($_POST['fname']) || trim($_POST['fname'])=="")
   $error[]="خطأ:خانة الاسم الاول فارغة";
  if(empty($_POST['password']) || trim($_POST['password'])=="")
   $error[]="خطأ : خانة الكلمة السرية فارغة";
  if(empty($_POST['password2']) || trim($_POST['password2'])=="")
   $error[]="خطأ خانة  تأكيد الكلمة السرية فارغة";
  if(empty($_POST['email'])|| trim($_POST['email'])=="")
   $error[]="خطأ : خانة البريد الالكتروني فارغة";
  if(empty($_POST['email2'])|| trim($_POST['email2'])=="")
   $error[]="خطأ : خانة تأكيد البريد الالكتروني فارغة";
  if(empty($_POST['age'])|| trim($_POST['age'])=="")
   $error[]="خطأ :خانة العمر فارغة";

  if(strlen($_POST['uname'])<4)
   $error[]="حطأ :  يجب ان يتكون اسم المستخدمن اكثر 4 حروف";

  if(strlen($_POST['password'])<4 || strlen($_POST['password2'])<4)
   $error[]="خطأ الكلمة السرية يجب ان تتكون من اكثر من 6 حروف";

  if($_POST['password']!=$_POST['password2'])
   $error[]="خطأ : الكلمات السرية غير متطابقة";
   //Validating Emails 

   if(!preg_match("/^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9](.[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])+$/",$_POST['email'])
    ||
    !preg_match("/^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9](.[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])+$/",$_POST['email2']))
  $error[]="خطأ: البريد الالكتروني غير صالح";



  if($_POST['email']!=$_POST['email2'])
   $error[]="خطأ : البريد الالكتروني غير متطابق";

  if(!is_numeric($_POST['age']))
   $error[]="خطأ : العمر المدخل ليس قيمة رقمية";


if(sizeof($error)>0){
   echo "<div id=\"error\">";
   echo "<ul>";    
 foreach($error as $k=>$v){
   echo "<li> ";
   echo $v;
   echo "</li>";   
  }
   echo "</ul>";
   echo "</div>";

   }


   else{
  include "conf.php";
                // Random confirmation code
                $confirm_code=md5(uniqid(rand()));
    $username=mysql_real_escape_string($_POST['uname']);
    $fname=mysql_real_escape_string($_POST['fname']);
    $password=md5($_POST['password']);
    $email=mysql_real_escape_string($_POST['email']);
    $age=$_POST['age'];
    $gender=$_POST['gender'];
    $adduser= mysql_query("INSERT INTO USERS VALUES('',$confirm_code,'$username','$fname','$password','$email','$age','$gender')");
     // send e-mail to ...
                  $to=$email;

                 // Your subject
              $subject="Your confirmation link here";

                   // From
              $header="from: your name <your email>";

                   // Your message
              $message="Your Comfirmation link \r\n";
              $message.="Click on this link to activate your account \r\n";
              $message.="http://www.yourweb.com/confirmation.php?passkey=$confirm_code";
                        // send email
              $sentmail = mail($to,$subject,$message,$header);
    if(!$adduser or !$sentmail){

     echo "<div id=\"succes\">";
     echo " register succesfully";
     echo "</div>";

    }

   }

  }



?>
//////////////// form start ////////////////////////
 <ul>
 <form method="post" action="index.php">
  <li><label>اسم المستخدم :</label> <span><input type="text" name="uname" /></span> </li>
  <li><label> الاسم الاول: </label> <span><input type="text" name="fname" /></span></li>
  <li><label> الكلمة السرية: </label> <span><input type="password" name="password" /></span> </li>
  <li><label> تأكيد الكلمة السرية: </label>  <span><input type="password" name="password2" /></span></li>
  <li><label> البريد الالكتروني: </label>  <span><input type="text" name="email" /></span></li>
  <li><label> تأكيد البريد الالكتروني: </label>  <span><input type="text" name="email2" /></span> </li>
  <li><label> العمر: </label>  <span><input type="text" name="age" /></span></li>
  <li><label> الجنس: </label><span><select name="gender"><option>ذكر</option> <option>انثى</option> </select> </span> </li>
  <li> <input type="submit" class="submit" value="اكمال" name="submit"/> </li>
  </form>
 </ul>

</div>
</body>
</html>
2
  • It always helps if a) you isolate the block of code that is causing the problem rathe rthan upload the entire script. b) put some debug in your code (e.g. display the SQL before executing the query, trap the response from mysql_query to see if it's an error, and get the error message) Commented Sep 22, 2010 at 9:54
  • On top of your script write: error_reporting (-1); Commented Sep 22, 2010 at 9:57

1 Answer 1

3

$confirm_code is a string, so it should be quoted in your INSERT statement

$adduser= mysql_query("INSERT INTO USERS VALUES('','$confirm_code','$username','$fname','$password','$email','$age','$gender')"); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.