[SOLVED] "if" relatively simple question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eulogy
Forum Newbie
Posts: 14
Joined: Sun Jun 15, 2008 3:07 am

[SOLVED] "if" relatively simple question

Post by eulogy »

EDIT! Solved!

I used this method over here: http://www.codingforums.com/showthread.php?t=146487

------------------------------------

I have an html form that prints into a .csv file using php.

Code: Select all

<?php

$Name = $_POST['Name'];
$Company = $_POST['Company'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];

$cvsData = $Name . "," . $Company . "," . $Email . "," . $Phone ."\n";
$fp = fopen ("signup.csv","a");
if($fp){
fwrite($fp,$cvsData);
fclose($fp);
} 
?>
Everything works, however I want to have a confirmation dialog-box, or for it to load another page after hitting submit.

The following code loads the page but I need to have a proper "if" which is where I'm having a little trouble.

Code: Select all

 print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.php\">";
I tried throwing it inside the if($fp){ but it just loads the confirmation page upon visiting the site.

Any help would be greatly appreciated, I'm sure there's a simple answer out there. All I need to know is how to do "If the data was submitted to the .csv (or even simply if the submit button was pressed?), then open this webpage". If you're feeling generous I'd also like to see how a dialog box would work, but I'm not too good with Javascript either.
Last edited by eulogy on Mon Jun 07, 2010 10:18 am, edited 1 time in total.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: "if" relatively simple question

Post by markusn00b »

What is the purpose of the confirmation dialog? To confirm what? Do you want to confirm that the data is to be entered, or do you want to confirm that the data has entered successfully?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: "if" relatively simple question

Post by Jonah Bron »

Code: Select all

if($fp && isset($_POST['Name'])){
Also, you need to check the validity of your $_POST variables with isset().
eulogy
Forum Newbie
Posts: 14
Joined: Sun Jun 15, 2008 3:07 am

Re: "if" relatively simple question

Post by eulogy »

markusn00b wrote:What is the purpose of the confirmation dialog? To confirm what? Do you want to confirm that the data is to be entered, or do you want to confirm that the data has entered successfully?
To confirm that the data was entered successfully. I don't think I need it to even check if it did or not, I just want the user to know so they don't try to type it again, as of right now it just clears the form but actually submits successfully.

I'm now trying this on my submit button,

[syntax]<input type="submit" name="submit" value="Submit" class="submit-button" onClick="alert('Thank you for signing up!')">[/syntax]

But this does not work either.

I've directly copied the code out of examples that DO work and I can't seem to get it to work for me :(
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: [SOLVED] "if" relatively simple question

Post by Jonah Bron »

By "doesn't work", do you mean the alert box doesn't come up?
Post Reply