Jump to content

Event display


Nimbuz

Recommended Posts

  • Replies 53
  • Created
  • Last Reply

Well, the final piece of the puzzle is missing. Once you have the data there, you have to have a block of code to check if the update form has been submitted, and if so, grab the data and run an update query.

 

When it comes to editing mysql data, you have 2 parts to it. Grab the desired row and display it in the form so it can be edited, then when that form is submitted, run an update query to update that row. Make sure you have the WHERE fieldID='$fieldID' part or you will update all your records to the data in the query.... that sucks when you have a lot of stuff to go back and correct.

 

Luckily I only did this once or twice before I learned to check for that WHERE clause before running the query to test it.

 

<?php

if(isset($_POST['update_event']))
{
  // grab $_POST data and set in friendly var names
  // create update query
$query = "UPDATE events SET fieldName='$fieldValue', fieldName2='$fieldValue2'..... WHERE eventId='$eventId'";
// run query
  if(mysql_affected_rows() > 0)
  {
    echo 'Row Updated';
  }

}
?>

 

Notice I did not actually create the code for you. I gave you the skeleton, you will have to finish it out.

 

I also noticed something here....

<?php
  /* these need to go inside the if statement below */
    $eventName = mysql_real_escape_string($_POST['event_name']);
    $eventLocation = mysql_real_escape_string($_POST['event_location']);
    $eventDate = date('Y-m-d H:i:s', strtotime($_POST['event_date']) ); // FORMAT: 05/30/09 1:35 am
  /* these need to go inside the if statement below */

      if(isset($_POST['create_event'])) {
        // Insert Values in a Row
         $insert_sql = "INSERT INTO events (eventName, eventLocation, eventDate) VALUES ('$eventName', '$eventLocation', '$eventDate')";
         $result = mysql_query($insert_sql, $connection) or die("Row insert failed: " . mysql_error());
        // If (or not) successful...
         if(mysql_affected_rows() > 0) {        
            echo "1 record added";
         }
      }
?>

 

See what you can do with that. I will check back tomorrow morning.

 

Nate

Link to comment
https://forums.phpfreaks.com/topic/141034-event-display/page/3/#findComment-740268
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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