Hello Everyone,
Im relativity new to PHP and MySQL and i have come up against a problem.  i have 2 tables that are linked via foreign key constraints.
Code: --
-- Table structure for table `rides`
--
CREATE TABLE rides (
  ride_date TIMESTAMP,
  ride_name VARCHAR(50) NOT NULL,
  planned_distance_travelled INT(5),
  actual_distance_travelled INT(5),
  planned_time_taken INT(5),
  actual_time_taken INT(5),
  average_heart_rate INT(5),
  calories_burned INT(5),
  weather_conditions VARCHAR(100),
  feelings_about_ride VARCHAR(100),
  PRIMARY KEY (ride_date)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Table structure for table `usersrides`
--
CREATE TABLE usersrides (
  userid SMALLINT UNSIGNED NOT NULL,
  ride_date TIMESTAMP,
  weight int(5),
  PRIMARY KEY (userid,ride_date),
  CONSTRAINT `fk_usersrides_ride_date` FOREIGN KEY (ride_date) REFERENCES ride (ride_date) ON DELETE RESTRICT ON UPDATE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
As you can see they are linked by the ride_date, which is a timestamp.  This means that inorder to successfully insert data into the tables, the data must be inserted at the same time to the second.  
This is the PHP script i am using to insert the data into the 2 tables:
Code: <?php
   echo connect();
            
   $userid = $_SESSION['userid'];
   $weight = 0;
            
   $ride_name = $_POST['ride_name'];
   $planned_dist_trav = $_POST['planned_dist_trav'];
   $actual_dist_trav = $_POST['actual_dist_trav'];
   $planned_time_tak = $_POST['planned_time_tak'];
   $actual_time_tak = $_POST['actual_time_tak'];
   $avg_heart_rate = $_POST['avg_heart_rate'];
   $calories= $_POST['calories'];
   $weather_cond = $_POST['weather_cond'];
   $feelings = $_POST['feelings'];
            
   $ride_name = stripslashes($ride_name);
   $planned_dist_trav = stripslashes($planned_dist_trav);
   $actual_dist_trav = stripslashes($actual_dist_trav);
   $planned_time_tak = stripslashes($planned_time_tak);
   $actual_time_tak = stripslashes($actual_time_tak);
   $avg_heart_rate = stripslashes($avg_heart_rate);
   $calories = stripslashes($calories);
   $weather_cond = stripslashes($weather_cond);
   $feelings = stripslashes($feelings);
            
   $ride_name = mysql_real_escape_string($ride_name);
   $planned_dist_trav = mysql_real_escape_string($planned_dist_trav);
   $actual_dist_trav = mysql_real_escape_string($actual_dist_trav);
   $planned_time_tak = mysql_real_escape_string($planned_time_tak);
   $actual_time_tak = mysql_real_escape_string($actual_time_tak);
   $avg_heart_rate = mysql_real_escape_string($avg_heart_rate);
   $calories = mysql_real_escape_string($calories);
   $weather_cond = mysql_real_escape_string($weather_cond);
   $feelings = mysql_real_escape_string($feelings);
                     
                  
   //add the date into the rides table
   $sql="INSERT INTO rides (ride_name, planned_distance_travelled, actual_distance_travelled, planned_time_taken, actual_time_taken, average_heart_rate, calories_burned, weather_conditions, feelings_about_ride) VALUES ('$ride_name','$planned_dist_trav','$actual_dist_trav','$planned_time_tak','$actual_time_tak','$avg_heart_rate','$calories','$weather_cond','$feelings')";
   $result=mysql_query($sql);
      if (!$result) {
         die('Error: ' . mysql_error());
      }elseif ($result) {
          echo "1 Record Added to the rides table";
           echo "<BR>";
        }
                    
                    
   //add the date into the usersrides table
   $sql1="INSERT INTO usersrides (userid, weight) VALUES ('$userid','$weight')";
   $result1=mysql_query($sql1);
      if (!$result1) {
         die('Error: ' . mysql_error());
      }elseif ($result1) {
         echo "1 Record Added to the usersrides table";
         //header("Refresh: 2; url=home.php");
      }
      mysql_close()
?>
I realise this is alot of reading, but i didnt know how to explain this situation any other way.  At the moment, data is being inserted into the 'rides' table, but when it gets to the usersrides table a foriegn key error comes up. 
What i would like to know is....Is what im trying to do possible?
Thanks in advance,
-Regards,
bit of help needed
Im about to sort out my registration page for my website by customising a "registration" script I came across. It has about all that I need, apart from the changes that i need to make to it
IIS7 and getimagesize() problem
I have just discovered after hrs of trying to fix a problem where it's coming from. It's to do with the php function getimagesize() and path names.When using these two different sets of code:Code:
Custom array sort? asc then desc
Any ideas how I could sort this array? I've been trying for a while. Maybe with usort, but I have no idea how... Each entry is laid out like this: ("$status||$id||$shop||$name||$date")I
Transform value 0 in no and 1 in yes help needed
Hello,I have this in the table: "value" type int 0 to represent false and 1 to represent true. everything works great in display to the user end it sees 0 or 1 i want to replace the 0 to
Format timestamp from mysql
When I tried this:Code: date("m/d/Y H:i A", $row['timestamp'])I got 12/31/1969 18:33 PM, so I know the time section is working at least. How can I get the mm/dd/yyyy section to work
Help with explandable category tree
I have the below query: SELECT l1.id as lev1_id,l2.id as lev2_id,l3.id as lev3_id,l1.category AS lev1, l2.category as lev2, l3.category as lev3 FROM categories AS l1LEFT JOIN categories AS l2 ON
mails going in spam??
The mails I sent to folks in my database using mail(function) are going in spam??Any idea how I rectify this issue?
Error with login script
I am getting an error with my login script:Error:Code: Warning: Cannot modify header information - headers already sent by (output started at /home/bucket/public_html/inc/config.php:7) in
Connect to database that isn't localhost
I am currently doing a small script for a company that doesn't have mySql support on there hosting. How would I connect to the database on my hosting account? Currently I am using the following but
Creation of Raw Exposure manually
SAP Gurus