如果x输入数据,则检索数据。 PHP& SQL [英] If x enter data, else retrieve data. PHP & SQL

查看:132
本文介绍了如果x输入数据,则检索数据。 PHP& SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我一直试图找到一种方法来做到这一点。



代码的关键是做到这一点:

检查数据库,看看字段是否填充,if不张贴表格。填好表格后,将数据提交到数据库,然后重新加载页面以转到步骤2.



否则,如果字段已满,则显示数据库中的数据,并绕过第一部分。

 <?php 
require_once('connectvars.php');
?>

<!DOCTYPE html

PUBLIC - // W3C // DTD XHTML 1.0 Strict // EN
http://www.w3。组织/ TR / XHTML1 / DTD / XHTML1-strict.dtd>

< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< title> PDI不合格材料报告< / title>
< link rel =stylesheettype =text / csshref =CSS / view.css/>
< / head>
< body>
< / body>
< / html>
<?php

echo'< form id =all>';
echo'< fieldset>';
echo'< div id =box4-1>';
//我们知道$ ncmrsr和$ ncmrsc都是空白的
$ row ['ncmrsr'] = trim($ row ['ncmrsr']);
$ row ['ncmrsc'] = trim($ row ['ncmrsc']);
if(empty($ row ['ncmrsr'])&&& empty($ row ['ncmrsc'])){
//添加注释的代码会在这里。
echo'< div id =ncmrsr>< span class =b> NCMR供应商回应:< / span>< textarea name =ncmrsrrows =6cols =85>N / A< / textarea>< / div>< br />';
echo'< br />';
echo'< div id =ncmrsc>< span class =b> NCMR供应商评论:< / span>< / span>< textarea name =ncmrsrrows =6cols =85>< / textarea>< / div>< br />';



$ b $ else {
// echo两个字段
if(!empty($ row ['ncmrsr']) ){
echo'< div id =ncmrsr>< span class =b> NCMR供应商回应:< / span>< / span>'。 $ row ['ncmrsr']。 '< / div>';}
if(!empty($ row ['ncmrsc'])){
echo'< div id =ncmrsc>< span class =& b> NCMR供应商评论:< br />< / span>'。 $ row ['ncmrsc']。 '< / div>';}
echo'< / div>';
echo'< / div>';
echo'< / fieldset>';
echo'< / form>';

}
?>


解决方案

回显任何动态字段。其次,无论数据如何,您总是可以生成表单。第三,回显没有包含表格的< tr> < td> 标签。第四,如果$ row变量中没有数据,则只能结束form和div标记。所以有很多这样的错误。

 <?php 
require_once('connectvars.php') ;
?>

<!DOCTYPE html

PUBLIC - // W3C // DTD XHTML 1.0 Strict // EN
http://www.w3。组织/ TR / XHTML1 / DTD / XHTML1-strict.dtd>

< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< title> PDI不合格材料报告< / title>
< link rel =stylesheettype =text / csshref =CSS / view.css/>
< / head>
< body>
<?php



//我们知道$ ncmrsr和$ ncmrsc都是空白的
$ row ['ncmrsr'] = trim $行[ 'ncmrsr']);
$ row ['ncmrsc'] = trim($ row ['ncmrsc']);
if(empty($ row ['ncmrsr'])&&& empty($ row ['ncmrsc'])){
//添加注释的代码会在这里。
echo'< form id =allmethod =postaction =pagetosaveformtoDB.php>';
echo'< fieldset>';
echo'< div id =box4-1>';
echo'< div id =ncmrsr>< span class =b> NCMR供应商回应:< / span>< textarea name =ncmrsrrows =6cols =85>N / A< / textarea>< / div>< br />';
echo'< div id =ncmrsc>< span class =b> NCMR供应商评论:< / span>< / span>< textarea name =ncmrsrrows =6cols =85>< / textarea>< / div>< br />
< input name =submittype =submitvalue =submit/>';
echo'< / div>< / fieldset>< / form>';
}

