0

这真的很奇怪,我不知道为什么会这样。我的其他文件工作正常(登录、注册和 memberadd)但是,在 memberaddprocess 文件上,当它尝试连接到数据库时,它说我的数据库不存在。另一个工作正常,只有 memberadd 过程。如果有人知道为什么,请解释一下。

这是我的 memberadd.php 代码

<?php
session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/chtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="Web Programming :: Assignment 2" />
    <meta name="Keywords" content="Web, programming" />
    <title>Member Login</title>
</head>

<body>
    <h1>My Member System</h1>

</body>
</html>

<?php
require_once('sqlconnect.inc.php');


if(isset($_SESSION['membername'] ))
    {

    echo "".$_SESSION['membername']."<p>Add Member Page</p>";


$conn = @mysqli_connect($host, 
        $user, 
        $pswd, 
        $dbnm);

    if (!$conn) {
        echo "<p>Database connection failure</p>"; 
    } else {

    @mysqli_select_db($conn, $dbnm)
        or die ("Database not available");
    }

    $memberHid = $_SESSION['membername'];

    $query = "SELECT member_name FROM team";
    $result = mysqli_query($conn, $query);
    if(!$result) {
        echo "<p>Query failed to execute, Error with: ",    $query, "</p>";
        } 

    $queryFetch = mysqli_fetch_row($result);
    //echo "<p> $queryResult1</p>"; 
    $m=0;
    while($queryFetch)
    {
    $mQueryFetch[$m] = $queryFetch[0];
    $queryFetch = mysqli_fetch_row($result);
    $m++;
    }
    $i=0;
    $query2 = "SELECT member_id 
                FROM team 
                WHERE member_name='$memberHid'";

    $result2 = @mysqli_query($conn, $query2);
    $queryFetchResult = mysqli_fetch_row($result);
    $memId = $queryFetchResult[0];

    $query3 = "SELECT COUNT(*) 
               FROM myteam 
               WHERE member_id1 = '$memId'"; //query for counting the no of friends 

    $resultSelect = @mysqli_query($conn,$query3)
                or die ("<p>Query failed to execute.</p>". "<p>Error with:" . mysqli_errno($conn) .":" . mysqli_error($conn))."</p>";

    $arCount = mysqli_fetch_row($resultSelect); 
                echo "<p>Number of Current team member is"." ". $arCount[0]."  "."</p>";

    $querySelect = "SELECT member_id2 FROM myteam WHERE member_id1 = '$memId'";

    $resultSelect2 = @mysqli_query($conn, $querySelect);
    $memArr = mysqli_fetch_row($resultSelect2);
    if($memArr)
    {
        while($memArr)
        {
            foreach($memArr as $value)
                {
                    $querySelect3 = "SELECT member_name
                                     FROM team
                                     WHERE member_id = '$value'";

                    $queryResult = @mysqli_query($conn,$querySelect3);
                    $fetchArr = mysqli_fetch_row($queryResult);
                    foreach($fetchArr as $value)
                    {
                        $newDat[$a] = $value;
                        $a++;
                    }       
                }
                $memArr = mysqli_fetch_row($resultSelect2);
            }

        $curLog = array_diff($mQueryFetch, $newDat); //for displaying profile names without the currently logged in user and his old friends profile names

    $querySelect2 = "SELECT member_name 
                     FROM team;";

    $querySelectResult = @mysqli_query($conn,$querySelect2)
                        or die ("<p>Query Failed to Execute.</p>". "<p>Error with" . mysqli_errno($conn) .":" . mysqli_error($conn))."</p>";

    echo "<table width='20%' border='1'>";
    echo "<tr><th>Member Name</th>";
    echo "<th>Status</th></tr>";
    $fetchArray = mysqli_fetch_row($querySelectResult);
    foreach($diff as $value)
    {
        if($value!=$_SESSION['membername'])
        {
            echo "<tr><td>{$value}</td>";
            $memberHid1 = $value;
            $memberHid = $_SESSION['membername'];
            echo "<td>"?>
            <form action ="memberaddprocess.php" method = "post" >
            <?php echo'<input type="hidden" name="memberHid1"  value="'.htmlspecialchars($memberHid1).'" />';?>
            <?php echo'<input type="hidden" name="memberHid"  value="'.htmlspecialchars($memberHid).'" />';?>
            <p><input type="submit" name="Addmember" value="AddMember" /></p>
            </form>
            <?php "</td></tr>"; 
        }
        $fetchArray = mysqli_fetch_row($querySelectResult);
    }   
        echo"</table>";
    }
    else
    {
        $n=0;
        $querySelect2 = "SELECT member_name FROM team ; ";
        $querySelectResult = @mysqli_query($conn, $querySelect2)
                        or die ("<p>Query Failed to Execute.</p>". "<p>Error with" . mysqli_errno($conn) .":" . mysqli_error($conn))."</p>";

        $fetchArray = mysqli_fetch_row($querySelectResult);
        while($fetchArray)
        {
            if($fetchArray[0] != $_SESSION['membername'])
            {
                $name[$n] = $fetchArray[0];
                $n++;
            }

            $fetchArray = mysqli_fetch_row($querySelectResult);
        }

        sort($name);
        echo "<table width='20%' border='1'>";
        echo "<tr><th>Member Name</th>";
        echo "<th>Status</th></tr>";

        for($n = 0; $n<sizeof($name); $n++)
        {
            $memberHid1 = $name[$n];
            $memberHid = $_SESSION['membername'];
            echo "<tr><td>{$memberHid1}</td>";
            echo "<td>"?>
            <form action ="memberaddprocess.php" method = "post" >
            <?php echo'<input type="hidden" name="memberHid1"  value="'.htmlspecialchars($memberHid1).'" />';?>
            <?php echo'<input type="hidden" name="memberHid"  value="'.htmlspecialchars($memberHid).'" />';?>
            <p><input type="submit" name="Addmember"value="AddMember" /></p>
            </form>
            <?php "</td></tr>"; 
        }
        echo "</table>";
    }
    echo"<p><a href='memberlist.php'>List members</a></p>";
    echo"<p><a href='logout.php'>Log out</a></p>";
    }
    else
    {
    echo "<p> Unauthorized access.Pls login</p>";
    echo"<p><a href='login.php'>Log in</a></p></div>";
    }



