Improve company productivity with a Business Account.Sign Up

x
?
Solved

I need any user to submit a form and dont show it to anyone else after being submitted

Posted on 2006-10-25
5
Medium Priority
?
192 Views
Last Modified: 2012-05-05
I have a page that shows up as an error page on my website  if the db cant connect.

I added the following to the page. This provides a form to a user to alert the admin that the site is down (works with sms) I will place a notice like" you are the first to see this erorror please advise the site admin"  

Then once theyve submitted it to me I dont want it to show up to anyone else.

I was thinking on the form submit to set a variable to 1 and later check the variable if its 1 I will not show the form code otherwise I will.

I have no clue as to how to make this work any thoughts Do I simply

define $count as global

then set
 
$count = 1; in the code that transmits the sms? Will this hold that variable no matter how many times the page is loaded?

Thanks



<form method="POST" action="<?php echo $PHP_SELF; ?>">
Number:<br />
<input type="text" name="number" maxlength="10" class="inputbox"><br />
(Example: 8001234567; US Only)<br /><br />
Subject:<br />
<input type="text" name="subject" maxlength="20" class="inputbox"><br />
(Max 20 Characters)<br /><br />
Message:<br />
<textarea name="message" rows="10" cols="15" class="inputbox"></textarea><br />
(Between 3 - 120 Characters)<br /><br />
<input type="submit" name="do" value="Send" class="button">
</form>
0
Comment
Question by:Roba122
  • 2
3 Comments
 
LVL 4

Expert Comment

by:anilande
ID: 17809800
if u want to retain a value after submitting the form use
$_SESSION['hit']=1;

this value will be retained in the server/session until the session is not destroyed.

to know about details about sessions visit this link

http://in.php.net/session
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17810639
you could write your data to a text file on the server, so that the solution is independant of any sessions for example.  You should make sure that you have the proper write/execute permissions on the server.  If you prefer, instead of posting form data to $_SERVER[PHP_SELF], you could post form data to a file in a section of your server that is not accessable from the web, this will remove any dangers of setting write permissions to web accessible folders.

in your section for handling the sms sending, you need to add the following code prior to the sms sending, which will write a small text file in the same directory as the script.  By writing the data in a php format, we can use it later if you want to make your script more advanced (reset button?)

<?php
$your_data = "$smssent=1";
// Open the file and erase the contents if any
$fp = fopen("smssent.php", "w");
// Write the data to the file
fwrite($fp, $your_data);
// Close the file
fclose($fp);
?>

You then need to use the following code on your main error page, which will decide whether or not to show your form, based on whether or not the file exists.  If you want to add reset scripts etc, you can always check the data that is held in the "$smssent" variable instead.

<?php
$filename='smssent.php'

if (file_exists($filename)) {
   //Nothing needs to be done, we don't want to show the form
}
else {
echo "<form method='POST' action='$PHP_SELF'>
Number:<br />
<input type='text' name='number' maxlength='10' class='inputbox'><br />
(Example: 8001234567; US Only)<br /><br />
Subject:<br />
<input type='text' name='subject' maxlength='20' class='inputbox'><br />
(Max 20 Characters)<br /><br />
Message:<br />
<textarea name='message' rows='10' cols='15' class='inputbox'></textarea><br />
(Between 3 - 120 Characters)<br /><br />
<input type='submit' name='do' value='Send' class='button'>
</form>"
}
?>
0
 
LVL 16

Accepted Solution

by:
ellandrd earned 2000 total points
ID: 17810715
There was an error in my last post, please find proper code below!!


you could write your data to a text file on the server, so that the solution is independant of any sessions for example.  You should make sure that you have the proper write/execute permissions on the server.  If you prefer, instead of posting form data to $_SERVER[PHP_SELF], you could post form data to a file in a section of your server that is not accessable from the web, this will remove any dangers of setting write permissions to web accessible folders.

in your section for handling the sms sending, you need to add the following code prior to the sms sending, which will write a small text file in the same directory as the script.  By writing the data in a php format, we can use it later if you want to make your script more advanced (reset button?)

<?php
$your_data = "$smssent=1";
// Open the file and erase the contents if any
$fp = fopen("smssent.php", "w");
// Write the data to the file
fwrite($fp, $your_data);
// Close the file
fclose($fp);
?>

You then need to use the following code on your main error page, which will decide whether or not to show your form, based on whether or not the file exists.  If you want to add reset scripts etc, you can always check the data that is held in the "$smssent" variable instead.

<?php
$filename='smssent.php';

if (file_exists($filename)) {
   //Nothing needs to be done, we don't want to show the form
}
else {
echo "<form method='POST' action='$PHP_SELF'>
Number:<br />
<input type='text' name='number' maxlength='10' class='inputbox'><br />
(Example: 8001234567; US Only)<br /><br />
Subject:<br />
<input type='text' name='subject' maxlength='20' class='inputbox'><br />
(Max 20 Characters)<br /><br />
Message:<br />
<textarea name='message' rows='10' cols='15' class='inputbox'></textarea><br />
(Between 3 - 120 Characters)<br /><br />
<input type='submit' name='do' value='Send' class='button'>
</form>";
}
?>
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question