编辑页面无法识别$ _GET值

时间:2017-01-29 13:51:09

标签: php get crud

我有一个简单的CRUD,一切都已经工作,除了更新,我似乎无法将$ _GET值从我的href传递到我的update.php页面。知道我做错了什么?

更新并删除href&#39>

<td><a href="update.php?updateid=<?php echo $row['stud_id'];?>">Edit</a></td>
<td><a href="index.php?deleteid=<?php echo $row['stud_id'];?>">Delete</a></td>

update.php

<?php
    include 'db.php';


    if(isset($_GET['updateid'])){
        $id = $_GET['updateid'];
    }

    $select = "SELECT * FROM student WHERE stud_id='".$id."'";
    $user = selectStud($select);

    if(isset($_POST['up-submit'])){
        $upfname = $_POST['up-fname'];
        $upmname = $_POST['up-mname'];
        $uplname = $_POST['up-lname'];
        $upcourse = $_POST['up-course'];

        $query = "UPDATE student SET stud_fname='".$upfname."',stud_mname='".$upmname.
        "',stud_lname='".$uplname."',stud_course='".$upcourse."' WHERE stud_id='".$id."'";

        $update = updateStud($query);

        if($update){
            echo "<script>alert('Update Success!'); window.location('index.php');</script>";
        }else{
            echo "<script>alert('Update Failed :('); window.location('index.php');</script>";
        }
    }


?>

<form method="POST" action="update.php">
    <input type="text" name="up-fname" placeholder="First Name" autocomplete="off"><br />
    <input type="text" name="up-mname" placeholder="Middle Name" autocomplete="off"><br />
    <input type="text" name="up-lname" placeholder="Last Name" autocomplete="off"><br />
    <label for="course">Course: </label>
    <select name="up-course">
        <option name="up-course" value="BSIT">BSIT</option>
        <option name="up-course" value="BSHM">BSHM</option>
        <option name="up-course" value="BSED">BSED</option>
        <option name="up-course" value="BSMT">BSMT</option>
    </select><br />

    <input type="submit" name="up-submit" value="Save Changes">
</form>

db.php中

<?php 

    function getConnection(){

        $conn = new PDO("mysql:host=localhost;dbname=preskilltest","root", "");
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return $conn;
    }   

    function selectStud($query){
            $pdo = getConnection();

            $stmt = $pdo->query($query);
            return $stmt->fetchAll();
    }

    function insertStud($query){
        $pdo = getConnection();

        $stmt = $pdo->query($query);
        return $stmt;

    }

    function updateStud($query){
        $pdo = getConnection();

        $stmt = $pdo->prepare($query);
        return $stmt->execute();
    }


?>

1 个答案:

答案 0 :(得分:0)

由于您在发送POST请求(表单)时无法访问GET参数(URL),因此需要在表单中嵌入GET参数。

所以在表单中添加以下内容:

  Sub CommandButton1_Click()

  Dim strF As String, strP As String, text As String, textline As String, tFlux As Integer
  strP = "C:\test" 'change for the path of your folder

  strF = Dir(strP & "\*.txt") 'Change as required

  Do While strF <> vbNullString

  Open strF For Input As #1
  Do Until EOF(1)

    Line Input #1, textline
    text = text & textline
    tFlux = InStr(text, "tflux")
    Range("B2").Value = Mid(text, tFlux + 9, 3) <----- this is the line where I need help, Now the last found value is copied into cell B2, but I want excel to move to B3 after filling B2, move to B4 after filling B3, etc....

Loop
Close #1
text = ""
strF = Dir()
Loop

End Sub

在服务器端代码中包含以下内容:

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CTEquiposMantenciones extends Migration
{
    public function up()
    {
        Schema::create('equipos_mantenciones', function (Blueprint $table) {
            $table->increments('id')->unique();
            $table->integer('equipos_id');
            $table->integer('matenciones_id');
        });
    }   
    public function down()
    {
        Schema::dropIfExists('equipos_mantenciones');
    }
}