Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:41:32+00:00 2026-05-31T08:41:32+00:00

What i am trying to do is recover data from a table and add

  • 0

What i am trying to do is recover data from a table and add them dynamicly to a table for the user to edit. The thing is tha i can’t find the way when the user clicks Προσθηκη to add a new empty field with the function addRow.

<?php 

    session_start();

    if (!isset($_SESSION['manager'])) {

        header("location: admin_login.php");
        exit();

    }

    $managerID= preg_replace('#[^0-9]#i','', $_SESSION["id"]);
    $manager= preg_replace('#[^A-Za-z0-9]#i','', $_SESSION["manager"]);
    $password= preg_replace('#[^A-Za-z0-9]#i','', $_SESSION["password"]);

    include "../storescripts/connect_to_mysql.php";
    $sql=mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1");

    $existCount=mysql_num_rows($sql);
    if($existCount==0){

        echo "Your Log In session data is not on record in the database";
        exit(); 
    }

?>

<?php
    // Script Error Reporting
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
?>

<?php 
    // Parse the form data and add inventory item to the system
    if (isset($_POST['product_name'])) {

        $pid = mysql_real_escape_string($_POST['thisID']);
        $product_name = mysql_real_escape_string($_POST['product_name']);
        $price = mysql_real_escape_string($_POST['price']);
        $category = mysql_real_escape_string($_POST['category']);
        $subcategory = mysql_real_escape_string($_POST['subcategory']);
        $details = mysql_real_escape_string($_POST['details']);
        // See if that product name is an identical match to another product in the system
    $sql = mysql_query("UPDATE products SET product_name='$product_name', price='$price', details='$details', category='$category', subcategory='$subcategory' WHERE id='$pid'");

        if($_FILES['my_photo']['tmp_name'] != ""){
            // Place image in the folder 
            $newname = "$pid.jpg";
            move_uploaded_file( $_FILES['my_photo']['tmp_name'], "../inventory_images/$newname");
        }
        header("location: inventory_list.php"); 
        exit();

    }


?>

<?php 
    //Edit Product Block
    if (isset($_GET['pid'])) {  

        $targetID=$_GET['pid'];
        $sql=mysql_query("SELECT * FROM products WHERE id='$targetID' LIMIT 1");
        $product_count=mysql_num_rows($sql);

        if($product_count > 0){

            while($row = mysql_fetch_array($sql)){

                $product_name=$row["product_name"];
                //Condition
                $condition_t=$row["active"];
                if($condition_t == 1){
                    $condition="<tr>
                                    <td>Κατάσταση</td>
                                    <td>
                                        <label>
                                            <input type='radio' name='condition' value='1' checked='checked'> Ενεργό</input>
                                            <input type='radio' name='condition' value='0'> Ανενεργό</input>
                                        </label>
                                    </td>
                                </tr>";
                }else if($condition_t == 0){
                    $condition="<tr>
                                    <td>Κατάσταση</td>
                                    <td>
                                        <label>
                                            <input type='radio' name='condition' value='1'> Ενεργό</input>
                                            <input type='radio' name='condition' value='0' checked='checked'> Ανενεργό</input>
                                        </label>
                                    </td>
                                </tr>";
                }
                $price=$row["price"];
                //Supplier
                $supplier=$row["supplier"];
                $sql_2=mysql_query("SELECT id,name FROM suppliers ORDER BY id");
                $suppliers_list = "<select name='supplier_choice'>
                <option value='0'>-------</option>";
                while($row_2 = mysql_fetch_array($sql_2)){
                    $suppliers_id=$row_2["id"];
                    $suppliers_name=$row_2["name"];
                    if($suppliers_id == $supplier){
                        $suppliers_list .= "<option value='$suppliers_id' selected='selected'>$suppliers_name</option>";
                    }else{
                        $suppliers_list .= "<option value='$suppliers_id'>$suppliers_name</option>";
                    }
                }
                $suppliers_list .="</select>";
                //Category
                $category=$row["category"];
                $category_list = "<select name='category_choice'><option value='0'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-----------</option>";
                $sql_3=mysql_query("SELECT id,category_name FROM category WHERE tier='1'");
                while($row_p = mysql_fetch_array($sql_3)){
                    $id_p=$row_p["id"];
                    $category_name_p=$row_p["category_name"];
                    $category_list .= "<option value='$id_p' disabled='disabled'>$category_name_p</option>";
                    $sql_4=mysql_query("SELECT id,category_name FROM category WHERE parent='$id_p'");
                    while($row_c = mysql_fetch_array($sql_4)){
                        $id_c=$row_c["id"];
                        $category_name_c=$row_c["category_name"];
                        if($category == $id_c){
                            $category_list .= "<option value='$id_c' selected='selected'>&nbsp;&nbsp;&nbsp;&nbsp;$category_name_c</option>";
                        }else{
                            $category_list .= "<option value='$id_c'>&nbsp;&nbsp;&nbsp;&nbsp;$category_name_c</option>";
                        }

                    }
                }
                $category_list .="</select>";
                $details=$row["details"];
                //Info
                $sql_5=mysql_query("SELECT id, add_info FROM info WHERE parent='$targetID'");
                $info_count=mysql_num_rows($sql_5);
                global $info_count;
                $info_table ="                    
                    <tr>
                        <td>Τεχνικά Χαρακτηριστικά</td>";

                if($info_count > 0){
                    $counter = 0; 
                    while($row_8 = mysql_fetch_array($sql_5)){
                        if( $counter == 0){
                            $info_id  = $row_8["id"];
                            $info_add = $row_8["add_info"];
                            $info_table .="<td><input type='text' name='information[]' id='information' size='84' value='$info_add'/></td></tr>";
                            $counter = $counter + 1;
                        }else{

                            $info_id  = $row_8["id"];
                            $info_add = $row_8["add_info"];
                            $info_table .="<tr>
                                            <td></td>
                                            <td>
                                                <input type='text' name='information[]' id='information' size='84' value='$info_add'/>
                                            </td>
                                        </tr>";

                        }/* End Else If */

                    }/*End While*/
                }


                $date_added=strftime("%b %d, %Y", strtotime($row["date_added"]));
            }

        }else{

            echo "This product doesn't exist anymore."; 

        }

    }

?>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Inventory Area</title>

<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/>

<SCRIPT language="javascript">
    //Add Information
    i=<?php echo $info_count ?>;
    function addRow(tableID) {

        var table = document.getElementById(tableID);

        var rowCount = 7+(i-1);
        var row = table.insertRow(rowCount);

        var cell1 = row.insertCell(0);

        var cell2 = row.insertCell(1);
        cell2.innerHTML = table.rows[6].cells[1].innerHTML;
        document.getElementById(information[i-1]).value="";
        i++;
    }

    function deleteRow(tableID) {
        if(i>=2){
            var table = document.getElementById(tableID);
            table.deleteRow(i+5);
            i--;
        }
    }

</SCRIPT>

<div align="center" id="mainWrapper"> 

  <?php include_once("template_header.php");?>

  <div id="pageContent">

        <form action="edit_product.php" enctype="multipart/form-data" name="my_Form" id="my_Form" method="post">

            <h2>Επεξεργασία Προϊόντος</h2>

            <table width="80%" border="0" cellspacing="0" cellpadding="6" id="dataTable">

                <tr>
                    <td>Όνομα</td>
                    <td>
                        <label>
                        <input name="product_name" type="text" id="product_name" size="100" value="<?php echo $product_name ?>" />
                        </label>
                    </td>
                </tr>

                <?php echo $condition;?>

                <tr>
                    <td>Τιμή</td>
                    <td>
                        <label>
                            <input name="price" type="text" id="price" size="20" value="<?php echo $price ?>" />
                        </label>
                    </td>
                </tr>

                <tr>
                    <td>Προμηθευτές</td>
                    <td>
                        <?php echo $suppliers_list; ?>
                    </td>
                </tr>

                <tr>
                    <td>Κατηγορία</td>
                    <td>
                        <?php echo $category_list; ?>
                    </td>
                </tr>

                <tr>
                    <td>Περιγραφή</td>
                    <td>
                        <label>
                            <textarea name="details" id="details" cols="64" rows="5"><?php echo $details ?> </textarea>
                        </label>
                    </td>
                </tr>

                <?php echo $info_table ?>

                <tr>
                    <td></td>
                    <td>
                    <INPUT type="button" value="Προσθήκη" onClick="addRow('dataTable')"/>
                    <INPUT type="button" value="Αφαίρεση" onClick="deleteRow('dataTable')"/>
                    </td>
                </tr>

                <tr>
                    <td>Εικόνα</td>
                    <td>
                        <label>
                            <input type="file" name="my_photo" id="my_photo"/>
                        </label>
                    </td>
                </tr>

                <tr>
                    <td>&nbsp;</td>
                    <td>
                        <label>
                            <input name="thisID" type="hidden" value="<?php echo $targetID ?>" />
                            <input type="submit" name="button" id="button" value="Αποθήκευση" />
                        </label>
                    </td>
                </tr>

            </table>

        </form>



  </div>

  <?php include_once("../template_footer.php");?>

</div>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:41:33+00:00Added an answer on May 31, 2026 at 8:41 am

    JavaScript:

    function insertRow(position) {
        var table = document.getElementById("theTable");
        var tr = table.insertRow(position);
        var td = tr.insertCell(0);
        tr.insertCell(1);
        tr.insertCell(2);
        var textNode = document.createTextNode("\u00A0");
        td.appendChild(textNode);
    }
    

    jQuery:

    function insertRow() {
        $("#theTable").append("<tr><td>&nbsp;</td><td></td><td></td></tr>");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to recover a table in a MySQL database from Time Machine, however
Trying to make a make generic select control that I can dynamically add elements
I'm trying to load data into a data frame in R from a state
I'm trying to fix my code to enable Perl to recover unneeded data by
I trying to recover some old source code (plain text) from a bunch of
I'm trying to create a stored procedure which will fetch data from sys.databases and
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I am trying to persist a Class with a LinkedList Attribute but can't seem
I am trying to figure out on which data the crc32 field in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.