Jump to content

Zserene

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by Zserene

  1. The p_id pulls over data fine. It's only when I go to update that the error occurs. $the_user_id is set to the p_id at the top of the code. It is then used in the "WHERE" statement of the query to update the correct row in the database: But this code is a duplicate from another page I made, the only difference is on this page I use a bootstrap table, not sure that should make any difference though. I don't know The p_id brought over is for user "1" and is set to $the_user_id via: if(isset($_GET['p_id'])) { $the_user_id = $_GET['p_id']; } That same variable $the_user_id is then used to define which row to change in the update query.
  2. <?php //THE "p_id" IS BROUGHT OVER FROM THE EDIT BUTTON ON VIEW_ALL_USERS if (isset($_GET['p_id'])) { $the_user_id = $_GET['p_id']; } // QUERY TO PULL THE SITE INFORMATION FROM THE p_id THAT WAS PULLED OVER $query = "SELECT * FROM users WHERE user_id = $the_user_id "; ---------------------------------row 10 $select_user = mysqli_query($connection,$query); //SET VALUES FROM ARRAY TO VARIABLES while($row = mysqli_fetch_assoc($select_user)) { -------------------------------------------------row 14 $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_email = $row['user_email']; $user_phone = $row['user_phone']; //$user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id']; }
  3. This is the button on the users page that sets p_id and sends to edit_user: and then at the top of the "edit_user" page it looks like p_id is pulled over: The first for statement at the top of the edit_user page is the if(isset($_GET['p_id'])) { $the_user_id = $_GET['p_id']; Also the page that catches it displays all the user data fine, its only when i got to update it to the DB that it breaks with error.
  4. I have a table with a list of users and an edit button and delete button. When the edit button is pressed on a site it passes the user_id as p_id to the page that catches it and displays the data. The problem is when I click on the "update user" button, I get the following error: Warning: Undefined variable $the_user_id in C:\xampp\htdocs\3-19-21(2) - SafetySite\admin\edit_user.php on line 10 Fatal error: Uncaught TypeError: mysqli_fetch_assoc(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\3-19-21(2) - SafetySite\admin\edit_user.php:14 Stack trace: #0 C:\xampp\htdocs\3-19-21(2) - SafetySite\admin\edit_user.php(14): mysqli_fetch_assoc(false) #1 {main} thrown in C:\xampp\htdocs\3-19-21(2) - SafetySite\admin\edit_user.php on line 14 The weird thing is I had another update user page with a table I created that ran the query to update the table in the database just fine. But as I created it, it didn't look all that great so I recreated the page and used a bootstrap table because of the much cleaner look. Both pages have the exact same PHP code, the only difference is the bootstrap table I added in. So I'm really at a loss with this. Other than the table and PHP code, there is a script at the bottom of the page for the table itself to allow for searching within the table, i'll include that as well. The PHP code is as follows: <?php //THE "p_id" IS BROUGHT OVER FROM THE EDIT BUTTON ON VIEW_ALL_USERS if (isset($_GET['p_id'])) { $the_user_id = $_GET['p_id']; } // QUERY TO PULL THE SITE INFORMATION FROM THE p_id THAT WAS PULLED OVER $query = "SELECT * FROM users WHERE user_id = $the_user_id "; $select_user = mysqli_query($connection,$query); //SET VALUES FROM ARRAY TO VARIABLES while($row = mysqli_fetch_assoc($select_user)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_email = $row['user_email']; $user_phone = $row['user_phone']; //$user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id']; } THE UPDATE QUERY CODE.................................................................................................................... <?php if(isset($_POST['update_user'])) { $user_id = $_POST['user_id']; $user_firstname = $_POST['user_firstname']; $user_lastname = $_POST['user_lastname']; $username = $_POST['username']; $user_email = $_POST['user_email']; $user_phone = $_POST['user_phone']; //$user_image = $_POST['user_image']; $user_title_id = $_POST['user_title_id']; $user_role_id = $_POST['user_role_id']; $query = "UPDATE users SET "; $query .= "user_id = '{$user_id}', "; $query .= "user_firstname = '{$user_firstname}', "; $query .= "user_lastname = '{$user_lastname}', "; $query .= "username = '{$username}', "; $query .= "user_email = '{$user_email}', "; $query .= "user_phone = '{$user_phone}', "; //$query .= "user_image = '{$user_image}', "; $query .= "user_title_id = '{$user_title_id}', "; $query .= "user_role_id = '{$user_role_id}' "; $query .= "WHERE user_id = '{$the_user_id}' "; $update_user = mysqli_query($connection,$query); if(! $update_user) { die("QUERY FAILED" . mysqli_error($connection)); } } ?> THE "UPDATE USER" BUTTON THE USER CLICKS ON TO UPDATE.................................................................................................................... <div class="col-1"> <button class="btn btn-primary" type="submit" name="update_user">Update User</button> </div> Any Help is Greatly Appreciated!
  5. Barand, Thanks so much! That is amazingly helpful and work great. I'll start using this format on the rest of the tables with multi line responses. And thanks for the pointers on placement (or lack thereof) of code within the while loop, easier to fix this stuff now than when I get everything finished up.
  6. Hi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query); // SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id']; // POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>"; //PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?> <tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.