else {
// echo the two fields
echo'< div id =box4-1>';
if(!empty($ row ['ncmrsr'])){
echo'< div id =ncmrsr>< span class =b> NCMR供应商回应:< ; br />< / span>'。 $ row ['ncmrsr']。 '< / div>';}
if(!empty($ row ['ncmrsc'])){
echo'< div id =ncmrsc>< span class =& b> NCMR供应商评论:< br />< / span>'。 $ row ['ncmrsc']。 '< / div>';}
echo'< / div>';

}
?>
< / body>
< / html>

另外我不确定connectvars在做什么,以及$ row变量是从哪里来的如果不能解决这个问题,我会去更多的信息。


Here is my code, I have been attempting to find a way to do this.

The point of the code is to do this:

Check database, see if field is filled, if not post form. Once form is filled, submit data to database, then reload page to go to step 2.

Else if field is full show data in database, and bypass the first part.

    <?php
  require_once('connectvars.php');
?>

<!DOCTYPE html 

     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PDI Non-Conforming Materials Report</title>
<link rel="stylesheet" type="text/css" href="CSS/view.css" />
</head>
<body>
</body> 
</html>
<?php

echo '<form id="all">';
echo '<fieldset>';
echo '<div id="box4-1">';
// We know both $ncmrsr AND $ncmrsc are blank
$row['ncmrsr'] = trim($row['ncmrsr']);
$row['ncmrsc'] = trim($row['ncmrsc']);
if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) {
     // code to add comment would go here.
        echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response:<br /></span><textarea name="ncmrsr" rows="6" cols="85">"N/A"</textarea></div><br />';
        echo '<br />';
        echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />';
        }



else {
// echo the two fields
                if (!empty($row['ncmrsr'])) {
                    echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response:<br /></span>' . $row['ncmrsr'] . '</div>';}
                if (!empty($row['ncmrsc'])) {
                    echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment:<br /></span>' . $row['ncmrsc'] . '</div>';}
                    echo '</div>';
echo '</div>';
echo '</fieldset>';
echo '</form>';

}
?>

解决方案

so first of all you end your html tag before you echo any dynamic fields. Second you always generate the form no matter what the data says. Third you echo <tr> and <td> tags without a containing table. Fourth you only end the form and div tags if there is no data in the $row variable. So there is a lot going on thats wrong.

<?php
  require_once('connectvars.php');
?>

<!DOCTYPE html 

     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PDI Non-Conforming Materials Report</title>
<link rel="stylesheet" type="text/css" href="CSS/view.css" />
</head>
<body>
<?php



// We know both $ncmrsr AND $ncmrsc are blank
$row['ncmrsr'] = trim($row['ncmrsr']);
$row['ncmrsc'] = trim($row['ncmrsc']);
if (empty($row['ncmrsr']) && empty($row['ncmrsc'])) {
     // code to add comment would go here.
        echo '<form id="all" method="post" action="pagetosaveformtoDB.php">';
        echo '<fieldset>';
        echo '<div id="box4-1">';
        echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response:<br /></span><textarea name="ncmrsr" rows="6" cols="85">"N/A"</textarea></div><br />';
        echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment:<br /></span><textarea name="ncmrsr" rows="6" cols="85" ></textarea></div><br />
        <input name="submit" type="submit" value="submit" />';
        echo '</div></fieldset></form>';
        }

else {
// echo the two fields
       echo '<div id="box4-1">';
       if (!empty($row['ncmrsr'])) {
          echo '<div id="ncmrsr"><span class="b">NCMR Supplier Response:<br /></span>' . $row['ncmrsr'] . '</div>';}
       if (!empty($row['ncmrsc'])) {
          echo '<div id="ncmrsc"><span class="b">NCMR Supplier Comment:<br /></span>' . $row['ncmrsc'] . '</div>';}
           echo '</div>';

}
?>
</body> 
</html>

Also I am not sure what connectvars is doing and if thats where the $row variable is coming from so I would def more information if that doesnt fix it.

这篇关于如果x输入数据,则检索数据。 PHP&amp; SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