TySkby 41 Junior Poster

These functions seem to be along the line of what you're looking for:

  • strrpos
    Find the position of the last occurrence of a substring in a string
  • substr
    Return part of a string

So, you could use strpos to find where the last . character occurs in the string example.org/some_file.zip, and then use substr to get the part of the string that comes after that character (which would be zip in this case).

Hope that helps!

TySkby 41 Junior Poster

Can you provide which CMS you are using, or any code you are using to process the data submitted in your FCKeditor form? The issue is probably due to something with one (or both) of those two things, especially if your CMS (or one of its plugins) was updated recently.

Have you tried outputting the text immediately after it has been submitted to your form handler? That could help in figuring out whether it actually is FCKeditor that is escaping tags, or if there is some code involved in processing that is doing it.

TySkby 41 Junior Poster

On line 7 of your code, you set

$destination = $_POST['destination']

That is correct, but now you don't need to use the $_POST variable anymore to reference that value. So the problem is in lines 9, 10, 17, and 18 where you are doing $_POST[$destination] because what that really works out to is $_POST[$_POST].

So if you alter your references a bit, you should be good. Try applying this to the lines mentioned above (here I'm using what should go on lines 9 and 10):

if (isset($_POST['dal'])  && isset($_POST['destination'])) {
	$distance = $cities[$destination];
TySkby 41 Junior Poster

No apology necessary! We're all here to help and be helped :)

To elaborate, when I suggested adding comments to your code, I was thinking something a bit more in-line that would elaborate what your code is doing step-by-step. You can use // to comment and document a single line of code in PHP and JavaScript.

Here's an example:

<script>
//Arrays for Image URLs, titles, and captions
var imageUrl = new Array(); 
var imageTitle = new Array();
var imageCaption = new Array();

<?php
//Explain what the $counta and $count variables are, and what this loop does here
for($counta=0; $counta<$count; $counta++)
{
echo "imageTitle[".$counta."]=\"".$imageTitle[$counta]."\";";
echo "imageUrl[".$counta."]=\"".$imageURI[$counta]."\";";
echo "imageCaption[".$counta."]=\"".$imageCaption[$counta]."\";";
}

?>

//Here you can tell readers why you are using jQuery.noConflict()
jQuery.noConflict();

jQuery(document).ready(function() {

//Tell us what var a is and what it will be used to do
var a=0;

//Give some details on this function here
function changepicture() {
jQuery("#slideshowpicture img").attr('src', imageUrl[a]);
jQuery("#slideshowtitle").html(imageTitle[a]);
jQuery("#slideshowarticle").html(imageCaption[a]);
jQuery(".dot"+a).attr('src', "<?php echo $templateuri; ?>/images/home/dotw.jpg");

//What are you checking for here?
if( a == 0) {
a++;
jQuery(".dot<?php echo $count-1; ?>").attr('src', "<?php echo $templateuri; ?>/images/home/dotb.jpg");

}
//What is the alternative?
else if( a == <?php echo $count-1; ?>) {
b = a - 1;
a = 0;
jQuery(".dot"+b).attr('src', "<?php echo $templateuri; ?>/images/home/dotb.jpg");
}
else {
b=a-1;
a++;
jQuery(".dot"+b).attr('src', "<?php echo $templateuri; ?>/images/home/dotb.jpg");
}
}
changepicture();
var slideinterval = setInterval(changepicture, 4000);
});
</script>

Those are just some places where I personally could use some clarification. Commenting is really good practice for allowing others to understand what …

TySkby 41 Junior Poster

Some comments to document your code and a little bit of extra information about your specific question/issue would go a long way. I did read through the code you posted, but it's a bit unclear (to me, at least) as to what you are attempting to do (which is why I suggest adding some comments to your code to help make it more understandable to an outside reader).

I'd love to help with this, but some clarification would definitely be useful. I can obviously only speak for myself, but I think that would help generate a better response from the members here- I know it would for me :)

TySkby 41 Junior Poster

I can see a problem with the structure of your if/else conditions. Currently your innermost code where you calculate $time and $walktime and print your outputs will only be executed if $_POST and $_POST are both set. If I'm understanding what you want to do correctly, the user would select either 'Chicago' or 'Dallas', but not both.

So the first thing you'll need to fix will be changing your code structure to be

if (isset($_POST['dal']) && isset($cities['destination']))
{
  //Put your code for Dallas as the selection here
}
else if (isset($_POST['chi']) && isset($cities['destination']))
{
  //Put your code for Chicago as the selection here
}
else
{
  print "Please select a Starting city and a Destination.";
}

A few other things you'll probably want to check for:
-Are the Starting city and the Destination city the same? You'll probably want to add 'Chicago' => 0 to $cities and 'Dallas' => 0 to $cities2 or else you'll get an error.
-Where are you setting the value for $cities? Do you mean to be checking isset($_POST) instead? If that's the case, you'll want to alter the code where you set $distance to be more like:

$distance = $cities[$_POST['destination']]

...assuming that the value of $_POST is a value in your $cities or $cities2 arrays.

Other than that, the idea of how you will find the distance between to cities looks to be pretty solid. It looks like you just need to tweak the structure a bit for everything to work.

TySkby 41 Junior Poster

If I'm reading this correctly, you have been able to split the string variable $str into an array. Assuming you have named the new array $str_array, you could do something like this:

-Iterate through the array and for each value in $str_array, use strlen() to count the number of characters in the current value
-Compare it to the existing longest value (we'll call it $longest). If it is larger, check if it's in the $area array.
-If it is, replace the value of $longest to be the value of the current iteration.

With this method, you'd come out with something similar to the following code:

//Set the $longest variable to be an empty string for now
$longest = '';

//Iterate through $str_array with the current iteration set to $value
foreach($str_array as $value)
{
	//Get the length of $value
	$length_value = strlen($value);
	//Get the length of $longest
	$length_longest = strlen($longest);
	
	//Compare the lengths
	if ($length_value > $length_longest)
	{
		//$value has more characters than $longest, so check if it is in $area
		if (in_array($value, $area))
		{
			//$value is a value of $area array, so make it the new value for $longest
			$longest = $value;
		}
	}
}

At the end of this loop, $longest will be equal to the longest word that exists in both $str_array and $area arrays.

Obviously this could be shortened down to be more efficient and such (and I would encourage you to do that), but I figured it would help more people …

asif49 commented: Offered great help! +3
TySkby 41 Junior Poster

Not usually on a properly-configured server with SMTP.

In the past, I have found that it sometimes works on a local machine if you configure the SMTP line in php.ini to point to the SMTP server of your ISP.

Sometimes it works, sometimes it doesn't- depends on your ISP and what kinds of restrictions they have on their SMTP server (usually whether they require SMTP authentication).

So if you have, say, Comcast as your ISP and their SMTP server address is "smtp.comcast.net" on port 25, you could try changing your php.ini file so that it reads like this:

SMTP = smtp.comcast.net
smtp_port = 25

Feel free to try that out, but don't be surprised if you don't have any luck. Also, I should note that the above php.ini configuration is for Windows. Unix servers rely on the "sendmail_path" line for that configuration. But that's only if you have sendmail set up on your server.

Oh, and if you do try that out, remember to save a backup of php.ini first. You probably know that already, but I feel obligated to say it, knowing the hell I've put myself through by messing with php.ini without a backup.

TySkby 41 Junior Poster

I've set up a home server (as far as I know it's called that). I'm using xampp and use "localhost/" to access the page on google chrome.

Are you saying that if this was hosted on the web then this problem would dissapear?

Most likely. Every time I've encountered this problem, it is resolved as soon as it is hosted on a server with a SMTP.

TySkby 41 Junior Poster

Found it!

I know you've already made some progress on this, but if you want to take a look, either for ideas or to use part of the code, here's the link: http://github.com/TySkby/WikiFB

If you have any questions, I'm happy to help. Good luck!

TySkby 41 Junior Poster

*Edit- I understand now after thoroughly reading page 2.

I'm going to do some hunting- I wrote a PHP application that does almost this exact same thing. When I find it, I'll put a link to the source files if you'd like.

TySkby 41 Junior Poster

Don't replace the single quote with doubles, in line 20, the issue is with the double quotes in border="0". Those should be changed to single quotes, as seen here:

<?php


  $groupname = $_REQUEST['groupname'] ;
  $info = $_REQUEST['info'] ;
  $size = $_REQUEST['size'] ;
  $special = $_REQUEST['special'] ;
  $firstname =$_REQUEST['firstname'] ;
  $lastname = $_REQUEST['lastname'] ;
  $address1 = $_REQUEST['address1'] ;
  $address2 = $_REQUEST['address2'] ;
  $city = $_REQUEST['city'] ;
  $prov = $_REQUEST['prov'] ;
  $email = $_REQUEST['email'] ;
  $phone1 = $_REQUEST['phone1'] ;
  $phone2 = $_REQUEST['phone2'] ;
  $phone3 = $_REQUEST['phone3'] ;
  $website = $_REQUEST['website'] ;
  
$message = "<table width='600px' border='0' cellspacing='3' cellpadding='3'>
  <tr>
    <td><strong>Groupname :</strong></td>
    <td>$groupname</td>
  </tr>
  <tr>
    <td><strong>Info :</strong></td>
    <td>$info</td>
  </tr>
  <tr>
    <td><strong>Size :</strong></td>
    <td>$size</td>
  </tr>
  <tr>
    <td><strong>Special :</strong></td>
    <td>$special</td>
  </tr>
  <tr>
    <td><strong>Firstname :</strong></td>
    <td>$firstname</td>
  </tr>
  <tr>
    <td><strong>Lastname :</strong></td>
    <td>$lastname</td>
  </tr>
  <tr>
    <td><strong>Address1 :</strong></td>
    <td>$address1</td>
  </tr>
  <tr>
    <td><strong>Address2 :</strong></td>
    <td>$address2</td>
  </tr>
  <tr>
    <td><strong>City :</strong></td>
    <td>$city</td>
  </tr>
  <tr>
    <td><strong>Prov :</strong></td>
    <td>$prov</td>
  </tr>
  <tr>
    <td><strong>Email :</strong></td>
    <td>$email</td>
  </tr>
  <tr>
    <td><strong>Phone1 :</strong></td>
    <td>$phone1</td>
  </tr>
  <tr>
    <td><strong>Phone2 :</strong></td>
    <td>$phone2</td>
  </tr>
  <tr>
    <td><strong>Phone3 :</strong></td>
    <td>$phone3</td>
  </tr>
  <tr>
    <td><strong>Website :</strong></td>
    <td>$website</td>
  </tr>
</table>" ;
  $headers  = "From: ".$email."\r\n";
  $headers .= 'MIME-Version: 1.0' . "\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	
  mail( "user@mailserver.com", "Vendor Application",
    $message, $headers );
  header( "Location: http://www.thewebsiteimlinkingto.ca/thanks!.html" );
  
  
?>

Hope this helps! :)

TySkby 41 Junior Poster

You could make an object in JavaScript for each node you need and define whether it's an absolute parent (has no ancestors), a parent and a child, or an absolute chile (has no descendents). Then have a method that sets an array to define the arrays in parents, and when you instantiate it, give it a reference to the instantiation's DOM selector.

After you do that, set up a script in jQuery (what I would do at least) that goes and decides what type of node everything is and calls the methods that instantiate the objects based on where they are your ancestral order.

TySkby 41 Junior Poster

Sorry that this is not completely specific to your problem, but since you said "Unfortunately, it's the regex I've been struggling with. I trying to do this
'a_key'(whitespace)=>(whitespace)'(content_to_replace)' for it, but I'm going around in circles."

Might I suggest something like Regex Buddy? Regex always hurts my head, and I find that the tool is something that reduces that from the level of a nasty migraine to a run-of-the-mill headache.

Only problem is that it's not free. So you may want to check out this thread for some alternatives.

diafol commented: Good links - cheers +13
TySkby 41 Junior Poster

Ok, as I thought. You're accessing your stuff through the browser as a local file and not through the server.

Remeber that a browser can only read HTML, JavaScript, and other client-side code. PHP is server-side, so you need to access it through your server (on 'localhost').

The solution to your issue depends on your Xampp installation, so if you installed Xampp to the location 'C:\Xampp' (which is default), you should go to 'C:\Xampp\htdocs' and in there, make a folder (I'll call it 'bureaublad' in this example) and paste your 'index.php' and 'login.php' files into that folder.

Then (as long as Xampp and Apache are running), you should be able to access you code with a URL like 'http://localhost/bureaublad/index.php'.


Currently, since you're accessing the files directly in your browser instead of letting them be processed through the server, the server isn't being asked to do anything and you can't use PHP as a result (because PHP needs to be processed through the server- it can't be done by the browser alone).

TySkby 41 Junior Poster

Quick question- are you accessing these pages with 'localhost' in your URL? The reason I ask is because you said you were getting the full code in Chrome, which shouldn't happen if you're accessing the pages through your Xampp server.

TySkby 41 Junior Poster

I think you need something like this:

$extract = mysql_query("select * from tbl_competition WHERE fld_closed='N'");

if (mysql_num_rows($extract) > 0) {
    while ($row = mysql_fetch_assoc($extract)) {
        //Do your thing with the data
    }
} else { //No rows from MySQL
    //Put your redirect stuff here
}

And yeah, where are your {} and all the code for what you want to happen during the while() loop?

TySkby 41 Junior Poster

That have something to do with installation than PHP/MySQL. Just uninstall the whole thing and reinstall it!

+1 for this idea.

I would hazard to guess that you may have 2 MySQL installations going, since WAMP usually includes that in the installation, but much easier to just get a fresh start, I would think.

TySkby 41 Junior Poster

NetBeans, definitely.

Others may say Eclipse or Aptana, but I personally prefer NetBeans for PHP. Netbeans also supports Zend, CodeIgniter, Symfony, as well as others via plugins.

TySkby 41 Junior Poster

I thought you were using phpMyAdmin, not Administrator for MySQL?

Your thumbnails looks like they're showing an error for Administrator for MySQL, which probably doesn't affect your MySQL installation.

Which system are you trying to use? Or is the problem that you can't access MySQL at all?

TySkby 41 Junior Poster

I'm a bit lost on this one, I'll admit... It's hard for me to check for errors when it's your environment (not your code) that has the errors.

That being said, what have you set CHMOD 777 to? You say it's 777 for all users- but where are those permissions applied (ie, the directory, the files, etc?).

Check that your 'menuleft.html' and 'menuright.html' files are also set with these permissions (because if it can't open the stream, I wonder if there are read permissions set to those files). Also, make sure the PHP file itself is executable and writable.

I don't know what method you are using to set your permissions, but a lot of people make the error of CHMODing the directory that they're working in, and often fail to CHMOD the individual files within that directory as well.

As far as I can see, your code is good for what you're trying to do, so you probably don't need to worry about that. Also, have you contacted you host (Godaddy?) about the issue?

TySkby 41 Junior Poster

What do you mean by permission errors? Are you getting an error from PHP, or are you getting your die("can't open file"); as an error?

TySkby 41 Junior Poster

Can you please post the PHP and HTML code again so we can see the most recent stuff you've been working with?

TySkby 41 Junior Poster

This may be a long shot, but TRY (you can always go back and change it if it doesn't work) renaming "php5.ini" to simply "php.ini". I think that "php5.ini" only works with php files with the ".php5" extension.

Not sure if I made that all up, but maybe it's worth a try.

If there's no change, there might be other settings you need to specify in "php5.ini", such as allowing file_put_contents() or fwrite().

TySkby 41 Junior Poster

Well I've made the suggested changes, and it still won't work.

Does it give you an error message, or just do nothing?

For your second question- to check if PHP can write to a file, save this script as a .php file and then try accessing it from your browser (make sure it's in the same directory as "menuleft.html"):

<?php
$file_to_check = "menuleft.html";
if(is_writable($file_to_check)){
    print("Yes");
} else {
    print("No");
}
?>

If it says "Yes", then you are able to write to menuleft.html and something is still wrong with your code. If you get a "No" then PHP doesn't have permission to write to that file.

As for your last question, there's always more than one way to do things. I think there were some suggestions earlier in this thread.

TySkby 41 Junior Poster

You need to escape your quotes or change them to single quotes on line 3:

<?php
$menu_text = $_POST['updateleft'];
$html_begin = "<html><body><table bgcolor=\"black\"><td><tr><font size=5 color=\"yellow\">";
$html_end = "</font></tr></td></table></body></table></html>";
$final_page = $html_begin.$menu_text.$html_end;

$file_name = 'menuleft.html';

file_put_contents($final_page,$file_name);
header("location:http://www.timbertheband.com/menu/menudadmin.html");
?>

Personally, I like single quotes, but if you want to keep them as double quotes, you need to add a \ before them, or else PHP will think you are ending the string.

TySkby 41 Junior Poster

Glad to be of help. I PMed you with my e-mail if you want to send those files over.

TySkby 41 Junior Poster

PHP needs write permissions to create a new file and modify permissions to change a file's content. Do you know if your server has these privileges enabled for your working directory?

TySkby 41 Junior Poster

Simple test to see if your server supports PHP:

Make a file called "info.php" that contains this:

<?php
phpinfo();
?>

Upload to your server and point your browser to it and see what happens.

TySkby 41 Junior Poster
<html>
<body>
<table>
<tr>
<td>
Menu left:
<form action="menuleft.php" method="post">
<textarea name="updateleft" cols="50" rows="4" "></textarea><br>
<input type='submit' value='submit' /><br />
</form>
Menu left preview<br>
<iframe src="menuleft.html"></iframe><br>
</td>
<td>

Menu right:
<form action="menuright.php" method="post">
<textarea name="updateright" cols="50" rows="4"></textarea><br>
<input type='submit' value='submit' /><br />
</form>
Menu right preview<br>
<iframe src="menuright.html"></iframe><br>
</td>
</body>
</html>

This is the source code for the page you provided the link for. I'm including it because it contains values I'm going to use here:

The source code for "menuleft.php" should look like this:

<?php

//Get text area value when form is submitted
$menu_text = $_POST['updateleft'];

//Update "menuleft.html"
$filename = 'menuleft.html';
file_put_contents($menu_text,$filename);

//Redirect back to your original page
header("location:http://comp.uark.edu/~cdavies/menu/menuadmin.html");

"menuright.php":

//Get text area value when form is submitted
$menu_text = $_POST['updateright'];

//Update "menuright.html"
$filename = 'menuright.html';
file_put_contents($menu_text,$filename);

//Redirect back to your original page
header("location:http://comp.uark.edu/~cdavies/menu/menuadmin.html");

That should do what you need it to. It will send you to your "menuleft.php" or "menuright.php", but will automatically redirect you once everything has been completed (shouldn't take more than a moment). You do need PHP to have writeable permissions to do this, but that's up to your server's configuration.

To make it so that you never leave the page at all, you would need to change "menuadmin.html" to "menuadmin.php". The 'action' for both forms needs to point to "menuadmin.php", and your textareas could have the same name (the alternative would be using a conditional if() statement).

Something like this would work (this example assumes both textareas …

TySkby 41 Junior Poster

file_put_contents() will create a file if one does not exist. Currently, if you send your form to the code in your last post, php will either create or overwrite a file called "finalpage.html" and fill it with the data from your form. So if you fill your form's text area (named 'formdata') with the text "Spaghetti and Meatballs", finalpage.html will output:

Spaghetti and Meatballs

If you look at the contents of "finalpage.html" though (view the source code), you will see that is no HTML tags- the only text contained in "finalpage.html" will be whatever you enter into the 'formdata' text area. So this will work if you're only interested in plain text. Otherwise you will need to put HTML in the 'formdata' text area manually (which could lead to submission errors if you're not careful) or else use your PHP code to concatenate HTML formatting at the beginning and end of $formdatavariable.

For example, you could do:

<?php
$formdatavariable = $_POST['formdata'];

$html_begin = "<html><head><title>Today's Menu</title></head><body><u><i>";
$html_end = "</i></u></body></html>";
$output = $html_begin.$formdatavariable.$html_end;

$finalpagevariable = "finalpage.html";
file_put_contents ( $finalpagevariable , $output );
?>

So this time if you entered "Spaghetti and Meatballs" into your form and press submit, the source code for "finalpage.html" will be

<html><title>Today's Menu</title><body><u><i>Spaghetti and Meatballs</u></i></body></html>

And if you view it in a browser, you will get a page with the title "Today's Menu" and the text:

Spaghetti and Meatballs

(Note that the text is underlined and italicized because of the <u> and <i> tags I included in …

TySkby 41 Junior Poster

Yeah, if your text area has a name attribute as "formdata", then you store that as $formdatavariable as you are showing in your last post.

I see two problems though:

1. $pagevariable needs to be a string, so you need quotes:

$pagevariable = "finalpage.html";

And you're using the parameter variables backwards. You need that line to look like this:

int file_put_contents($pagevariable, $formdatavariable);

The correct syntaxt for file_put_contents can be found here: http://php.net/manual/en/function.file-put-contents.php

TySkby 41 Junior Poster

I still am missing some of your code- the file that defines your writefield() function is missing (or you didn't include the part of index.php that defines that function), so I can't test this at all, but here are some issues you need to correct first:

On line 32 of index.php, you have this:

<td class="style1"><input type="checkbox" name="I am the Head of the Department.">

Change that to this:

<td class="style1"><input type="checkbox" name="dept_head" value="1">

Changing the name makes it easier to work with, and it should have a value of 1 so we can see if it was checked.

I'm assuming the way this works (again, I can't see the form as it displays in a browser) is that the users fills the form, and when they submit, an e-mail gets sent to both the user and the head of a department. BUT, if a department head is filling the form, they check the above-mentioned checkbox and the e-mail only goes to them. If I have this wrong, let me know, but if I'm correct...

Starting at line 227 in send.php, we currently have this:

$headers = "";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "Reply-to: <" . $_POST["email"] . ">\n";
$headers .= "From: " . addslashes($_POST["name"]) . " <" . $_POST["email"] . ">\n";
$headers .= "CC: " . addslashes($_POST["name"]) . " <" . $_POST["email"] . ">\n";
$headers .= "MIME-Version: 1.0\n";

// if (mail("wood.jac@husky.neu.edu", "Supply Form", $message, $headers))
if (mail($to[$_POST["department"]], "You have a new order", $message, $headers))
{ …
TySkby 41 Junior Poster

You won't be able to keep your changes if all you're doing is having PHP process a form and then display the results because you're not saving it anywhere.

Two solutions:

1. Have the PHP that processes your form and then writes the output to a file that you can access. When you update the form, your PHP should overwrite the existing file with the new form data.
What you'd need is 3 (minimum) files:
-form.html Displays your form and points to 'update.php'
-update.php Processes the form and writes the values to 'menu.html'
-menu.html Displays the newest menu

2. Use a mysql database. You would need these files:
-form.html Same as above
-update.php Processes the form and updates a table in your mysql database with the data collected from 'form.html'
-menu.php Selects the proper fields from your mysql table, assigns them to a variable, and then displays the newest menu by including the variables within the same basic HTML you'd use for 'menu.html'.

Each has its own advantage, but will give you pretty much the same result. If you use mysql, you can store and retrieve the information in whatever way you need, but if it's just a basic menu that you're after, writing the form's information to an HTML page will do that too. If you're planning on expanding this, I'd go with mysql, otherwise, go with the first option.

Good luck, let me know if you …

TySkby 41 Junior Poster

I'm not sure I'm completely understanding the way your processing is supposed to work. You should be able to include a statement that evaluates whether a department head's box has been checked, but I don't know the names of your form values, so would you mind posting the code for the corresponding form as well?

PS- Remember to use [code] tags : )

TySkby 41 Junior Poster

Glad to help- good luck!

TySkby 41 Junior Poster

Everything looks good- you just forgot to add the tag to make the image a link. The only change I made was in line 6:

<?php 
$img_array = glob("images/Coupons/*.{jpg}",GLOB_BRACE); 
//Pick a random image from the array 
$img = array_rand($img_array); 
//Display the image on the page 
echo '<a href="whatever.php">'.'<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" /></a>';
?>
TySkby 41 Junior Poster

Yup :)

TySkby 41 Junior Poster

Didn't see this before I posted my solution:

Maybe a better way to do this is have one interest field and have your checkboxes with the values; 1,2,4 (bit). So any combination will give a unique value total: 1,2,3,4,5,6,7. e.g. 6 = 2 + 4 (the second and third checkbox).

You can check the presence of a value in the total with a bitwise operator (&):

$a & $b (will give 0 if false or the common bit if true)

2 & 3 = 2 (2 is the common bit)
1 & 3 = 1 (1 is the common bit)
1 & 6 = 0 (no common bits)

Perhaps I haven't explained this very well, and it's possible that it's overcomplicating the solution.

The reason I mentioned this is that if you do this:

<td class="checkbox"><input type="checkbox" name="newMusic[]" value="1"/>To find new and exiting music</td>
<td class="checkbox"><input type="checkbox" name="newMusic[]" value="2"/>Shopping for music related products</td>
<td class="checkbox"><input type="checkbox" name="newMusic[]" value="4"/>Other</td>

SO for processing:

$total = array_sum($_POST['newMusic']);

Now you don't need to check each individual checkbox.

You're all welcome to stomp on my idea. Just a thought.

I agree that it would work, but it looks a bit complex for a trivial checkbox form. Plus the math would have to change if the form was ever updated to include more checkbox options.

TySkby 41 Junior Poster

Okay, so if I am understanding correctly, you have two tables- one that stores things like "To find new and exiting music", "Shopping for music related products", etc. each with a corresponding ID key? And the second table is the user information and includes three fields for holding the ID keys that correspond to the first table?

If that's correct, then what you need is for your checkboxes to be enclosed within <form></form> tags with proper attributes, like this:

[B]<form method='post' action='process.php' name='myform'>[/B]
<tr>
<td class="typeMusic">What are your interests:</td>
<td class="checkbox"><input type="checkbox" name="new" value="1"/>To find new and exiting music</td>
<td class="checkbox"><input type="checkbox" name="shop" value="2"/>Shopping for music related products</td>
<td class="checkbox"><input type="checkbox" name="other" value="3"/>Other</td>
</tr>
[B]</form>[/B]

where process.php is the name of the PHP file that the form will send its data to and myform is whatever name attribute the form should have (it usually doesn't matter).


Process.php should look something like this:

<?php

//Retrieve your form data and store it in corresponding variables
$chk_new = $_POST['new'];  //If checked, will equal 1
$chk_shop = $_POST['shop']; //If checked, will equal 2
$chk_other = $_POST['other']; //If checked, will equal 3

//Decide which ones were checked and then store them to DB
if ($chk_new == 1) {
     //...MySQL query here for what to do if the box was checked
}
if ($chk_shop == 2) {
     //...MySQL query here for what to do if the box was checked
}
if ($chk_other == 3) {
     //...MySQL query here for what to do …
TySkby 41 Junior Poster

All of your checkboxes have the same name attribute, which will cause problems when you're trying to determine what was checked. Try giving each checkbox a unique name, even if it is something like "cb1", "cb2", etc. And give each of them a value of "1".

Then when you process the form, you can assign each checkbox to a variable, and if the variable is equal to one, then insert that checkbox's reason into your database as a string.

Can we see some PHP code in order to see what issue PHP is having?

TySkby 41 Junior Poster

Hopefully I'm understanding you right, but it seems that a simple solution would be to have your form processing script check whether the box was checked and deal with it through an if then statement.

So if the checkbox in your form is called "department_head_checkbox" and it has a checked value of 1...

$deptheadbox = $_POST['department_head_checkbox'];
if ($deptheadbox == '1'){
     ...//Whatever needs to happen if the box was checked
} else {
     ...//Whatever needs to happen if the box was not checked
}

Put that wherever your processing script decides what e-mail addresses are used.

Sort of rudimentary, but if you need more help, just post your questions (and including some code always helps).

-Ty

TySkby 41 Junior Poster

One thing I noticed is that you said the user has 3 tries to log in. A problem with that you aren't including a time limit for those tries- what if a user fails 3 tries over a period of 2 weeks? You don't want to lock them out for that!

What I would do is have two cookies created on the first login attempt and use them to track how many times they have tried to log in. The reason you need two cookies is that one of them must be updated each time a login is attempted, and the other needs to store the original expiration time of the cookie that gets update.

If your cookies expire after, say, 15 minutes, then you can use that to allow a maximum of 3 tries for each 15 minute period. Each time the user fails to provide the correct login credentials, update the cookie's value to reflect the number of failed attempts. If the cookie has a value of greater than 3, then save the timestamp to your DB and don't allow any more attempts for 60 minutes.

I modified your original code to do this. Check it out- it may be what you're looking for:

<?php
    session_start();
    include("config.php");

    //Check if the user has already tried to login
    //If they have, set the variable $auth_tries to the value of the cookie and get the expire time
    if (isset($_COOKIE['time_limit'])) {
        $num_tries = $_COOKIE['auth_attempts'];
        $expire_time = $_COOKIE['time_limit'];
    } else …