从PHP添加数据

时间:2011-03-29 22:48:06

标签: php mysql

您好我想从表中添加数据。但是,它没有出现在XAMPP(MySQL)

我做错了什么。我花了很长时间才看到有什么不对,但我找不到任何错误。

FYI。

config.php将PHP连接到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>

2 个答案:

答案 0 :(得分: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表示为数组索引?我不确定你要去的是什么

答案 1 :(得分: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')");