Basic Email Form Thingy

Ask about a PHP problem here.
Post Reply
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Basic Email Form Thingy

Post 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 :)
Last edited by ExtremeGaming on Mon Jul 23, 2012 6:59 am, edited 1 time in total.
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: Basic Email Form Thingy

Post by Helx »

I think
value='$_SERVER[REMOTE_ADDR]'
Has to be
value=".$_SERVER[REMOTE_ADDR]."
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Basic Email Form Thingy

Post 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") {
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: Basic Email Form Thingy

Post by ExtremeGaming »

Solved did wrong format for sql :?
Ty for the other help as well totally looked over that
<?php while(!$succeed = try()); ?>
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: Basic Email Form Thingy

Post 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);
?>
<?php while(!$succeed = try()); ?>
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Basic Email Form Thingy

Post 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;
Image
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: Basic Email Form Thingy

Post by ExtremeGaming »

Thank you so much jacek :D 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?
<?php while(!$succeed = try()); ?>
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Basic Email Form Thingy

Post by jacek »

Yeah my bad, mysql_results() always wants the column index (I think :?)
Image
Post Reply