infrabyte Posted May 23, 2011 Share Posted May 23, 2011 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 https://forums.phpfreaks.com/topic/237220-updating-specific-record-in-mysql-field/ Share on other sites More sharing options...
gristoi Posted May 23, 2011 Share Posted May 23, 2011 <?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 https://forums.phpfreaks.com/topic/237220-updating-specific-record-in-mysql-field/#findComment-1219087 Share on other sites More sharing options...
Pikachu2000 Posted May 23, 2011 Share Posted May 23, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Link to comment https://forums.phpfreaks.com/topic/237220-updating-specific-record-in-mysql-field/#findComment-1219089 Share on other sites More sharing options...
infrabyte Posted May 23, 2011 Author Share Posted May 23, 2011 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 https://forums.phpfreaks.com/topic/237220-updating-specific-record-in-mysql-field/#findComment-1219097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.