简体   繁体   中英

Pull information from an array

So basically I don't really know how to explain what i need or if the title is even correct but i need some help.I'll explain what I'm trying to do the best I can.

This is a picture of the page I'm working on and referring to http://i40.tinypic.com/14m5euh.png .

SO basically what I need to do is,when the user uploads a file and clicks on upload it will upload to a database along with the job number ,so far I've managed to get it to update into the database .

But I can't get the job number in the database because my information is all in an array from the database I tried to store the information into a session variable ,its loops and gets replaced by the next one,so basically what ever the last job number is will be stored in the database which of cause is wrong?

The last problem I've is,how do I get the users answer from the drop down box into a variable ?

My code:

  $con = mysqli_connect("localhost", "root", "","fixandrun") or die(mysqli_error()); 
  $data = mysqli_query($con,"SELECT * FROM bookjob") or die(mysql_error()); 

  Print "<table border cellpadding=10>"; 
  Print "<table border='2'>";

  echo "<table  border='2' cellpadding=10>
        <tr>
            <th> Job number</th>
            <th> Job details</th>
            <th> Pc number </th>

            <th> Job status</th>
            <th> Upload report</th>
            <th> Update Job</th>

        </tr>";

        while($row= mysqli_fetch_array($data))
        {
        echo "<tr>";
            echo "<td>".$_SESSION['JOBNUM'] = $row['jobnumber'] . "</td>";
            echo "<TD width=20% height=100>" . $row['jobdetails'] . "</td>";
            echo "<td>" . $row['pcnumber'] . "</td>";
            echo "<td> <select name='jobprogress'>
                    <option Value='pending'>pending</option>
                    <option value='Completed'>Completed</option>
                    <option value='In progress'>In progress</option>
                    <option value='Need more information'>Need more information</option>

                </select>  </td>";
            echo "<td>  <form action='reportupload.php' method='post' enctype='multipart/form-data' name='uploadform'>
                    <input type='hidden' name='MAX_FILE_SIZE' value='350000'>
                    <input name='report' type='file' id='reportupload' size='50'>
                    <input name='upload' type='submit' id='upload' value='Upload'>
                </form>
            </td>";
            echo "<td> <a href='updateadmin.php'>Update information</a></td>";
            echo "</tr>";
        }
        echo "</table>";
    echo "<br>";

There are many problems with your code. It would be extremely time consuming to go through them all, so I'll run down some things you need to look at to get this going.

FIrstly, you can make as many forms as you want, and with the help of PHP you can do this dynamically as youre doing. The problem is for every job, youre creating a new form with the same exact name. You need to find a way to make them the name of each form dynamic if youre going to do that.

Secondly, you probably shouldnt make a new form, so take all your opening and closing tags out of the loop, put the opening form tag before the while, and the ending form tag after the while loop.

I would suggest you go read about HTML forms a little more and PHP while loops and fetching information from a database with embedded forms before messing with this more. No offence, but I think you need a little more knowledge on this before fiddling with it.

I would suggest making a test database and table with maybe 3 fields, then making a small form with a couple field and seeing if you can fetch the data and update it with your form first.

i think i have done what you ment, is this right now?

        $cnt = 0;
                while($row= mysqli_fetch_array($data))
                  {
                echo " <form action='test.php' method='post' enctype='multipart/form-data' name='uploadform' . $cnt>";

                      echo "<tr>";
                      echo "<td>".$_SESSION['JOBNUM'. $cnt] = $row['jobnumber'] . "</td>";
                      echo "<TD width=20% height=100>" . $row['jobdetails'] . "</td>";
                      echo "<td>" . $row['pcnumber'] . "</td>";
                      echo "<td> <select name='jobprogress'>
                          <option Value='pending'>pending</option>
                          <option value='Completed'>Completed</option>
                          <option value='In progress'>In progress</option>
                          <option value='Need more information'>Need more information</option>

                          </select>  </td>";
                      echo "<td> 
    <input type='hidden' name='MAX_FILE_SIZE' value='350000'>
    <input name='report' type='file' id='reportupload' size='50'>


                                    </td>";
                      echo "<td><input name='upload' type='submit' id='upload' value='Upload'></td>";
                      echo "</tr>";

                      echo "</form>";
                      ++$cnt;
                  }
                echo "</table>";
                echo "<br>";


                    ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM