Jump to content

Updating specific record in mysql field


infrabyte

Recommended Posts

Hi All,

 

Please can someone help me with this bit of code. I have a mysql database with a table called 'events'. I have six fields namely 'ID, mxitID, type, message, ts, publish'.

I am trying to update the field 'publish' from Yes --> No or if it is already No then back to Yes again. I have two files then main one beacon.php and publish.php

Here is the code:

 

beacon.php

<?php
        // connect to the database
        include('connect-db.php');

        // display data in table
//        echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View by Page</a></p>";
//   echo "Select your Carousel: ";
   
   // get results from database
        $result = mysql_query("SELECT * FROM events WHERE type='beacon'")
                or die(mysql_error());

        echo "<table border='1' cellpadding='10'>";
   echo "<a href='index.php'>b Back</a><br><br>";
        echo "<tr> <th>ID</th> <th>mxitID</th> <th>Type</th> <th>Message</th> <th>Timestamp</th> <th>Published</th> <th>Modify</th></tr>";

        // loop through results of database query, displaying them in the table
        while($row = mysql_fetch_array( $result )) {
                
                // echo out the contents of each row into a table
                echo "<tr>";
                echo '<td>' . $row['ID'] . '</td>';
                echo '<td>' . $row['mxitID'] . '</td>';
                echo '<td>' . $row['type'] . '</td>';
      echo '<td>' . $row['message'] . '</td>';
      echo '<td>' . $row['ts'] . '</td>';
      echo '<td>' . $row['publish'] . '</td>';
                echo '<td><a href="publish.php?id=' . $row['ID'] . '"><input name="update" type="submit" id="update" value="Update"></a></td>';
                echo "</tr>"; 
        } 
        // close table>
        echo "</table>";
?>

publish.php
<?php

// connect to the database
include('connect-db.php');

// get id value
$id = $_GET['id'];
echo "$id";

$sql="SELECT * FROM events WHERE type='beacon'";
$result=mysql_query($sql);


$active=($result['publish']=='')?'Yes':'No';
echo "$active";

if ($active='Yes') {
    $active='No';
} else {
    $active='Yes';
}
$sql = "UPDATE events SET publish='$active' WHERE ID='$id'";
$result = mysql_query($sql);

// header("Location: beacon.php");
?>

 

I cant seem to change the value...any help would be much appreciated. Thank you in advance.

 

MOD EDIT: code tags added.

Link to comment
Share on other sites

<?php

// connect to the database
include('connect-db.php');

// get id value
$id = $_GET['id'];
echo "$id";

$sql="SELECT * FROM events WHERE type='beacon'";
$result=mysql_query($sql);


$active=($result['publish']=='')?'Yes':'No';
echo "$active";

if ($active='Yes') {
    $active='No';
} else {
    $active='Yes';
}
$sqltwo = "UPDATE events SET publish='$active' WHERE ID='$id'";
$resulttwo = mysql_query($sqltwo);

// header("Location: beacon.php");
?>

Link to comment
Share on other sites

Hi, Thanx for the feedback.

That doesn't seem to change anything. I just want to change the published field from Yes to No if I click on Update or visa versa

It must be a simple thing but I'm just not seeing it at the mo. This is supposed to be a script that changes a row in the database from published to unpublished (ie Yes/No)

 

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.