基本パターンの最近のブログ記事

php データINSERT

| コメント(0)

@$prefPanel = $_POST['panel'];

        if(!($_POST["panel"])){

    echo "何か入力してください。";

    echo "<form action=\"./database.php\" method=\"post\">";

    echo "<input type=\"submit\" name=\"submit\" value=\"戻る\">";

    echo "</form>";

    exit;

    } 

 $$prefToshi = $_POST['toshi'];

$prefName= $_POST['name'];

$sql = "INSERT INTO user(name,toshi,panel)  VALUES('".$prefName."', '".$prefToshi."', '".$prefPanel."')";

$result = executeQuery($sql);

echo "<form name=\"formauto\" action=\"./database.php\" method=\"post\">";

echo "<SCRIPT language=\"JavaScript\">document.formauto.submit();</SCRIPT>";

echo "</form>";

php 基本select SQL文

| コメント(0)

$sql = "SELECT * FROM users";

  $result = executeQuery($sql);
 
  $rows = mysql_num_rows($result);
 
  if($rows){
    while($row = mysql_fetch_array($result)) {
      @$tempHtml .= "<tr>";
      $tempHtml .= "<td>".$row["id"]."</td>";
      $tempHtml .= "<td>".$row["created"]."</td>";
      $tempHtml .= "<td>".$row["approval"]."</td>";
      $tempHtml .= "<td>".$row["userid"]."</td>";
      $tempHtml .= "<td>".$row["username"]."</td>";
      $tempHtml .= "<td align = 'left'>".$row["password"]."</td>";
      $tempHtml .= "<td align = 'left'>".$row["pass"]."</td>";
      $tempHtml .= "<td align = 'left'>".$row["email"]."</td>";
      $tempHtml .= "<td align = 'left'>".$row["active"]."</td>";
      $tempHtml .= "<td><a href=\"user_update.php?id=".$row["id"]."\" target=\"_self\">update</a></td>";
      $tempHtml .= "<td><a href=\"user_delete2.php?id=".$row["id"]."\" target=\"_self\">Del</a></td>";
      $tempHtml .= "</tr>\n";
    }
    $msg = $rows."件のデータがあります。";
  }else{
    $msg = "データがありません。";
  }
 
  //結果保持用メモリを開放する
  mysql_free_result($result);
 
 
<form action="user_insert.php" method="post">
<table>
 
     <tr><th>created</th>
      
     <td><input type="text" name="created" id="date" value="2015/05/20"></td>
      
     </tr>
      
     <tr><th>userid</th>
      
     <td><input type="text" name="userid" style="ime-mode:disabled"></td>
     </tr>
      
     <tr><th>username</th>
      
     <td><input type="text" name="username" style="ime-mode:disabled"></td>
     </tr>
      
     <tr><th>password</th>
      
     <td><input type="text" name="password" style="ime-mode:disabled"></td>
     </tr>
 
      <tr><th>pass</th>
      
     <td><input type="text" name="pass" style="ime-mode:disabled"></td>
     </tr>   
           
     <tr><th>email</th>
      
     <td><input type="text" name="email" style="ime-mode:disabled"></td>
     </tr>   
     
           
    <th>active</th>
      
     <td><input type="text" name="active" style="ime-mode:disabled" value="31"></td>
        
     
           
     <tr><th>操作</th>
      
     <td>
            <input type="submit" name="submit" value="作成">
     </td></tr>
 
           </form>
</table>
 
 
 
<table>
   <tr>
     <th>id</th>
     <th>created</th>
     <th>approval</th>
     <th>userid</th>
     <th>username</th>
     <th>password</th>
     <th>pass</th>
     <th>email</th>
     <th>active</th>
     <th colspan="2">EDIT</th>
    </tr>
      <?= @$tempHtml ?>
</table>

php データ削除

| コメント(0)
<?php

<?php

if(@$_POST['approval'] == ''){

   $prefData = $_GET['data'];

   $prefId = $prefData[0];

   $prefSite = $prefData[1];

   $prefYear = $prefData[2];

echo "<form action=\"./search_input.php\" method=\"post\">";

echo "<input type=\"hidden\" name=\"year\" value=".$prefYear.">";

echo "<input type=\"hidden\" name=\"keyword\" value=".$prefSite.">";

echo "<input type=\"submit\" name=\"submit\" value=\"戻る\">";

echo "</form>";

}

if(@$_POST['approval'] == 'approval'){

      $prefId = $_POST["id"];
      $prefSite = $_POST['s_id'];
      $prefYear = $_POST['year'];

       $sql = "DELETE FROM management WHERE id = ".$prefId;

      $result = executeQuery($sql);

      echo "<form  name=\"formauto\" action=\"./search_input.php\" method=\"post\">";

      echo "<input type=\"hidden\" name=\"year\" value=".$prefYear.">";

      echo "<input type=\"hidden\" name=\"keyword\" value=".$prefSite.">";

      echo "<SCRIPT language=\"JavaScript\">document.formauto.submit();

      </SCRIPT>"; echo "</form>"

; } ?>

<br><br><br>

