Jump to content

Button on mysql


XCalibre3

Recommended Posts

I have written this code:

 

<?php
    						 if(!$customer_details)
    						 {
    						 }
    						 else{
    							foreach($customer_details as $key=>$value)
    							{
    								?>
    							<tr>
    								<td><?php echo $key+1;?>&nbsp&nbsp</td>
    								<td><?php echo $value['fname'];?>&nbsp<?php echo $value['lname'];?></td>
    								<td>&nbsp&nbsp&nbsp&nbsp<?php echo $value['email'];?></td>
    								<td>&nbsp&nbsp&nbsp&nbsp<?php echo $value['phone'];?></td>
    								<td>&nbsp&nbsp&nbsp&nbsp<?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.... :D ..... 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 by XCalibre3
Link to comment
Share on other sites

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 by Strider64
Link to comment
Share on other sites

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;?>&nbsp&nbsp</td>
    								<td><?php echo $value['fname'];?>&nbsp<?php echo $value['lname'];?></td>
    								<td>&nbsp&nbsp&nbsp&nbsp<?php echo $value['email'];?></td>
    								<td>&nbsp&nbsp&nbsp&nbsp<?php echo $value['phone'];?></td>
    								<td>&nbsp&nbsp&nbsp&nbsp<?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 by XCalibre3
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 by XCalibre3
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.