XCalibre3 Posted April 23, 2023 Share Posted April 23, 2023 (edited) I have written this code: <?php if(!$customer_details) { } else{ foreach($customer_details as $key=>$value) { ?> <tr> <td><?php echo $key+1;?>  </td> <td><?php echo $value['fname'];?> <?php echo $value['lname'];?></td> <td>    <?php echo $value['email'];?></td> <td>    <?php echo $value['phone'];?></td> <td>    <?php echo $value['resnum'];?></td> <td><?php echo '<td><button type="submit" name="status" value='.$value['id'].' />status</button></td>'; ?> </tr> <?php I know, the code is not lined and a mess.... ..... but, I've tried using php to make the status button try even the simplest echo something and can't get it figured out. I need the button to change from status to flagged if possible, and then in database change 0 to 1 Thank you! Edited April 23, 2023 by XCalibre3 Quote Link to comment https://forums.phpfreaks.com/topic/316202-button-on-mysql/ Share on other sites More sharing options...
Strider64 Posted April 23, 2023 Share Posted April 23, 2023 (edited) First of all this is the proper way of doing this line <?php echo '<td><button type="submit" name="status" value="'.htmlspecialchars($value['id']).'">status</button></td>'; ?> Second I don't why you are doing the following? if(!$customer_details) Plus showing how you handle the database connection and how you change the values would be helpful. Edited April 23, 2023 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/316202-button-on-mysql/#findComment-1607637 Share on other sites More sharing options...
XCalibre3 Posted April 23, 2023 Author Share Posted April 23, 2023 (edited) 36 minutes ago, Strider64 said: First of all this is the proper way of doing this line <?php echo '<td><button type="submit" name="status" value="'.htmlspecialchars($value['id']).'">status</button></td>'; ?> Second I don't why you are doing the following? if(!$customer_details) Plus showing how you handle the database connection and how you change the values would be helpful. This is the database code: <?php $servername='localhost'; $username="root"; $password=""; try { $con=new PDO("mysql:host=$servername;dbname=calendar",$username,$password); $con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); //echo 'connected'; } catch(PDOException $e) { echo ''.$e->getMessage(); } $searchErr = ''; $customer_details=''; if(isset($_POST['save'])) { if(!empty($_POST['search'])) { $search = $_POST['search']; $stmt = $con->prepare("select * from reservations where fname like '%$search%' or lname like '%$search%' or resnum like '%$search%' or email like '%$search%' or phone like '%$search%'"); $stmt->execute(); $customer_details = $stmt->fetchAll(PDO::FETCH_ASSOC); //print_r($customer_details); ?> <div class="table-responsive"> <table class="table"> <tr> <th>#</th> <th>Name</th> <th>Email</th> <th>Phone</th> <th>Reservation #</th> </tr> <?php if(!$customer_details) { } else{ foreach($customer_details as $key=>$value) { ?> <tr> <td><?php echo $key+1;?>  </td> <td><?php echo $value['fname'];?> <?php echo $value['lname'];?></td> <td>    <?php echo $value['email'];?></td> <td>    <?php echo $value['phone'];?></td> <td>    <?php echo $value['resnum'];?></td> <?php echo '<td><button type="submit" name="status" value="'.htmlspecialchars($value['id']).'">status</button></td>'; ?> </tr> <?php } } } else { $searchErr = "Please enter the information"; } } if(isset($_POST['status'])) { echo "working"; } The echo working was just a try to see what happend. I still need button to change to flagged and database to change too 1. Edited April 23, 2023 by XCalibre3 Quote Link to comment https://forums.phpfreaks.com/topic/316202-button-on-mysql/#findComment-1607638 Share on other sites More sharing options...
mac_gyver Posted April 23, 2023 Share Posted April 23, 2023 a <button> by itself doesn't do anything. a button with type='submit' must be part of a form. a button without type='submit' must have an event or javascript associated with it to do anything. you will need to put a complete post method form, with a button with type='submit', within the html table cell, for this to work. Quote Link to comment https://forums.phpfreaks.com/topic/316202-button-on-mysql/#findComment-1607640 Share on other sites More sharing options...
XCalibre3 Posted April 23, 2023 Author Share Posted April 23, 2023 7 minutes ago, mac_gyver said: a <button> by itself doesn't do anything. a button with type='submit' must be part of a form. a button without type='submit' must have an event or javascript associated with it to do anything. you will need to put a complete post method form, with a button with type='submit', within the html table cell, for this to work. OMG I'm laughing so hard.... DUH! I'll pput the form and see what happens lol Quote Link to comment https://forums.phpfreaks.com/topic/316202-button-on-mysql/#findComment-1607641 Share on other sites More sharing options...
XCalibre3 Posted April 23, 2023 Author Share Posted April 23, 2023 14 minutes ago, mac_gyver said: a <button> by itself doesn't do anything. a button with type='submit' must be part of a form. a button without type='submit' must have an event or javascript associated with it to do anything. you will need to put a complete post method form, with a button with type='submit', within the html table cell, for this to work. Okay it's working now LOL! SMH..... but how to change from status to flagged on mysql button? Would it be the same php code to change name on a button, or do I need to write it diferently b/c it's in thee database? Quote Link to comment https://forums.phpfreaks.com/topic/316202-button-on-mysql/#findComment-1607642 Share on other sites More sharing options...
XCalibre3 Posted April 24, 2023 Author Share Posted April 24, 2023 (edited) Okay, I ended up doing this instead. I turned the button text color to red, so flagged shows as red, which means they either no showed on the reservation, or gave trouble to the diving instructor. Flagged in red lets us decide if we want to allow them to come again. but it won't change the background color; which I would like. Any suggestions? <?php if ($value['flagged'] == 'Yes') { echo '<td><button type="submit" style=color:red; name="flagged" value="'.htmlspecialchars($value['id']).'">Flagged</button></td>'; }else{ ?> <?php echo '<td><button type="submit" name="flagged" value="'.htmlspecialchars($value['id']).'">Flagged</button></td>'; ?> I tried the basic style= again and didn't work Edited April 24, 2023 by XCalibre3 Quote Link to comment https://forums.phpfreaks.com/topic/316202-button-on-mysql/#findComment-1607654 Share on other sites More sharing options...
XCalibre3 Posted April 24, 2023 Author Share Posted April 24, 2023 I just changed the <td> color instead. Don't know if there's anyone online to help, but I did accomplish changing the <td>; which works for what I wanted. Quote Link to comment https://forums.phpfreaks.com/topic/316202-button-on-mysql/#findComment-1607655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.