<form name="form" action="./delete.php" method="post">
    <input type="hidden" name="approval" value="approval">
    <input type="hidden" name="id" value="<?= $prefId ?>">
    <input type="hidden" name="s_id" value="<?= $prefSite ?>">
    <input type="hidden" name="year" value="<?= $prefYear ?>">
    <input type="submit" name="submit" value = "削除実行">
</form>

php ファイル名取得、複数GET

| コメント(0)

ファイル名を取得する、拡張子なしここから

$Filename = basename($_SERVER["PHP_SELF"],".php");

関連するソース

$tempHtml .= "<td><a href=\"./update.php?data[]=".$row["did"]." & data[]=".$Filename."\" target=\"_self\">編集</a></td>";

//////受取り

$prefData = $_GET['data'];

$prefDid = $prefData[0];

$Filename = trim($prefData[1]);

//配列要素にスペースが入ってしまうので取り除く

$preDate = trim($prefData[2]);

//配列要素にスペースが入ってしまうので取り除く

//////持ち回り

<input type="hidden" name="filename" value="<?= $Filename ?>"> $Filename = $_POST['backhome'];

//////ファイル名で分岐する

if($Filename == "payout_view"){

  echo "<form  name=\"formauto\" action=\"./$Filename.php\" method=\"post\">";

  echo "<input type=\"hidden\" name=\"dates\" value=".$dates.">";

  echo "<input type=\"hidden\" name=\"datee\" value=".$datee.">";

  echo "<SCRIPT language=\"JavaScript\">document.formauto.submit();</SCRIPT>";

  echo "</form>";

}

if($Filename == "stock_view"){

  echo "戻れません。";

 }

if($Filename == "list_select"){

  echo "<form action=\"./$Filename.php\" method=\"post\">";

  echo "<input type=\"submit\" name=\"submit\" value=\"戻る\">";

  echo "</form>";

}

php 基本パターン 更新編集

| コメント(0)
「update.php」
<?php
  
  $prefId = $_GET['id'];
  
  $sql = "SELECT * FROM tools WHERE id = ".$prefId;
  $result = executeQuery($sql);
  
  $rows = mysql_num_rows($result);
  
  if($rows){
    $row = mysql_fetch_array($result);
          $prefMaker = $row["maker"];
          $prefCatalog = $row["catalog"];
          $prefSpec = $row["spec"];
          $prefPrice = $row["price"];
          $prefVolume = $row["volume"];
    $tempHtml = "<input type=\"submit\" name=\"submit\" value=\" 更新 \">";
    $msg = "データを変更後、更新ボタンをクリックしてください。\n";
  }else{
    $tempHtml = "<a href=\"#\" onClick=\"history.back(); return false;\">前の画面へ戻る</a>\n";
    $msg = "データがありません。\n";
  }
  
  //結果保持用メモリを開放する
  mysql_free_result($result);
?>
  
<br>
     <form action="./list.php" method="post">
       <input type="submit" name="submit" value="戻る">
     </form>
  
    <h3>更新確認</h3>
    <?= $msg ?>
    <form action="update2.php" method="post">
             <input type="hidden" name="id" value="<?= $prefId ?>">
      <table>
        <tr><th>メーカ</th><th>品名</th><th>仕様・規格</th><th>単価</th><th>数量</th></tr>
        <tr>
            <td><input type="text" size="8" name="maker" value="<?= $prefMaker ?>" style="ime-mode: active;"></td>
            <td><input type="text" style="ime-mode: disabled;text-align:right" size="5" name="catalog" value="<?= $prefCatalog ?>"></td>
            <td><input type="text" style="ime-mode: disabled;text-align:right" size="10" name="spec" value="<?= $prefSpec ?>"></td>
            <td><input type="text" style="ime-mode: disabled;text-align:right" size="5" name="price" value="<?= $prefPrice ?>"></td>
            <td><input type="text" style="ime-mode: disabled;text-align:right" size="10" name="volume" value="<?= $prefVolume?>"></td>
        </tr>
      </table>
      <br />
        
      <?= $tempHtml ?>
    </form>
「update2.php」
 

<?php

 
$prefId = $_POST["id"];
$prefMaker = $_POST["maker"];
$prefCatalog = $_POST["catalog"];
$prefSpec = $_POST["spec"];
$prefPrice = $_POST["price"];
$prefVolume = $_POST["volume"];
 
//下記省略してるがPOSTされた変数を、「カラム=変数」にする

$sql = "UPDATE tools SET memo = '".$prefMemo."' , memo = '".$prefMemo."', memo = '".$prefMemo."', memo = '".$prefMemo."', memo = '".$prefMemo."'";

$sql .= "  WHERE tools.id = $prefId";

$resulta = executeQuery($sql);

echo "<form  name=\"formauto\" action=\"./list.php\" method=\"post\">";

echo "<SCRIPT language=\"JavaScript\">document.formauto.submit();</SCRIPT>";

echo "</form>";

//または、

?>

<form name="formauto" action="./list.php" method="post">

             <SCRIPT language="JavaScript">document.formauto.submit();</SCRIPT>

</form>