2011-03-29 49 views
0

您好我想添加表中的數據。然而,它並沒有出現在XAMPP(MySQL)中添加來自PHP的數據

我在做什麼錯了。花了很長時間看看有什麼不對,但我找不到任何東西。

fyi。

config.php連接PHPto MySQL。和 clean.php清理變量。

<?php 

    session_start(); 
    echo "<div style='text-align:right'><h1>Welcome ". $_SESSION['SESS_FIRST_NAME']."!</h1> </div>"; 
    if($_SESSION['SESS_admin'] == 0) 
     { 
      require("do_menu.php"); 
      echo "<div style='text-align:right'> 
      <form action='SearchUser.php' method='POST'> 
      <Table border='0' align='right'> 
      <tr> 
       <td > 
        <select name='SEARCH' id='SEARCH'> 
         <option value='ID_NO' selected='selected'>ID Number</option> 
         <option value='FNAME'>First Name</option> 
         <option value='LNAME' >Last Name</option> 
         <option value='MNAME'>Middle Name</option> 
         <option value='DATE'>Birthday</option> 
         <option value='SEX'>SEX</option> 
         <option value='AGE'>Age</option> 
         <option value='STATUS'>Status</option> 
         <option value='TEL_NO'>Landline Number</option> 
         <option value='ADDRESS'>Address</option> 
         <option value='OCCUPATION'>Occupation</option> 
         <option value='REFERRED_BY '>Referrals</option> 
         <option value='itResult'>Result</option> 
        </select> 
       </td> 
       <td rowspan =2><input name='SUBMIT' type='SUBMIT' id='SUBMIT' value='Search!'></td> 
      </tr> 
      <tr> 
       <td><input name='INPUT' type='text' id='INPUT'></td> 
      </tr> 
      </table><br> 
      </FORM> </div>"; 
     } 
    else 
     require("do_menu3.php"); 


    require("clean.php"); 
    require("config.php"); 
    require("auth.php"); 
    require("do_html_header.php"); 
    do_html_header(); 
    do_menu(); 

?> 

<?php 
    if (!$_POST['SUBMIT']){ 
?> 



    <center> 
    <form action="<?php print $_SERVER['PHP_SELF']; ?>" method="POST" name=register> 
    <table width="400" border="0" cellspacing="1" cellpadding="0" align="center"> 
    <tr> 
    <td bgcolor="yellow"><H1>Add Specialist</H1></td> 
    </tr> 
    <tr> 
      <td width="100"> 
      <fieldset> 
      <label for="name">name:</label> 
       <input 
        type="text" 
        id="name" 
        name="name" 
        maxlength="100" 
        onkeyup="checkNameForLength(this);" /> 

      </fieldset> 
      </td> 
     </tr> 
     <tr> 
      <td width="100"> 
      <fieldset> 
      <label for="spec_username">Specialist's Username:</label> 
       <input 
        type="text" 
        id="spec_username" 
        name="spec_username" 
        maxlength="100" 
        onkeyup="checkNameForLength(this);" /> 

      </fieldset> 
      </td> 
     </tr> 
     <tr> 
      <td width="100"> 
      <fieldset> 
      <label for="spec_password">Specialist's Password:</label> 
       <input 
        type="text" 
        id="spec_password" 
        name="spec_password" 
        maxlength="28" 
        onkeyup="checkNameForLength(this);" /> 

      </fieldset> 
      </td> 
     </tr> 
     <tr> 
      <td width="100"> 
      <input type="hidden" name="online_check" id="online_check" size="50" value="Y"> 

      </td> 
     </tr> 
     <tr> 
      <td width="100"><center><input name="SUBMIT" type="SUBMIT" id="SUBMIT" value="SUBMIT"> 
      <input type="RESET" value="RESET"></form> 
      <form action="login-form.php"><input type="SUBMIT" name="Submit" value="Go Back!"/></center></form></td> 

     </tr> 
    </table> 


<?php 
    } 
    else { 

     //Array to store validation errors 
     $errmsg_arr = array(); 

     //Validation error flag 
     $errflag = false; 

     //Function to sanitize values received from the form. Prevents SQL injection 

     $name      = clean($_POST['name']); 
     $spec_username    = clean($_POST['spec_username']); 
     $spec_password   = clean($_POST['spec_password']); 
     $online_check    = clean($_POST['online_check']); 


     $_SESSION["spec_id"]    = $spec_id; 
     $_SESSION["name"]     = $name; 
     $_SESSION["spec_username"]  = $spec_username; 
     $_SESSION["spec_password"]  = $spec_password; 
     $_SESSION["online_check"]   = $online_check; 

     //Input Validations 

     if($name == '') { 
      $errmsg_arr[] = 'Name missing'; 
      $errflag = true; 
     } 
     if($spec_username == '') { 
      $errmsg_arr[] = 'Username missing'; 
      $errflag = true; 
     } 
     if($spec_password == '') { 
      $errmsg_arr[] = 'Password missing'; 
      $errflag = true; 
     } 
     if($online_check == '') { 
      $errmsg_arr[] = 'Online Check missing'; 
      $errflag = true; 
     } 



     //If there are input validations, redirect back to the registration form 
     if($errflag) { 
      $_SESSION['ERRMSG_ARR'] = $errmsg_arr; 
     session_write_close(); 
     print "You have input errors. These are:"; 
     print "<BR><UL>"; 
     for ($i=0; $i<sizeof($errmsg_arr); $i++) { 
       print "<LI>$errmsg_arr[$i]"; 
      } 
      print "</UL>"; 
     print "<A HREF=\""; 
      print $_SERVER['PHP_SELF']; 
      print "\">Go back</A>"; 
     exit(); 
     } 
     else { 
      echo "<center><BR><BR>You entered the following information:"; 

      echo "<BR>Name = $name"; 
      echo "<BR>Username = $spec_username"; 
      echo "<BR>Password = $spec_password"; 
      echo "<BR>Online Check = $online_check"; 

      $result = mysql_query("select * from specialist_info where spec_id = '$spec_id'"); 
      if(!(mysql_num_rows($result) == 0)) { 
       print "<BR>User number $spec_id is already assigned to another User<BR><A HREF =\"".$_SERVER['PHP_SELF']. "\">Go Back</A>"; 
      @mysql_free_result($result); 
      exit(); 
      } 
     $result = mysql_query("INSERT INTO specialist_info (spec_id, name, spec_username, spec_password, online_check) VALUES('$spec_id', '$name', '$spec_username',spec_password('$password'), '$online_check')"); 
      print ("<BR><BR>1 record added"); 

     } 
    } 
?> 

</BODY> 
</HTML> 
+0

嚴重?請指出錯誤的位置 – 2011-03-29 22:57:55

+0

我想放在數據庫中的數據沒有顯示在MySQL中。是的,它很嚴肅。 – 2011-03-29 23:14:06

回答

2

這是你的查詢行

$result = mysql_query(" 
     INSERT INTO specialist_info (spec_id, name, spec_username, spec_password, online_check) 
     VALUES('$spec_id', '$name', '$spec_username',spec_password('$password'), '$online_check')"); 

什麼是spec_password('$password')什麼?

spec_password不是函數。你的男人說$spec_password?意思是$password是數組索引?林不知道你要什麼

+0

哦,好吧,我現在看到它,謝謝! – 2011-03-30 00:38:35

+0

它假設是md5('$ password') – 2011-03-30 00:39:24

1

嘗試...

$result = mysql_query("INSERT INTO specialist_info(
spec_id, 
name, 
spec_username, 
spec_password, 
online_check 
)VALUES(
'$spec_id', 
'$name', 
'$spec_username', 
'".spec_password($password)."', 
'$online_check')");