-3

I have a problem

I try to display the data from database in TABLE (HTML), and then the data that I have displayed must be save in another table with the same content

Display Data

    <?php
     include('ApprovalDB.php');
$result = mysql_query("SELECT pr_id, prcode, type, client, requestdate, status FROM t_purchaserequest where status = 'Approved' and type = 'Sample Only'")
or die(mysql_error());

echo "<table class = 'tbl1' cellpadding='10'>";
echo "<thead><td>PRCODE</td><td>TYPE</td> <td>CLIENT</td> <td>REQUESTED DATE</td> <td>STATUS</td><td>ACTION</td></thead>";

while($row = mysql_fetch_array( $result )) {
echo "<tr>";

echo '<td>' . $row['prcode'] . '</td>';
echo '<td>' . $row['type'] . '</td>';
echo '<td>' . $row['client'] . '</td>';
echo '<td>' . $row['requestdate'] . '</td>';
echo '<td>' . $row['status'] . '</td>';

echo '<td><a href="returnDB.php?id=' . $row['pr_id'] . '" class = "link1">Return Item</a></td>';
echo "</tr>";

}
echo "</table>";
echo "<a href =  'javascript:window.history.go(-1);' class = 'img_arrow'><img src = 'back_arrow.png'></a>";
?>

this link return item, the function must be save the item display in the table.. since I was a newbie.. I don't how I should start here...

thank you for your response to my problem

Jhesie
  • 25
  • 1
  • 7
  • 1
    when you click the link you want to insert? – lalithkumar May 17 '17 at 12:55
  • That link doesn't send any data other than the row ID. So in returnDB.php, you would need to lookup the data from the original table and the insert into the other table. – Sloan Thrasher May 17 '17 at 12:56
  • @lalithkumar yes, base on the selected id it will be inserted on another table – Jhesie May 17 '17 at 12:56
  • You could also use the _INSERT ... SELECT_ form of the insert statement. – Sloan Thrasher May 17 '17 at 12:57
  • *"then the data that I have displayed must be save in another table with the same content"* - Where's your INSERT? the one that you tried. – Funk Forty Niner May 17 '17 at 12:57
  • @SloanThrasher sorry if i cannot understand it... if you mind to give an example... – Jhesie May 17 '17 at 12:57
  • you can send primary key to returnDB.php, there you could do select and insert – lalithkumar May 17 '17 at 12:58
  • i haven't start the insert statement... because I don't know where to start.. @Fred-ii- – Jhesie May 17 '17 at 12:59
  • add your returnDB.php @Jhesie – lalithkumar May 17 '17 at 12:59
  • well, you're going to have to post your db schemas for everything, because nobody knows what those are and answers given may not solve it. Edit: to which one was given just now and was downvoted for it, which is not mine. – Funk Forty Niner May 17 '17 at 13:01
  • thanks for the suggestion.... @Fred-ii- – Jhesie May 17 '17 at 13:03
  • @Jhesie: SO isn't a code writing service. If you haven't written anything in returnDB.php yet, you'll need to do some more research and at least make an attempt to write the code. Review the help section for how to ask a question, and what types of questions are appropriate on SO. – Sloan Thrasher May 17 '17 at 13:12
  • ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 17 '17 at 13:17

1 Answers1

1

First of all shouldn't store the details again in HTML format because that you can create anytime.

If you want to do so you can create one variable and store the rendering HTML in that variable, you can print the same variable and keep that variable in hidden field.

Submit the form with post request because may be the hidden size of hidden field value be more.

If the size of the hidden field is more then just send primary key of the record to the server side get the detail again from the DB create the same HTML and store it back to another table.

Below is the code to store the HTML in the variable and display it. you can create form and submit the values as I mentioned above.

<?php

include('ApprovalDB.php');
$result = mysql_query("SELECT pr_id, prcode, type, client, requestdate, status FROM t_purchaserequest where status = 'Approved' and type = 'Sample Only'")
or die(mysql_error());
$str = "";
$str .= "<table class = 'tbl1' cellpadding='10'>";
$str .= "<thead><td>PRCODE</td><td>TYPE</td> <td>CLIENT</td> <td>REQUESTED DATE</td> <td>STATUS</td><td>ACTION</td></thead>";

while ($row = mysql_fetch_array($result)) {
    $str .= "<tr>";

    $str .= '<td>' . $row['prcode'] . '</td>';
    $str .= '<td>' . $row['type'] . '</td>';
    $str .= '<td>' . $row['client'] . '</td>';
    $str .= '<td>' . $row['requestdate'] . '</td>';
    $str .= '<td>' . $row['status'] . '</td>';
    $str .= "</tr>";

}
$str . "</table>";


//display the data 

echo $str;

//to save the data ideally you should not save in this format but still you want to do you can do in two way

//1. most appropriate way you can get the product details in server side, create same string like i have created above and save it to db 

//2.create hidden field and save the data with post form 
echo "<input type='hidden' name='my-data' value='".$str."' >";


echo "<a href =  'javascript:window.history.go(-1);' class = 'img_arrow'><img src = 'back_arrow.png'></a>";
?>
Gyaneshwar Pardhi
  • 471
  • 1
  • 4
  • 15
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Jay Blanchard May 17 '17 at 13:06
  • Please add an explaination to your answer @gyaan – Sloan Thrasher May 17 '17 at 13:08
  • 1.I don't know why you want to save the data in html formate you can create that data any time while rendering itself. – Gyaneshwar Pardhi May 17 '17 at 13:11
  • if you will submit data using the hidden field that's not a good way because the size of the field value may be huge, you can just send the product id to server side and then you can create the same string which will send fewer data to the server and will be fast. I hope this will explain my points. I have explained the code in the comment itself and can anyone tell me why downvote? – Gyaneshwar Pardhi May 17 '17 at 13:19
  • @SloanThrasher what needs to explain there? – Gyaneshwar Pardhi May 17 '17 at 13:24
  • How does it answer the OP's question? What specifically did you change from the OP's question's code? Just posting some code without explaining these things isn't the way SO works. – Sloan Thrasher May 17 '17 at 13:31
  • @SloanThrasher as I saw the question he wants to print the data and save to back in with HTML tags. so I have created one string which can be used for both the purpose. I have commented in the code itself when I am printing the values and how can he save it back to the database with HTML tag. I don't think I need to explain the code in words. – Gyaneshwar Pardhi May 17 '17 at 13:37
  • 1
    @gyaan, Review the help section on answers, it suggests that you do need to provide an explanation "in words". Basically, you shouldn't expect a reader (OP or people in the future) to have to run a diff on the code to spot the difference. Not trying to be mean, just offering friendly advice. – Sloan Thrasher May 17 '17 at 13:44
  • @SloanThrasher thanks for the advice will keep in mind. – Gyaneshwar Pardhi May 17 '17 at 13:47
  • Don't just keep it mind @gyaan, edit your existing posts. – Jay Blanchard May 17 '17 at 21:11
  • @SloanThrasher and Jay Blanchard updated the answer thanks for the guiding me how to write the proper answer in StackOverflow. – Gyaneshwar Pardhi May 18 '17 at 07:05