0

私はphpにかなり慣れていないので、更新されたデータを含むフォームを再表示することに問題があります。

これまでの話:

「ユーザー」を電子メール アドレスで識別する登録ページとログオン ページがあります。ログインすると、ユーザーは自分の「メンバー」ページに移動し、そのユーザーが保持している個人データが表示されます。その後、必要に応じてそのデータを編集するよう招待されます。これにより、「更新」ページに移動し、完了時にデータベースが (非表示の) 「更新 + ac」ページを介して更新され、独自の「マスター」ページに戻ります。問題は、「メンバー」ページを取得して更新されたデータをフォームに再表示することも、フォーム自体を再表示することもできないことです。

「メンバー」ページに関連するコードは次のとおりです。

<?php
        include_once 'login.php';
        include_once 'functions.php';

        if (isset($_SESSION['user']))
            {
            $user = $_SESSION['user'];        

        mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
        mysql_select_db($dbname) or die("Unable to connect: " . mysql_error());

        $data = "SELECT * FROM `names` WHERE email='$user'";
        $result=mysql_query($data) or die(mysql_error());
    while($row=mysql_fetch_array($result)){
    }
?>
    <table border='1px' style="background-color:#F0F8FF; font-weight: bold;" >
        <caption>Personal Record</caption>

    <tr>
    <th>ID</th>
        <td><?php
            echo $row['id'];
         ?></td>
    </tr>
    <tr>
    <th>Name</th>
        <td><?php
            echo $row['name'];
         ?></td>
    </tr>

    <tr>
    <th>E-Mail</th>
        <td><?php
            echo $row['email'];
         ?></td>
    </tr>

    <tr>
    <th>Main Telephone</th>
        <td><?php
            echo $row['maintel'];
         ?></td>
    </tr>
    <tr>
    <th>Mobile Telephone</th>
        <td><?php
            echo $row['mobtel'];
         ?></td>
    </tr>
    <tr>
    <th>Organisation</th>
        <td><?php
            echo $row['organisation'];
         ?></td>
    </tr>
    <tr>
    <th>Group Leader</th>
        <td><?php
            echo $row['group_leader'];
         ?></td>
    </tr>
    <tr>
    <th>Supervisor</th>
        <td><?php
            echo $row['supervisor'];
         ?></td>
    </tr>
    <tr>
    <th>Volunteer</th>
        <td><?php
            echo $row['volunteer'];
         ?></td>
    </tr>
    <tr>
    <th>Assessor</th>
        <td><?php
            echo $row['assessor'];
            }

         ?></td>
    </tr>
    </table>


        <p><br />
        <form method="post" action="update.php">
            <input name="Submit1" type="submit" value="Edit" style="width: 67px" /></form>
        </p>
        <p>&nbsp;</p>

以下は「update.php」ページのコードです。

<?php
include_once 'login.php';
        include_once 'functions.php';

    session_start();
// Connect to server and select database.
    mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
        mysql_select_db($dbname) or die("Unable to connect: " . mysql_error());
// get value of id that sent from address bar
            if (isset($_SESSION['user']))
            {
            $user = $_SESSION['user'];
// Retrieve data from database
$sql="SELECT * FROM names WHERE email='$user'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
}
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>E-Mail</strong></td>
<td align="center"><strong>Main Tel</strong></td>
<td align="center"><strong>Mob Tel</strong></td>
<td align="center"><strong>Organisation</strong></td>
<td align="center"><strong>Group Leader</strong></td>
<td align="center"><strong>Supervisor</strong></td>
<td align="center"><strong>Volunteer</strong></td>
<td align="center"><strong>Assessor</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="name" type="text" id="name" value="<? echo $rows['name']; ?>"></td>
<td><input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" size="40"></td>
<td align="center"><input name="maintel" type="text" id="maintel" value="<? echo $rows['maintel']; ?>" size="15"></td>
<td align="center"><input name="mobtel" type="text" id="mobtel" value="<? echo $rows['mobtel']; ?>"></td>
<td align="center"><input name="organisation" type="text" id="organisation" value="<? echo $rows['organisation']; ?>"></td>
<td align="center"><input name="group_leader" type="text" id="group_leader" value="<? echo $rows['group_leader']; ?>"></td>
<td align="center"><input name="supervisor" type="text" id="supervisor" value="<? echo $rows['supervisor']; ?>"></td>
<td align="center"><input name="volunteer" type="text" id="volunteer" value="<? echo $rows['volunteer']; ?>"></td>
<td align="center"><input name="assessor" type="text" id="assessor" value="<? echo $rows['assessor']; ?>"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?
// close connection
mysql_close();
?>

最後に、「upate_ac.php」ページのコードは次のとおりです。

<?php
        include_once 'login.php';
        include_once 'functions.php';
// Connect to server and select database.
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
        mysql_select_db($dbname) or die("Unable to connect: " . mysql_error());
// update data in mysql database
$id = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$maintel = $_POST['maintel'];
$mobtel = $_POST['mobtel'];
$organisation = $_POST['organisation'];
$group_leader = $_POST['group_leader'];
$supervisor = $_POST['supervisor'];
$volunteer = $_POST['volunteer'];
$assessor = $_POST['assessor'];
$sql="UPDATE `names` SET id='$id', `name`='$name', `email`='$email', `maintel`='$maintel', `mobtel`='$mobtel', `organisation`='$organisation', `group_leader`='$group_leader', `supervisor`='$supervisor', `volunteer`='$volunteer', `assessor`='$assessor' WHERE `id`='$id''";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='member.php?view=$user'>View result</a>";
}
else {
echo "ERROR";
}
?>

何が起こるかというと、「Successfull」と「View Result」が表示されます。[結果の表示] をクリックすると、[メンバー] ページに移動しますが、フォームが表示されません。

助けていただければ幸いです。

4

1 に答える 1

0

ページのsession_start()先頭に がありません。さらに、 update_ac.php にリンクを次のように配置しています

<a href='member.php?view=$user'>View result</a>".

したがって、それを使用してメンバーページのユーザーフィールドを取得し、$_GET['view']それを使用してさらにクエリを実行する必要$_SESSIONがあります。

于 2012-04-07T13:48:50.163 に答える