Jump to content

Event display


Nimbuz

Recommended Posts

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

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