Jump to content

Need help getting a start on this script


tyler_durden

Recommended Posts

I am unsure how to go about this, but this is what i'm trying to do.  At the end of running the script, ultimately I want both the tables 'holiday_reminders' and 'reminders' to be updated.  I have a check box next to a list of holidays on a page, and the code below works like it should updating the 'holiday_reminders' table.  The problem comes with updating the 'reminders' table within this same script.

 

<?php

extract($_POST);
extract($_GET);

    $april_fools = $_POST['april_fools'];
    $boss_day = $_POST['boss_day'];
    $boxing_day = $_POST['boxing_day'];
    $canada_day = $_POST['canada_day'];
    $chinese_new_year = $_POST['chinese_new_year'];
    $christmas = $_POST['christmas'];

  $query = "UPDATE holiday_reminders SET april_fools='".$april_fools."',boss_day='".$boss_day."',boxing_day='".$boxing_day."',canada_day='".$canada_day."',chinese_new_year='".$chinese_new_year."',christmas='".$christmas."' WHERE usrname='$my->username'";mysql_query($query);
if (!mysql_affected_rows()){     $query = "INSERT INTO holiday_reminders (usrname,april_fools,boss_day,boxing_day,canada_day,chinese_new_year,christmas) VALUES ('$my->username','$april_fools','$boss_day','$boxing_day','$canada_day','$chinese_new_year','$christmas')";     mysql_query($query) OR die( mysql_error() );}

echo "april_fools = $april_fools";
echo "boss_day = $boss_day";
echo "boxing_day = $boxing_day";
echo "canada_day = $canada_day";
echo "chinese_new_year = $chinese_new_year";
echo "christmas = $christmas";

?>

 

The question now is how to add to the script to get the holiday name and date into the reminders table listed below (there are other fields but I only included the important ones).

 

CREATE TABLE `reminders` (
  `date_field` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `email` varchar(200) NOT NULL default '',
  `holidayname` varchar(100) NOT NULL default '',
  `usrname` varchar(50) NOT NULL default '',

 

I thought of 2 ways to do it, and I don't know what is better.  I could somehow include in the above code all the variables for the holiday name above to insert, or to grab the info out of another table I created below.

 

CREATE TABLE `holiday_dates` (
  `holiday_code` varchar(25) NOT NULL default '',
  `holiday_date` timestamp NOT NULL default '0000-00-00 00:00:00',
  `holiday_name` varchar(25) NOT NULL default '',
  PRIMARY KEY  (`holiday_code`)

 

Either way, I'm a newbie with PHP, and I haven't been able to find any tutorials on how to exactly do this (a tutorial did help me write the original code I have posted above).

Link to comment
https://forums.phpfreaks.com/topic/48817-need-help-getting-a-start-on-this-script/
Share on other sites

I'm thinking that what i'm trying to do is confusing.  I added some extra code to show what I am trying to do, but i'm missing some simple syntax.

<?php

extract($_POST);
extract($_GET);

    $april_fools = $_POST['april_fools'];
    $boss_day = $_POST['boss_day'];
    $boxing_day = $_POST['boxing_day'];
    $canada_day = $_POST['canada_day'];
    $chinese_new_year = $_POST['chinese_new_year'];
    $christmas = $_POST['christmas'];

  $query = "UPDATE holiday_reminders SET april_fools='".$april_fools."',boss_day='".$boss_day."',boxing_day='".$boxing_day."',canada_day='".$canada_day."',chinese_new_year='".$chinese_new_year."',christmas='".$christmas."' WHERE usrname='$my->username'";mysql_query($query);
if (!mysql_affected_rows()){     $query = "INSERT INTO holiday_reminders (usrname,april_fools,boss_day,boxing_day,canada_day,chinese_new_year,christmas) VALUES ('$my->username','$april_fools','$boss_day','$boxing_day','$canada_day','$chinese_new_year','$christmas')";     mysql_query($query) OR die( mysql_error() );}

$query = "SELECT holiday_date, holiday_name FROM holiday_dates";
  $holidayz = mysql_query($query) or die("Could not query: " . mysql_error());

$query = "INSERT INTO reminders (usrname,date_field,subject) VALUES ('$my->username','$date_field','$holidayname')" where holiday above = 1;     

?>

The last 2 queries are where i'm stuck.  The POST part on the top has a variable of "1" if checked, which is being inserted into the first table/query successfully.  Then, I want to take all the variables with "1", and insert a row into the 'reminders' table inserting the date and holiday name where the variable is "1", with the info in the holiday_date table.

 

Hope this makes more sense...

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.