0

いくつかのデータを含むデータベースを作成しました。私はすでにJqueryMobileでデータを表示することができます。唯一の問題は、編集ページにアクセスしてデータを更新し、ホームページに戻っても、URLが同じままであるということです。例:

私はexample.com/index.phpにいます--->example.com/index.php?id=1(または他の番号)に向かうリンクをクリックします->データを更新し、クリックしてに戻ります更新されたデータを含むindex.phpですが、URLはindex.phpのコンテンツでexample.com/index.php?id=1のままです。よくわかりません!!これは私の2つのファイルです:

index.php

  <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />

<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>

 </head>
 <body>


<div data-role="page">
    <div data-role="header">
        <h3>
            AmateurStandenLive
        </h3>
    </div>
    <div data-role="content">
        <div data-role="collapsible-set" data-collapsed="true" >
                 <div data-role="collapsible" data-collapsed="true" data-theme="a">
                <h3>Oost</h3>


                <div data-role="collapsible" data-collapsed="true" data-theme="b">
                <h3>4G</h3>

                <ul data-role="listview" >
                    <?php
                try
                {
                    $connection = mysql_connect("localhost","zomervak_amalive","***");
                    mysql_select_db("***", $connection);
                    $result = mysql_query("SELECT * FROM zattop");

                    while($row = mysql_fetch_array($result))
                    {
                        echo "<li><a href='edit.php?id=" . $row['id'] . "'><h2>" . $row['thuis'] . " - "  . $row['uit'] . "</h2><h3>" . $row['thuisscore'] . " - " . $row['uitscore'] . "</h3></a></li>";
                    }

                    mysql_close($connection);
                }
                catch(Exception $e)
                {
                    echo $e->getMessage();
                }
            ?>
                </ul>
                </div>
            </div>
          <div data-role="collapsible" data-collapsed="true" data-theme="a">
                <h3>West</h3>  
                <div data-role="collapsible" data-collapsed="true" data-theme="b">
                <h3>4B</h3>
      </div>
        </div>

    </div>

edit.php

 </head>
 <body>
 <?php

 if ($error != '')
 {
 echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
 ?>

 <form action="" method="post">
 <input type="hidden" name="id" value="<?php echo $id; ?>"/>

 <table border="1">
 <tr>
 <td colspan="2"><b><font color='Red'>Edit Records </font></b></td>
   </tr>
 <tr>
 <td width="179"><b><font color='#663300'>Name<em>*</em></font></b></td>
 <td><label>
 <input type="text" name="thuisscore" value="<?php echo $thuisscore; ?>" />
 </label></td>
 </tr>

 <tr>
 <td width="179"><b><font color='#663300'>Address<em>*</em></font></b></td>
 <td><label>
 <input type="text" name="uitscore" value="<?php echo $uitscore; ?>" />
 </label></td>
 </tr>


 <tr align="Right">
 <td colspan="2"><label>
 <input type="submit" name="submit" value="Edit Records">
  </label></td>
 </tr>
 </table>
 </form>
 </body>
 </html>
 <?php
  }


 /* Database Connection */

 $sDbHost = 'localhost';
 $sDbName = '***';
 $sDbUser = 'zomervak_amalive';
 $sDbPwd = '***';

 $dbConn = mysql_connect ($sDbHost, $sDbUser, $sDbPwd) or die ('MySQL connect failed. ' . mysql_error());
 mysql_select_db($sDbName,$dbConn) or die('Cannot select database. ' . mysql_error());


if (isset($_POST['submit']))
{

if (is_numeric($_POST['id']))
{

$id = $_POST['id'];
$thuisscore = mysql_real_escape_string(htmlspecialchars($_POST['thuisscore']));
$uitscore = mysql_real_escape_string(htmlspecialchars($_POST['uitscore']));



if ($thuisscore == '' || $uitscore == '' )
{

$error = 'ERROR: Please fill in all required fields!';


valid($id, $thuisscore, $uitscore, $error);
}
else
{

mysql_query("UPDATE zattop SET thuisscore='$thuisscore', uitscore='$uitscore' WHERE     id='$id'")
or die(mysql_error());

header('Location: index.php');
}
}
else
{

echo 'Error!';
}
}
else

{

if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{

$id = $_GET['id'];
$result = mysql_query("SELECT * FROM zattop WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);

if($row)
{

$thuisscore = $row['thuisscore'];
 $uitscore = $row['uitscore'];


valid($id, $thuisscore, $uitscore,'');
}
else
{
echo "No results!";
}
}
else

{
echo 'Error!';
}
}
?>

誰でも助けることができますか?

4

1 に答える 1

0

一部の変数が設定されていないことを意味する Undefined エラーが発生しています。

問題は入力フィールドにあります。名前は設定されていません。

     <input type="text" name="name" id="name" value="<?php echo $thuisscore; ?>"  />
     </div>

     <div data-role="fieldcontain">
     <label for="name"><b>Uitteam:</b></label>
     <input type="text" name="name" id="name" value="<?php echo $uitscore; ?>"  />

どちらも 'name="name"' という同じ名前を持ち、後でこれらを POST 変数として要求することに注意してください。

$thuisscore = mysql_real_escape_string(htmlspecialchars($_POST['thuisscore']));

$uitscore = mysql_real_escape_string(htmlspecialchars($_POST['uitscore']));

しかし、それらは存在しません。

だからこれを試してください。

<input type="text" name="thuisscore" id="name" value="<?php echo $thuisscore; ?>"  />
     </div>

     <div data-role="fieldcontain">
     <label for="name"><b>Uitteam:</b></label>
     <input type="text" name="uitscore" id="name" value="<?php echo $uitscore; ?>"  />

また、ページの上部で $error 変数を初期化します ($error = null;)

リダイレクトを index.php ではなく view.php に変更することを忘れないでください

header('Location: index.php'); // becomes header('Location: view.php');
于 2013-01-13T01:08:32.140 に答える