Jump to content

form code expansion help please


paulmo

Recommended Posts

This line is whack, to use a technical term:php$month = intval(date('G')) [1, 2, 3] ? 'winter' : intval(date('G')) [4, 5,] ? 'Spring' : intval(date('G')) [6, 7, 8] ? 'summer' : intval(date('G')) [9, 10, 11] ? 'harvest' : intval(date('G')) [12] ? 'Holiday Season';Replace that with this:

switch (intval(date('G')){  case 1: case 2: case 3:	$month = 'Winter';  break;  case 4: case 5:	$month = 'Spring';  break;  case 6: case 7: case 8:	$month = 'Summer';  break;  case 9: case 10: case 11:	$month = 'Harvest';  break;  case 12:	$month = 'Holiday Season';  break;}

Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

thanks guy i added the paren. the form is activating again but the "month" variable is still not working. here's the code now:

<?phpswitch (intval(date('G'))){  case 1: case 2: case 3:	$month = 'Winter';  break;  case 4: case 5:	$month = 'Spring';  break;  case 6: case 7: case 8:	$month = 'Summer';  break;  case 9: case 10: case 11:	$month = 'Harvest';  break;  case 12:	$month = 'Holiday Season';  break;}$time = intval(date('G')) < 12 ? 'morning' : intval(date('G')) < 18 ? 'afternoon' : 'evening';//^These^ are 2 shorthand 'if's, known as "ternary (three-part) statements" or "conditional statements."// $destinationVar = $trueOrFalse ? 'if true' : 'if false';switch($_POST['theme']){	case 'grey':		echo "A somber {$month} {$time} blankets your spirit, {$_POST['Name']}, but grey also provides an insulating comfort, calm, and reflection; be in it for a while and cherish its evenness.";		break;	case 'black':	   echo "A difficult {$month} {$time} casts over your spirit at the moment, {$_POST['Name']}, yet before every breakthrough lies a challenge through darkness, anxiety and the unknown. Stay vigilant and prepare yourself for the return of joy, laughter, and saving light.";		break;	case 'light':		echo "The joy of light is upon you this {$_POST['month']} {$time} {$_POST['Name']}; you are a living manifestation of satisfaction, confidence and love. You are merged with positive energy, and at the apex of living. Remember where you are now, as you will aspire to return here.";		break;	default:		echo "Please choose a theme, {$_POST['Name']}.";}?>

further direction is greatly appreciated—paul

Link to comment
Share on other sites

Make sure you have error messages enabled. I'm not sure if line breaking is screwing something up, but you have a single line comment on more then one line. Add this at the top:ini_set("display_errors", 1);error_reporting(E_ALL);

Link to comment
Share on other sites

someguy whatever that ini_set error code does it worked! however the month variables are taking a life of their own; summer and harvest have been called within the past hour (not spring as it should be, case/month 4), and the time is still off (afternoon at 10 am est) even with the javascript local time fix (which is posted here somewhere—chris showed me that). another step closer—thanks

Link to comment
Share on other sites

I should have checked the reference. In the date function the G modifier returns the 24-hour time, not the month. To get the month use "n". I'm not sure what you're doing with the Javascript function, I don't know what the offset element is, but all that Javascript function does is get the current hour and subtracts whatever the offset value is from the current hour, then saves that back as the offset value. Your PHP script isn't doing any time correction, it's just using date('G'), which is the server time.

Link to comment
Share on other sites

ok tried this

switch (intval(date('N')))

getting a line error now (and had been just before replacing g with n...variable/month error line 61, which there is no line 61 using go to line or status bar...

Link to comment
Share on other sites

this is great it's working! thanks so much. the months are on, but time seems to be an issue i'll have to tackle. now i need to add another value (?) to the $month variables. like at first i'm using the season for the month, "happy Spring morning" etc. but then i'd like to call another term for those month cases later on, like, "during this time of awakening or rebirth..." (for spring) or "during the storms and cold" (winter etc.) which i'd call using an offshoot from the $month variable i'm guessing if it can be done that way.

case 1: case 2: case 3:	$month = 'winter';

like can you have a $month value with different 'words' assigned to it? or create a montha or monthb and list all the cases 123 etc. with different text? thanks

Link to comment
Share on other sites

Yeah, just assign more then one variable in the switch, or use an array.

switch (intval(date('n'))){  case 1: case 2: case 3:	$month1 = 'Winter';	$month2 = 'cold';  break;

switch (intval(date('n'))){  case 1: case 2: case 3:	$month['season'] = 'Winter';	$month['temp'] = 'cold';  break;

Link to comment
Share on other sites

Just think of an array like a table or an Excel spreadsheet. Most arrays only have one row, that's a single-dimension array with just a series of "columns" or elements. They can either be numbered, which is the default, or you can give each element a name like I did above. If you have a multidimension array then it's like you have rows and columns. Since array numbering starts at 0 instead of 1, this would reference "row" 3, "column" 5:$array[2][4]That's for a 2-dimensional array, which is basically what a table is. Higher order arrays become difficult to conceptualize, I've had to write a program that used a 5-dimensional array but that's the largest I've worked with in practice.

Link to comment
Share on other sites

wow that is cool—i'm visualizing a 2D and seeing the potential. anyhow this variable/switch stuff is what i've needed. thanks for getting me here! now i'm going to incorporate a database, for practice and monitoring visitors, time of day and what mood they're in would be helpful. will i link to database from php page or need separate page/file type?also if you want credit link to from my site let me know.

Link to comment
Share on other sites

thanks for that link will work on database. would like to capitalize first letter of person's name on input form, in case person writes in small case. doesn't matter that it corrects it right away (like in Word) just that it gets processed when form's processed. ideas for this? thank you

Link to comment
Share on other sites

i've tried this in php page, up top, nested (?) in 'Name', re-naming str 'Name' (from form), tried in html form page. guess i'm lost again.also re-named a radio field value 'dark' instead of 'black' and revised 'case' accordingly in php process page...field is staying 'black' on radio form and not executing (just that value). fix for this? thanks

Link to comment
Share on other sites

warning, this is getting messy. have created a table in database in php admin/mysql (not in a doc like everywhere on help sites), external page, dbconnect.php fragment of:

mysql_select_db("xxx") or die(mysql_error()); echo 'Connected successfully';mysql_close($link);

seemed to work as it said "connected successfully" in my page after processed form. connected where i know not. trying INSERT INTO (code below) as it seems that's a feature that can store user info from form. thought was setting table up right with "name" field since my form has "name" field, but "name"'s not not working either now (was "Name"); like changing "black" to "dark", seems changing anything in a form causes problems. plus i really have no idea what i'm doing regarding interacting the form with the database at this point. ultimate plan is to automatically post user messages to specific page column on site (instead of e-mail form as it is now), with text format and colored quote marks dependent on selected gray light dark (more switches i'm guessing), with user input field info name location etc. listed below message pretty much like a guestbook, then store or insert user info and messages into database for admin/editing purposes. the capital first letter code is about half way down here.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"		"http://www.w3.org/TR/html4/loose.dtd"><html lang="en"><head><meta content="Pursuit of pleasure defined." name="description">	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">	<title> Release Center Interactive: Paul Mollomo, MA </title>	<link rel="stylesheet" type="text/css" href="columns.css"></head><div id="header"><img src="banner-interactive.gif"></div><div id="col1"><p style="font-variant:small-caps;" > <strong>process</strong></p><p><?phpini_set("display_errors", 1);error_reporting(E_ALL); include ('dbconnect.php');$query = "INSERT INTO contacts (name,";) VALUES ";  $query.= "('".$name."')";  $result = $database->query($query);switch (intval(date('n'))){case 1: case 2: case 3:	$month1 = 'winter';  break;  case 4: case 5:$month1 = 'Spring';$month2 = 'despite the warming air and profusion of life all around you.'; $month3 = 'and the profusion of life is awakening your senses. Anything seems possible, and it is!';$month4 = 'and the awakening life around you is beyond your scope right now.'; $month5 = 'When you do emerge from the dire moment, you will be surprised by the simplest beauties that Nature is spawning—yourself included!';$month6 = 'After this time in incubation, you will notice that the mists of grey have provided life to the burgeoning growth: both in the natural world and in yourself.';$month7 = 'The budding trees and flowering shrubs are symbolic of your bursting forth in unbridaled potential.';break;  case 6: case 7: case 8:	$month = 'summer';  break;  case 9: case 10: case 11:	$month = 'harvest';  break;  case 12:	$month = 'Holiday Season';  break;}$str = strtoupper(substr($name, 0, 1)) . strtolower(substr($name, 1)); $time = intval(date('G')) < 12 ? 'morning' : intval(date('G')) < 18 ? 'afternoon' : 'evening';//^These^ are 2 shorthand 'if's, known as "ternary (three-part) statements" or "conditional statements."// $destinationVar = $trueOrFalse ? 'if true' : 'if false';switch($_POST['theme']){	case 'grey':		echo "A somber {$month1} {$time} blankets your spirit, {$_POST['name']}, {$month2} But, grey can also provide peace, calm, and reflection. Ride through grey for the time being, and organize your direction. </p><p>{$month6}";	   break;	case 'dark':	   echo "A difficult {$month1} {$time} casts over your spirit at the moment, {$_POST['name']}, {$month4} </p><p>Yet, before every breakthrough lies a challenge through darkness, anxiety and the unknown. Stay vigilant and prepare yourself for the return of joy, laughter, and saving light.</p><p>{$month5}";		break;	case 'light':		echo "The joy of light is upon you this {$month1} {$time}, {$_POST['name']}, {$month3} You are living in satisfaction, confidence and love. </p><p>You are merged with positive energy, and at the apex of living. {$month7} </p><p>Remember where you are now, as you will aspire to return here!";		break;	default:		echo "Please choose a theme, {$_POST['name']}.";}?></p><br/><br/><ul>					<li><a href="index.php">interactive</a></li>				</ul></div><div id="col2"><p>Wish to share your experience with the Release Center Interactive? </br>Use the form below; your thoughts are appreciated! <form method="post" action="contact.php"> <input type="hidden" name="redirect" value="redirect.php" /><p>E-mail: </p><input name="email" type="text" cols="25" class="buttonsb"><br><p>Message:</p> <textarea name="message" rows="9" cols="50" class="buttonsb"></textarea><br> <input type="submit" name="submit" value="Send" class="buttons"/> </form> </p></div><div id="footer"><h5>Site content and design © Paul Mollomo 2008.<br><a href="pauldriftwood.html">Visit Paul Driftwood: Shades of Blues.</a></center></h5></div></body></html>

Link to comment
Share on other sites

first i changed the form:

<form method="post" action="interactive.php"> <input type="hidden" name="check_submit" value="1" /><p>Identity: <input name="identity" type="text" cols="25" class="buttonsb">Location: <input name="location" type="text" cols="25" class="buttonsb"></br>E-mail/Website: <input name="web" type="text" cols="15" class="buttonsb">Occupation/Interest: <input name="occupation" type="text" cols="8" class="buttonsb"></p><p>Message:</br> <textarea name="message" rows="9" cols="50" class="buttonsb"></textarea></br> <input type="submit" name="submit" value="Send" class="buttons"/> </form> </p></div>

this is how i'm trying to interact with database, with new form variables to put it all together (changed name to identity). again this is to be a posted comments form no longer an e-mail form:

<?php ini_set("display_errors", 1);error_reporting(E_ALL); include ('dbconnect.php');$query = "INSERT INTO contacts (identity, location, web, ";$query.= "occupation, message) VALUES ";$query.= " ( ' ".$identity."', ' ". $location."', '".$web. " ', ";$query.="'".$occupation."','".$message."')";$result = $database->query($query);$str = strtoupper(substr($str, 0, 1)) . strtolower(substr($str, 1)); $destinationVar = {$_POST ['message']} </br>{$_POST ['identity']}{$_POST ['location']}{$_POST ['web']}{$time}?>

Also, are you connecting to the database server before you select the database?
i'm unsure about that. here is my dbconnect page without server, password info etc.
$link = mysql_connect('xxx', 'xxx', 'xxx');mysql_select_db("xxxx") or die(mysql_error()); echo 'Connected successfully';mysql_close($link);

as far as database goes i set up table with name location etc variables but unsure if it's interacting if at all. doesn't seem to be collecting anything like name entry.

Link to comment
Share on other sites

First off, about this:

$link = mysql_connect('xxx', 'xxx', 'xxx');mysql_select_db("xxxx") or die(mysql_error()); echo 'Connected successfully';mysql_close($link);

You're connecting to the MySQL server and then immediately closing the connection. That doesn't seem weird to you?You're trying to use variables in your SQL query that you haven't set yet. You can't use $identity if you haven't set $identity to anything. You need to assign the variable to the value from the form and protect it against a SQL injection attack.$identity = mysql_real_escape_string($_POST['identity']);etc, before you create the query. All of the other code you have after the query isn't doing anything.

Link to comment
Share on other sites

someguy thanks for the start to this...yes that seemed weird to me as does a lot of what i'm doing. at one point was posting mysql login password etc on web page which i quickly edited. will try what you suggested and read more about mysql.also would you know where to put this

$str = strtoupper(substr($str, 0, 1)) . strtolower(substr($str, 1));

and also why radio field variables are not editable?

Link to comment
Share on other sites

a lot of questions...here's what i have now (log in xxx's for display here), page not loading:

<?php ini_set("display_errors", 1);error_reporting(E_ALL); $link = mysql_connect('xxxx', 'xxxxx', 'xxxx');mysql_select_db("xxxx") or die(mysql_error()); $identity = mysql_real_escape_string($_POST['identity']);$location = mysql_real_escape_string($_POST['location']);$web = mysql_real_escape_string($_POST['web']);$message = mysql_real_escape_string($_POST['message']);$theme = mysql_real_escape_string($_POST['theme']);$query = "INSERT INTO contacts (identity, location, web, ";$query.= "message) VALUES ";$query.= " ( ' ".$identity."', ' ". $location."', '".$web. " ', ";$query.= '".$message."')";$result = $database->query($query);$str = strtoupper(substr($str, 0, 1)) . strtolower(substr($str, 1)); $destinationVar = {$_POST ['message']} </br>{$_POST ['identity']}{$_POST ['location']}{$_POST ['web']}{$time}?>

and about database, when i "include" external db connection page, my log in info shows on web page. yet i've been reading external page is the most efficient way to connect, so obviously i'm doing something wrong. after opening connection (before variable values/queries i'm guessing) do i close database connection after said queries?

Link to comment
Share on other sites

Archived

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


×
×
  • Create New...