0

このスクリプトを更新しました。スクリプト要件の動的ドロップダウン部分は、このフォーラムの優れたメンバーからの貢献によって達成されました。現在、ドロップダウン リストからアイテムが選択されたときに、フォームのフィールドの一部を自動入力するように取り組んでいます。たとえば、ドロップダウンから pipeno と wallthickiness を選択した場合、対応する DJoint、pipeno2、Heatno1、heatno 2 のタプルをレコードに配置して、データベースからフォームのさまざまなフィールドに自動的に入力したいと考えています。 auto-populate は、私が php scipt でエコーしているものですが、スクリプトの最後の行でこのエラーが発生し続けるため、スクリプトに何か問題があると思います。私は本当にいくつかの貢献に感謝し、この問題を助けます

解析エラー: 構文エラー、C:\Users\imasha\Documents\My Web Sites\Personal Site1\dropdown2.php の 63 行目の予期しないファイルの終わり

ここに私の更新されたスクリプトがあります

        <?php
         // Php Code to connect to postgresqldatabase
         include ("connection.php");

        $query = 'select * from fieldtally order by pipeno asc'; 
        $result = pg_query($db_handle,$query); 
        while ($row = pg_fetch_row($result))
        {

       // Creates Arrays to use in dropdowns
            $pipeno_array[] = $row[0];
            $wallthickness_array[] = $row[1];
        } 

        // Declare dropdown functions for the HTML form
        function dropdown($field_name, $num){

        // Creates the Dropdown
            echo "<select name=\"".$field_name."\" id=\"".$field_name.$num."\"\n";
            echo "<option value=\"\"> --- Select --- </option>\n";
            // Chooses which array to use for Dropdown options
            global $pipeno_array, $wallthickness_array;
            $name_array = ($field_name == 'pipeno') ? $pipeno_array : $wallthickness_array;
            // Creates the Dropdown options based off the array above
            foreach($name_array as $k){
                echo "<option value=\"$k\">$k</option> \n"; }
            // Ends the Dropdown
             echo "</select>\n"; 
             if($field_name == 'pipeno'){
                $wallthickness = 'wallthickness';
                echo $formValue->DJNo($DJno);
                echo $formValue->Heatno1($pipeweight);
                echo $formValue->pipeno2($pipeno2);
                echo $formValue->Heatno2($pipegrade);
        }
        ?>

        <html>
        <head><title>UG Pipeline Fiedl Data Capture</title>
        </head>
        <body>
        <p></p>
        <form action="<?php echo $PHP_SELF; ?>" method="post">
        <table width="600" cellpadding= "10" cellspacing="1" border="2">
        <tr align="center" valign="top">
        <td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
        <h3>Input Field Tally Information</h3>
        Select Pipe No:<?php dropdown('pipeno', 1); ?>  Select Wall Thickness:<?php dropdown('wallthickness', 1); ?><br /><br />

     DJ No:<input type="text" name="jointno" value="<?php $DJno = "jointno"; echo $formValue->DJNo($DJno);?>"> 

    HeatNo1: <input type="text" name="pipeweight" value="<?php $pipeweight = "pipeweight"; echo $formValue->Heatno1($pipeweight); ?>"><br><br>

    pipeno2: <input type="text" name="loadtally" value="<?php $pipeno2 = "loadtally"; echo $formValue->pipeno2($pipeno2);?>"> 

    HeatNo2: <input type="text" name="pipeweight" value="<?php $pipeweight = "pipegrade"; echo $formValue->Heatno2($pipegrade); ?>"><br><br>

    Input Serial No: <input type="text" name="serialno"><br><br> 

    Input measured Length: <input type="text" name="measuredlength"><br><br>

    <input type="Submit" name="submit" value="Submit">

    </td></tr></table>
    </form>

<p>
<form action="fieldbend.php" method="post">
<table width="600" cellpadding="10" cellspacing="1" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#ff9d9d">
<h3>Input Field Bend Information</h3>
Select Pipe No:<?php dropdown('pipeno', 2); ?>  Select Wall Thickness:<?php dropdown('wallthickness', 2); ?><br /><br />
Input Measured Distance: <input type="text" name="measureddistance"><br /><br /> Input Bend Angle: <input type="text" name="benddegree"><br><br>
Input Bend Type: <input type="text" name="bendtype"><br><br>
<input type="Submit" name="submit" value="Submit">
</td></tr></table>
</form></P>

<p>
<form action="apptally.php" method="post">
<table width="600" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#66CC66">
<h3>Input App. Tally Information</h3>
 Input Type: <input type="text" name="type">   Input Serial No: <input type="text" name="serialno"><br><br>
Input Reference ID: <input type="text" name="referenceid"><br><br>
<input type="Submit" name="submit" value="Submit">
</td></tr></table>
</form></P>
     </body>
    </html>
4

2 に答える 2

2

コードにいくつかの問題があることに気付きました。

Mauricio が指摘した最初のものは、あなたがあなたのタグ<options></options>の中にいないということです。また、オプションがであり、取得しているのに、<select name="education"></select>なぜ名前を選択するのですか?education$row['pipeno']$_POST['pipeno']

2 番目の問題は、<options></options>.

//<option> value="<?=$row["pipeno"]; ?>"><?=$row["pipeno"]; ?></option>
        print ("<option> $row[0]</option>");

<option>開始タグをコメントアウトしています。すでに閉じているためvalue、タグの外側にあります。各オプションを&<option>で 2 回エコーしているようです。<option value="<?=$row["pipeno"]; ?>"><?=$row["pipeno"]; ?></option>print ("<option> $row[0]</option>");

EDIT これは、質問の編集済みコードと一致するように更新されます

これをもう一度見てみると、ドロップダウンの作成方法に問題があると思います。これを関数として一番上に置いてみてください。後で必要な場所で呼び出すだけです。次に、ドロップダウンがpipenoまたは用であるかどうかを指定してから、ドロップダウンwallthicknessの数を指定するだけで、一意の を作成できますid

コードを次のように変更してみてください-

<?php
 $PGHOST = "localhost:25376";
 $PGDATABASE = "Pipeline";
 $PGUSER = "postgres";
 $PGPASSWORD = "Casa2009";
 $PGPORT = 5432;
 $db_handle = pg_connect("dbname=$PGDATABASE user=$PGUSER password=$PGPASSWORD");
 if ($db_handle) {
 echo 'Connection attempt succeeded.';
 } else {
 echo 'Connection attempt failed.';
 }

$query = 'select * from fieldtally order by pipeno asc '; 
$result = pg_query($db_handle,$query); 
while ($row = pg_fetch_row($result))
{
    // Creates Arrays to use in dropdowns
    $pipeno_array[] = $row[0];
    $wallthickness_array[] = $row[1];
} 

 // This function creates dropdowns that can be used in your forms
function dropdown($field_name, $num){
    // Creates the Dropdown
    echo "<select name=\"".$field_name."\" id=\"".$field_name.$num."\"\n";
    echo "<option value=\"\"> --- Select --- </option>\n";
    // Chooses which array to use for Dropdown options
    global $pipeno_array, $wallthickness_array;
    $name_array = ($field_name == 'pipeno') ? $pipeno_array : $wallthickness_array;
    // Creates the Dropdown options based off the array above
    foreach($name_array as $k){
        echo "<option value=\"$k\">$k</option>\n"; }
    // Ends the Dropdown
    echo "</select>\n";
}
?>

<html>
<head><title>UG Pipeline Fiedl Data Capture</title>
</head>
<body>
<p></p>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<table width="600" cellpadding= "10" cellspacing="1" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Input Field Tally Information</h3>
Select Pipe No:<?php dropdown('pipeno', 1); ?>  Select Wall Thickness:<?php dropdown('wallthickness', 1); ?><br /><br />
Input Joint No: <input type="text" name="jointno"> Input measured Length: <input type="text" name="measuredlength"><br><br>
Input Serial No: <input type="text" name="serialno"><br><br> 
<input type="Submit" name="submit" value="Submit">
</td></tr></table></form> 

<p>
<form action="fieldbend.php" method="post">
<table width="600" cellpadding="10" cellspacing="1" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#ff9d9d">
<h3>Input Field Bend Information</h3>
Select Pipe No:<?php dropdown('pipeno', 2); ?>  Select Wall Thickness:<?php dropdown('wallthickness', 2); ?><br /><br />
Input Measured Distance: <input type="text" name="measureddistance">  Input Bend Angle: <input type="text" name="benddegree"><br><br>
Input Bend Type: <input type="text" name="bendtype"><br><br>
<input type="Submit" name="submit" value="Submit">
</td></tr></table>
</form></P>

<p>
<form action="apptally.php" method="post">
<table width="600" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#66CC66">
<h3>Input App. Tally Information</h3>
 Input Type: <input type="text" name="type">   Input Serial No: <input type="text" name="serialno"><br><br>
Input Reference ID: <input type="text" name="referenceid"><br><br>
<input type="Submit" name="submit" value="Submit">
</td></tr></table>
</form></P>

</body>
</html>

これが私のサンプルfieldtallyテーブルです-

<code>fieldtally</code> テーブル

フォームは次のようになります - HTML フォーム

注: select size="3" を使用してこの画像の複数行を表示しましたが、上記のコードでは標準の 1 行のままにしました。

于 2012-10-11T22:02:23.287 に答える
0

そしてそのここ:

Select Pipe No: <select name="education"> </select>  Select Wall Thickness: <input type="text" name="wallthickness"><br><br>

タグ選択を開いて同じ行で閉じ、要素を配置した後です。これを解決するには、次の行を修正します。

変化する:

Select Pipe No: <select name="education"> </select>  Select Wall Thickness: <input type="text" name="wallthickness"><br><br>

に:

Select Wall Thickness: <input type="text" name="wallthickness"><br><br>
Select Pipe No: <select name="education"> 

次のように本文を閉じる前に選択タグを閉じます。

</select>
</body>

ここでは、要素をタグ選択に入れています。それを試してみてください

于 2012-10-11T20:27:27.507 に答える