Page 1 of 1
Basic Email Form Thingy
Posted: Mon Jul 23, 2012 6:38 am
by ExtremeGaming
So...first off title says it all. No validation as of yet but cannot seem to get messages to display when sql condition is met seen on lines 9 and 17. Wasn't really sure whether to post in php or sql...
<?php
session_start();
if (isset($_REQUEST['email'])) {
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("123", $subject, $message, "From:" . $email); echo "Testing successful";
}
else if($_SESSION[adform_access]=="0") {
echo "<form method='post' action='' name='Form1'>
From: <input name='email' type='text' /><br /> <input type='hidden' name='subject' value='$_SERVER[REMOTE_ADDR]' /><br />
<p>Message:</p> <textarea name='message' rows='15' cols='40'></textarea>
<p> </p>
<input type='submit' />
</form>";
}
else if($_SESSION[adform_access]=="1") {
echo "Testing Restricted";
}
else {
echo "Testing error";
}
?>
It seems to always display the form even when the session variable is changed.
sql is simple adform_access 0 = success 1 = restricted any other is an error. Any help would be greatly appreciated
Re: Basic Email Form Thingy
Posted: Mon Jul 23, 2012 6:41 am
by Helx
I think
value='$_SERVER[REMOTE_ADDR]'
Has to be
value=".$_SERVER[REMOTE_ADDR]."
Re: Basic Email Form Thingy
Posted: Mon Jul 23, 2012 4:27 pm
by Temor
abcedea wrote:
Has to be
value=".$_SERVER[REMOTE_ADDR]."
nope. single quotes is the correct syntax. I would however use curly brackets. Like this:
value='{$_SERVER[REMOTE_ADDR]}'
This line is missing some single quotes.
else if($_SESSION[adform_access]=="1") {
else if($_SESSION['adform_access']=="1") {
Re: Basic Email Form Thingy
Posted: Mon Jul 23, 2012 6:09 pm
by ExtremeGaming
Solved did wrong format for sql
Ty for the other help as well totally looked over that
Re: Basic Email Form Thingy
Posted: Mon Jul 23, 2012 10:11 pm
by ExtremeGaming
ok one more problem. Since then I added an option to add a on/off/maintenance option to the form. The sql is updating right but if you are to echo the variable it is always set to on? Never seen this happen here is the new code. If you are to execute the code it says there is an error with the form
The Access is set on Maintenance
<?php
require ('Advertise/Home/Form.php');
if (isset($_REQUEST['email']))
{
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("123", $subject,
$message, "From:" . $email);
echo "Thank you for your service. The requirements for advertising your website will be emailed to "$email" when your email is read and processed. Please <a href='/'>click here</a> to continue.";
}
else if($result == "On")
{
echo "<form method='post' action='' onsubmit='return Form1_Validator(this)' name='Form1'>
From: <input name='email' type='text' readonly='readonly' value='$_SESSION[email]' length='10' /><br />
<input type='hidden' name='subject' value='Home Page Advertisement' type='text'/><br />
<p>Message:</p>
<textarea name='message' rows='15' cols='40'></textarea><br />
<p>*Note: Inappropriate/ Off topic messages will result in a ban.</p>
<p> </p>
<input type='submit' />
</form></font>";
}
else if($result == "Off") {
echo "The advertise form has been taken down temporarily.";
}
else if($result == "Maintenance") {
echo "The advertise form is currently under maintenance. Please check back later.";
}
else {
echo "There is an error with the advertise form. Please contact support.";
}
?>
And Form.php
<?php
require ('config.php');
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());
$query = "SELECT Access FROM $advertise_table_name WHERE id = '1'";
$result = mysql_query($query);
?>
Re: Basic Email Form Thingy
Posted: Tue Jul 24, 2012 12:57 am
by jacek
mysql_query() just performs the query, it does not fetch the result you need to use either mysql_fetch_assoc() or mysql_result(). something like this
$result = mysql_query($query);
$mode = mysql_result($result);
You could then do your checks on $mode;
Re: Basic Email Form Thingy
Posted: Tue Jul 24, 2012 2:14 am
by ExtremeGaming
Thank you so much jacek
sorry very new to php. Did get an error saying it expects 2 parameters but fixed it by doing
$mode = mysql_result($result, 0);
that ok?
Re: Basic Email Form Thingy
Posted: Wed Jul 25, 2012 11:18 pm
by jacek
Yeah my bad, mysql_results() always wants the column index (I think
)