To prevent the form from disappearing

Asked 1 years ago, Updated 1 years ago, 37 views

Nice to meet you.
I started studying PHP three months ago and am currently trying to create a rudimentary web app with PHP+MySQL.First of all, I started to make a simple purchase order, but I failed to fill in the form, so I am looking it up online, but I would appreciate it if you could let me know.

As for the input items,

  • Date
  • Order to

    • Company name

    • Branch name

  • Order Items

    • Divisions

    • Medium classification

    • Subdivision

    • Unit price

    • quantity

    • Total


  • Company name

  • Branch name


  • Divisions

  • Medium classification

  • Subdivision

  • Unit price

  • quantity

  • Total

It says.
I have tried and tried various things by preparing the selection button for each date, order destination, and order item, but the item I entered disappears because there are several execution buttons.In other words, if you press the Confirm Date button and then click the Confirm Order Address button, the date you entered disappears. I've tried $_COOKIE, but it doesn't work very well.I would appreciate it if you could let me know if anyone has built such a sales management tool in PHP.The specifications I am aiming for are as follows.Thank you for your cooperation.

★What you want to do:
①Select Order Date
② Extract items from DB by putting the item code in the INPUT column called dcode
③ Create a purchase order with all the data in it

★What's troubling you:
Even if you enter the date, it disappears when you press the set_item button

function show_item($counter)
{

//PDO Information
$dbhost_name = "localhost";  
$database="xxx";      
$username="yyy";           
$password="zzz"; 
$pdo=new PDO('mysql:host='.$dbhost_name.'; dbname='.$database,$username,$password,array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));



// acquisition of item information
$filter_item="";
$var1 = "set_item".$counter;
$var2 = "dcode".$counter;

if(isset($_POST[$var1]))
    {
    $filter_item=$_POST[$var2];
    $sql_item="SELECT type_name, prod_name, item_name FROM mst_item WHERE dcode='{$filter_item}'";

    // PDO data acquisition
    foreach($pdo->query($sql_item)as$lst_item) 
        {
        ${"type".$counter} = $lst_item['type_name'];
        ${"prod".$counter} = $lst_item['prod_name'];
        ${"item".$counter} = $lst_item['item_name'];
       }
    }


// Displaying the Item Selection Table
echo'<tr>'."\n";
echo'<td><input type="text" name="dcode'.$counter.''>/td>'\n";
echo'<td><input type="submit" name="set_item'.$counter.'"value="select"></td>'."\n";
echo'<td style="width:100px;"><input type="text" name="type_name" value="'.${"type".$counter}.'">/td>'\n";
echo'<td style="width:100px;"><input type="text" name="prod_name" value="'.${"prod".$counter}.'">/td>'\n";
echo'<td style="width:100px;"><input type="text" name="item_name" value="'.${"item".$counter}.'">/td>'."\n";
echo'<td><input type="text" name="place'.$counter.'" id="div_item"></td>'."\n";
echo'<td><input type="text" name="quant'.$counter.""id="div_item"></td>'."\n";
echo'<td>'."\n";
echo'<select name="base'.$counter.""id="div_item">'."\n";
echo'<option value="pcs">pcs</option>'\n";
echo'<option value="box">box</option>'\n";
echo'<option value="kg">kg</option>'\n";
echo'<option value="g">g</option>'."\n";
echo'</select>'."\n";
echo'</td>'."\n";
echo'<td><input type="text" name="unit'.$counter.'" id="div_item"></td>'."\n";
echo'<td><input type="text" name="sum'.$counter.""id="div_item"></td>'."\n";
echo'</tr>'."\n";
echo "\n";

}

javascript php html

2022-09-30 19:10

2 Answers

I don't know if it matches the situation, but I wrote a very simple php using <input type="date">, so please refer to it.
Save the file as utf-8 or change the meta charset characterization to match your environment.

<?php
$ex3val=";
if(isset($_POST["example3"])){
  // adopt a value if it has been sent
  $ex3val=htmlspecialchars($_POST["example3"]);
}
?><html lang="ja">
<metacharset="UTF-8">
<body>
<form method="post">
  <div>
    <!--no ingenuity-->
    Always disappear: <input type="date" name="example1">
  </div>
  <div>
    <!--Initial value available-->
    Always February 16, 2012:<input type="date" name="example2" value="2012-02-16">
  </div>
  <div>
    <!--Initial value set in php-->
    Remains after button: <input type="date" name="example3" value="<?phpecho$ex3val;?>">br/>
  <input type="submit" value="submit">
  </div>
</form>
</body>
</html>


2022-09-30 19:10

There seems to be a misunderstanding about the web system.

When the browser submits, it waits for a reply from the server, but if the content is HTML or text, it tries to update the screen with the content (all previous screens will disappear).
Therefore, if you want to have the date put in the previous action and display it on the next screen, you need to create an HTML containing the date information and pass it to the browser.
In this case, when you have the item code put on the next screen and send it back, you still need to send the date from your browser.Even if there is no change, the server cannot create HTML without a browser sending it because it does not remember the previous date.(There is a way to save it elsewhere, but I omit it because it doesn't seem appropriate to use in this example and it will be confusing to write.)
I don't want to change it, but if there is any data you would like me to send, I will attach the attribute type="hidden" to the input tag and fill it up in HTML so that you can send it as the next submit.
If you create HTML by enclosing all of these things in form tags, it will be the intended behavior.

Today, however, such a system is not built very often, and programming that updates only a part of the screen using a function called Ajax is the mainstream.
Also, there is a process in the example program that generates SQL from $_POST, but it is very dangerous for security and should be stopped.
Overall, I think it's faster to ask someone to teach you than to teach yourself.


2022-09-30 19:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.