Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 快捷码中的编辑按钮重定向到数据库Wordpress中项目的页面_Php_Html_Wordpress - Fatal编程技术网

Php 快捷码中的编辑按钮重定向到数据库Wordpress中项目的页面

Php 快捷码中的编辑按钮重定向到数据库Wordpress中项目的页面,php,html,wordpress,Php,Html,Wordpress,我有一个快捷代码,在这个代码中,我显示了在另一个页面上提交的表单中的一些信息。问题是我如何“重定向”到传递我按下编辑按钮的项目id的同一表单?有人能给点建议吗 以下是短代码的代码: <?php global $wpdb; $table_name = $wpdb->prefix . 'property'; $properties = $wpdb->get_results("SELECT * FROM $table_name"); ?> <?php foreach (

我有一个快捷代码,在这个代码中,我显示了在另一个页面上提交的表单中的一些信息。问题是我如何“重定向”到传递我按下编辑按钮的项目id的同一表单?有人能给点建议吗

以下是短代码的代码:

<?php
global $wpdb;
$table_name = $wpdb->prefix . 'property';
$properties = $wpdb->get_results("SELECT * FROM $table_name");

?>
<?php foreach ($properties as $property) : ?>

    <div class="col-sm-4 my-4 card-selector">
        <div class="card bg-light text-dark card-height">
            <?php if ($property->sale_rent == 0) : ?>
                <div class="corner-ribbon top-left sticky red shadow">Sale</div>
            <?php elseif ($property->sale_rent == 1): ?>
                <div class="corner-ribbon top-left sticky red shadow">Rent</div>
            <?php endif; ?>
            <img class="img-responsive card-img-top" src="" alt="">
            <div class="card-body">
                <h2 class="card-title"><?php echo $property->country ?></h2>
                <h3 class="card-title"><?php echo $property->price ?> £</h3>
                <h5 class="card-title"><?php echo $property->county, $property->town ?></h5>
                <h6 class="card-title"><?php echo $property->displayable_address ?></h6>
                <i class="fas fa-bed"><?php echo $property->nr_of_bedrooms ?></i> <i
                        class="fas fa-bath"><?php echo $property->nr_of_bathrooms ?></i>
                <p id="description" class="description card-text"><?php echo $property->property_description ?></p>
                <?php if ($property->custom) : ?>
                    <a href="" class="card-link">Edit</a>
                    <a class="deleterow card-link"
                       href="">Delete</a>
                <?php endif; ?>
            </div>
        </div>
    </div>
<?php endforeach; ?>

特价
租
£

这是我提交的表格的一部分:

url: http://test.localhost/wordpress/add-property/
<h1>Add Property</h1>
<hr>
<div id="property-status"></div>
<form id="add-form" method="post" action="#" enctype="multipart/form-data">
    <div class="row">

        <div class="col-md-8">
            <form name="contact-form" action="" method="post" id="contact-form">
                <div class="form-group ">
                    <label>County*</label>
                    <input type="text" id="county" class="form-control" name="county" value="" required/>
                </div>
                <div class="form-group">
                    <label>Country*</label>
                    <input type="text" id="country" class="form-control" name="country" value="" required/>
                </div>
                <div class="form-group">
                    <label>Town</label>
                    <input type="text" id="town" class="form-control" name="town" required/>
                </div>
                <div class="form-group">
                    <label>Postcode</label>
                    <input type="number" id="postcode" class="form-control" name="postcode" value="" required/>
                </div>
                <div class="form-group">
                    <label>Description</label>
                    <textarea name="property_description" id="property_description" class="form-control"></textarea>
                </div>
url:http://test.localhost/wordpress/add-property/
添加属性

郡* 国家* 城镇 邮政编码 描述
您需要这样做

<?php
global $wpdb;
$table_name = $wpdb->prefix . 'property';
$properties = $wpdb->get_results("SELECT * FROM $table_name");

?>
<?php foreach ($properties as $property) : ?>

    <div class="col-sm-4 my-4 card-selector">
        <div class="card bg-light text-dark card-height">
            <?php if ($property->sale_rent == 0) : ?>
                <div class="corner-ribbon top-left sticky red shadow">Sale</div>
            <?php elseif ($property->sale_rent == 1): ?>
                <div class="corner-ribbon top-left sticky red shadow">Rent</div>
            <?php endif; ?>
            <img class="img-responsive card-img-top" src="" alt="">
            <div class="card-body">
                <h2 class="card-title"><?php echo $property->country ?></h2>
                <h3 class="card-title"><?php echo $property->price ?> £</h3>
                <h5 class="card-title"><?php echo $property->county, $property->town ?></h5>
                <h6 class="card-title"><?php echo $property->displayable_address ?></h6>
                <i class="fas fa-bed"><?php echo $property->nr_of_bedrooms ?></i> <i
                        class="fas fa-bath"><?php echo $property->nr_of_bathrooms ?></i>
                <p id="description" class="description card-text"><?php echo $property->property_description ?></p>
                <?php if ($property->custom) : ?>
                    <a href="<?php echo 'http://test.localhost/wordpress/add-property/?id='.$property->id;?> " class="card-link">Edit</a>
                    <a class="deleterow card-link"
                       href="">Delete</a>
                <?php endif; ?>
            </div>
        </div>
    </div>
<?php endforeach; ?>




<?php

global $wpdb;
$table_name = $wpdb->prefix . 'property';


if(isset($_GET['id'])){
    $properties = $wpdb->get_results("SELECT * FROM $table_name where id= $_GET['id']");

    print_r($properties);
}

?>

<h1>Add Property</h1>
<hr>
<div id="property-status"></div>
<form id="add-form" method="post" action="#" enctype="multipart/form-data">
    <div class="row">

        <div class="col-md-8">
            <form name="contact-form" action="" method="post" id="contact-form">
                <div class="form-group ">
                    <label>County*</label>
                    <input type="text" id="county" class="form-control" name="county" value="" required/>
                </div>
                <div class="form-group">
                    <label>Country*</label>
                    <input type="text" id="country" class="form-control" name="country" value="" required/>
                </div>
                <div class="form-group">
                    <label>Town</label>
                    <input type="text" id="town" class="form-control" name="town" required/>
                </div>
                <div class="form-group">
                    <label>Postcode</label>
                    <input type="number" id="postcode" class="form-control" name="postcode" value="" required/>
                </div>
                <div class="form-group">
                    <label>Description</label>
                    <textarea name="property_description" id="property_description" class="form-control"></textarea>
                </div>
            </form>
     </div>
</div>
<a href="<?php echo site_url().'/add-property/?id='.$property->id;?>" class="card-link">Edit</a>
<a class="deleterow card-link" href="">Delete</a>

特价
租
£


你需要这样做

<?php
global $wpdb;
$table_name = $wpdb->prefix . 'property';
$properties = $wpdb->get_results("SELECT * FROM $table_name");

?>
<?php foreach ($properties as $property) : ?>

    <div class="col-sm-4 my-4 card-selector">
        <div class="card bg-light text-dark card-height">
            <?php if ($property->sale_rent == 0) : ?>
                <div class="corner-ribbon top-left sticky red shadow">Sale</div>
            <?php elseif ($property->sale_rent == 1): ?>
                <div class="corner-ribbon top-left sticky red shadow">Rent</div>
            <?php endif; ?>
            <img class="img-responsive card-img-top" src="" alt="">
            <div class="card-body">
                <h2 class="card-title"><?php echo $property->country ?></h2>
                <h3 class="card-title"><?php echo $property->price ?> £</h3>
                <h5 class="card-title"><?php echo $property->county, $property->town ?></h5>
                <h6 class="card-title"><?php echo $property->displayable_address ?></h6>
                <i class="fas fa-bed"><?php echo $property->nr_of_bedrooms ?></i> <i
                        class="fas fa-bath"><?php echo $property->nr_of_bathrooms ?></i>
                <p id="description" class="description card-text"><?php echo $property->property_description ?></p>
                <?php if ($property->custom) : ?>
                    <a href="<?php echo 'http://test.localhost/wordpress/add-property/?id='.$property->id;?> " class="card-link">Edit</a>
                    <a class="deleterow card-link"
                       href="">Delete</a>
                <?php endif; ?>
            </div>
        </div>
    </div>
<?php endforeach; ?>




<?php

global $wpdb;
$table_name = $wpdb->prefix . 'property';


if(isset($_GET['id'])){
    $properties = $wpdb->get_results("SELECT * FROM $table_name where id= $_GET['id']");

    print_r($properties);
}

?>

<h1>Add Property</h1>
<hr>
<div id="property-status"></div>
<form id="add-form" method="post" action="#" enctype="multipart/form-data">
    <div class="row">

        <div class="col-md-8">
            <form name="contact-form" action="" method="post" id="contact-form">
                <div class="form-group ">
                    <label>County*</label>
                    <input type="text" id="county" class="form-control" name="county" value="" required/>
                </div>
                <div class="form-group">
                    <label>Country*</label>
                    <input type="text" id="country" class="form-control" name="country" value="" required/>
                </div>
                <div class="form-group">
                    <label>Town</label>
                    <input type="text" id="town" class="form-control" name="town" required/>
                </div>
                <div class="form-group">
                    <label>Postcode</label>
                    <input type="number" id="postcode" class="form-control" name="postcode" value="" required/>
                </div>
                <div class="form-group">
                    <label>Description</label>
                    <textarea name="property_description" id="property_description" class="form-control"></textarea>
                </div>
            </form>
     </div>
</div>
<a href="<?php echo site_url().'/add-property/?id='.$property->id;?>" class="card-link">Edit</a>
<a class="deleterow card-link" href="">Delete</a>

特价
租
£


如果要使“添加”和“编辑”页面相同,则需要在“添加”页面中添加更多代码

首先,做出这样的改变

<?php
global $wpdb;
$table_name = $wpdb->prefix . 'property';
$properties = $wpdb->get_results("SELECT * FROM $table_name");

?>
<?php foreach ($properties as $property) : ?>

    <div class="col-sm-4 my-4 card-selector">
        <div class="card bg-light text-dark card-height">
            <?php if ($property->sale_rent == 0) : ?>
                <div class="corner-ribbon top-left sticky red shadow">Sale</div>
            <?php elseif ($property->sale_rent == 1): ?>
                <div class="corner-ribbon top-left sticky red shadow">Rent</div>
            <?php endif; ?>
            <img class="img-responsive card-img-top" src="" alt="">
            <div class="card-body">
                <h2 class="card-title"><?php echo $property->country ?></h2>
                <h3 class="card-title"><?php echo $property->price ?> £</h3>
                <h5 class="card-title"><?php echo $property->county, $property->town ?></h5>
                <h6 class="card-title"><?php echo $property->displayable_address ?></h6>
                <i class="fas fa-bed"><?php echo $property->nr_of_bedrooms ?></i> <i
                        class="fas fa-bath"><?php echo $property->nr_of_bathrooms ?></i>
                <p id="description" class="description card-text"><?php echo $property->property_description ?></p>
                <?php if ($property->custom) : ?>
                    <a href="<?php echo 'http://test.localhost/wordpress/add-property/?id='.$property->id;?> " class="card-link">Edit</a>
                    <a class="deleterow card-link"
                       href="">Delete</a>
                <?php endif; ?>
            </div>
        </div>
    </div>
<?php endforeach; ?>




<?php

global $wpdb;
$table_name = $wpdb->prefix . 'property';


if(isset($_GET['id'])){
    $properties = $wpdb->get_results("SELECT * FROM $table_name where id= $_GET['id']");

    print_r($properties);
}

?>

<h1>Add Property</h1>
<hr>
<div id="property-status"></div>
<form id="add-form" method="post" action="#" enctype="multipart/form-data">
    <div class="row">

        <div class="col-md-8">
            <form name="contact-form" action="" method="post" id="contact-form">
                <div class="form-group ">
                    <label>County*</label>
                    <input type="text" id="county" class="form-control" name="county" value="" required/>
                </div>
                <div class="form-group">
                    <label>Country*</label>
                    <input type="text" id="country" class="form-control" name="country" value="" required/>
                </div>
                <div class="form-group">
                    <label>Town</label>
                    <input type="text" id="town" class="form-control" name="town" required/>
                </div>
                <div class="form-group">
                    <label>Postcode</label>
                    <input type="number" id="postcode" class="form-control" name="postcode" value="" required/>
                </div>
                <div class="form-group">
                    <label>Description</label>
                    <textarea name="property_description" id="property_description" class="form-control"></textarea>
                </div>
            </form>
     </div>
</div>
<a href="<?php echo site_url().'/add-property/?id='.$property->id;?>" class="card-link">Edit</a>
<a class="deleterow card-link" href="">Delete</a>

希望这有帮助

如果要使添加和编辑页面相同,则需要在添加页面中添加更多代码

首先,做出这样的改变

<?php
global $wpdb;
$table_name = $wpdb->prefix . 'property';
$properties = $wpdb->get_results("SELECT * FROM $table_name");

?>
<?php foreach ($properties as $property) : ?>

    <div class="col-sm-4 my-4 card-selector">
        <div class="card bg-light text-dark card-height">
            <?php if ($property->sale_rent == 0) : ?>
                <div class="corner-ribbon top-left sticky red shadow">Sale</div>
            <?php elseif ($property->sale_rent == 1): ?>
                <div class="corner-ribbon top-left sticky red shadow">Rent</div>
            <?php endif; ?>
            <img class="img-responsive card-img-top" src="" alt="">
            <div class="card-body">
                <h2 class="card-title"><?php echo $property->country ?></h2>
                <h3 class="card-title"><?php echo $property->price ?> £</h3>
                <h5 class="card-title"><?php echo $property->county, $property->town ?></h5>
                <h6 class="card-title"><?php echo $property->displayable_address ?></h6>
                <i class="fas fa-bed"><?php echo $property->nr_of_bedrooms ?></i> <i
                        class="fas fa-bath"><?php echo $property->nr_of_bathrooms ?></i>
                <p id="description" class="description card-text"><?php echo $property->property_description ?></p>
                <?php if ($property->custom) : ?>
                    <a href="<?php echo 'http://test.localhost/wordpress/add-property/?id='.$property->id;?> " class="card-link">Edit</a>
                    <a class="deleterow card-link"
                       href="">Delete</a>
                <?php endif; ?>
            </div>
        </div>
    </div>
<?php endforeach; ?>




<?php

global $wpdb;
$table_name = $wpdb->prefix . 'property';


if(isset($_GET['id'])){
    $properties = $wpdb->get_results("SELECT * FROM $table_name where id= $_GET['id']");

    print_r($properties);
}

?>

<h1>Add Property</h1>
<hr>
<div id="property-status"></div>
<form id="add-form" method="post" action="#" enctype="multipart/form-data">
    <div class="row">

        <div class="col-md-8">
            <form name="contact-form" action="" method="post" id="contact-form">
                <div class="form-group ">
                    <label>County*</label>
                    <input type="text" id="county" class="form-control" name="county" value="" required/>
                </div>
                <div class="form-group">
                    <label>Country*</label>
                    <input type="text" id="country" class="form-control" name="country" value="" required/>
                </div>
                <div class="form-group">
                    <label>Town</label>
                    <input type="text" id="town" class="form-control" name="town" required/>
                </div>
                <div class="form-group">
                    <label>Postcode</label>
                    <input type="number" id="postcode" class="form-control" name="postcode" value="" required/>
                </div>
                <div class="form-group">
                    <label>Description</label>
                    <textarea name="property_description" id="property_description" class="form-control"></textarea>
                </div>
            </form>
     </div>
</div>
<a href="<?php echo site_url().'/add-property/?id='.$property->id;?>" class="card-link">Edit</a>
<a class="deleterow card-link" href="">Delete</a>

希望这有帮助

您能指出哪个变量包含id以及您需要如何将其作为$\u GET参数传递吗?@IvnH我在问如何制作相同的表单,当我单击“编辑”时也是编辑表单,我知道值中应该包含什么。我不知道url是如何复合的。在php中是…?id=1。因此,我关心的是如何重定向到带有id的url的页面。能否指出包含id的变量以及需要如何将其作为$_GET参数传递?@IvnH我在问如何制作相同的表单,当我单击“编辑”时也是编辑表单,我知道值中应该包含什么。我不知道url是如何复合的。在php中是…?id=1。所以我关心的是如何重定向到带有id的url的页面。