?>  

这是我的 memberaddprocess.php 代码

<?php
//////////////////////////////////////
    session_start();
    require_once('sqlconnect.inc.php');
/////////////////////////////////////

    $memberHid1 = $_POST['memberHid1'];  
    $new_session = $_POST['memberHid']; 

    $conn = @mysqli_connect($host, 
        $user, 
        $pswd, 
        $dbnm);

    if (!$conn) {
        echo "<p>Database connection failure</p>"; 
    } else {

    @mysqli_select_db($conn, $dbnm)
        or die ("Database not available");
    }

    $query = "SELECT member_id 
              FROM team 
              WHERE member_name = '$memberHid1'";

    $queryResult = @mysqli_query($conn, $query)
                or die ("<p>Unable to execute query.</p>". "<p>Error code:" . mysqli_errno($conn) .":" . mysqli_error($conn));

    $fetchArr = mysqli_fetch_row($queryResult);

    $memberHid3 = $fetchArr[0];             
    $memberHid = $_SESSION['membername'] = $new_session;

    $query2 = "SELECT member_id 
               FROM member 
               WHERE member_name = '$memberHid'";

    $queryResult2 = @mysqli_query($conn,$query2)
        or die ("<p>Unable to execute query.</p>". "<p>Error code" . mysqli_errno($conn) .":" . mysqli_error($conn));

    $fetchArr2 = mysqli_fetch_row($queryResult2);
    $memberHid4 = $fetchArr2[0];

    $query3 = "INSERT INTO myteam 
               VALUES($memberHid4, $memberHid3)";

    $queryResult3 = @mysqli_query($conn,$query3)
        or die ("<p>Unable to execute query.</p>". "<p>Error code" . mysqli_errno($conn) .":" . mysqli_error($conn))."</p>";
                echo "<p>$memberHid1"."  "." Successfully added</p>";

        $queryCount = "SELECT COUNT(*) 
                       FROM team";
        $countResult = @mysqli_query($conn,$queryCount);
        $fetchCountArr = mysqli_fetch_row($countResult);    
        for($n=0;$n<$fetchCountArr[0];$n++)
        {
            $pst = $n+1;
            $query4 = "SELECT member_id2
                        FROM myteam 
                        WHERE friend_id1 = '$pst'";

            $countResult2 = @mysqli_query($conn,$query4);
            $countArr = mysqli_fetch_row($countResult2);
            $a=0;
            while($countArr)
            {
                $a++;
                $countArr = mysqli_fetch_row($countResult2); //echo "<p>$a</p>";
            }

            $query4 = "UPDATE team 
                       SET num_of_members= '$a' 
                       WHERE member_id = '$pst' ";

            $countResult2 = @mysqli_query($conn,$query4);

        }

    $querySelect = "SELECT member_id2 
                    FROM myteam 
                    WHERE member_id1 = '$memberHid4'";

    $querySelectResult = @mysqli_query($conn, $querySelect);
    $fetchArr = mysqli_fetch_row($querySelectResult);

    while($fetchArr)
    {
        foreach($fetchArr as $value)

        {
            //echo $value;
            $querySelect2 = "SELECT member_name 
                            FROM friends where friend_id='$value'";
            $querySelectResult2 = @mysqli_query($conn, $querySelectResult2);
            $fetchArr2 = mysqli_fetch_row($querySelectResult2);
            foreach($fetchArr2 as $value)
            {
                //echo $value;
            }       
        }
        $fetchArr = mysqli_fetch_row($querySelectResult);
    }

    header("Location:memberadd.php");
    echo('<a href="memberlist.php">Updated memberlist</a></p></div>');
                //header('Location: friendadd.php'); 

?>
4

1 回答 1

0

确定问题并不容易,但我在 mysql 论坛上找到了一个可能与您的问题有关的主题( MySQL 说表不存在,但它确实存在)。

确保计算机上没有其他 mysql 实例很重要。这也可能导致您的问题。

于 2013-11-01T01:45:25.913 回答