Jump to content

$op = $_POST['op'];


cudsuk

Recommended Posts

For those not aware , i am just starting out and trying to learn to solve errors by getting hints or tips , not actually looking for you to do it fo rme as such or i will never learn but i appreciate the help

 

I have a old script that is about 7 years out of date i need to update and it is throwing up a error of

 

Notice: Undefined index: op in C:\xampp\htdocs\videos\contact.php on line 8

 

Notice: Undefined variable: status in C:\xampp\htdocs\videos\contact.php on line 74

 

The code is

 

<?php


// Change these two variables to meet your needs.


$myemail = '[email protected]';
$subject = 'my site';


$op = $_POST['op'];


if($op == 'contact')
{
$name = stripslashes($_POST[name]);
$email = stripslashes($_POST[email]);
$text = stripslashes($_POST[text]);
$referer = $_POST[referer];
$remote_host = $_SERVER[REMOTE_ADDR];
$server = $_SERVER[sERVER_NAME];
$browser = $_SERVER[HTTP_USER_AGENT];


if(!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$",$email))
{
$status = "We're sorry, but you've entered an incorrect email address.<br>";
}
if(!$name)
{
$status .= "Please enter your name.<br>";
}
if(!$text)
{
$status .= "Please enter a message.<br>";
}


if(!$status)
{
$header = "From: $emailrnReply-To: $emailrn";


$message = "
Name: $name
Referer: $referer
Site: $server
Remote Host: $remote_host
Remote Browser: $browser


$text
";


if(mail($myemail, $subject, $message, $header))
{
$status = "Thank you for your Feedback!!<br><br>";
}
else
{
$status = "There was a problem sending your feedback, please try again later.<br><br>";
}


}
else
{
$status .= "<br>Please press <u>back</u> on your browser to resubmit.<br><br>";
}
} 


// Now check the referer page and ensure it's a proper URL


$referer = $_SERVER['HTTP_REFERER'];


if(!preg_match('#^http\:\/\/[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i', $referer))
{
unset($referer);
}


?>


<?php print $status; ?>


<form method="post" action="<?php print $_SELF; ?>">
<input type="hidden" name="op" value="contact">
<input type="hidden" name="referer" value="<?php print $referer; ?>">
Name<br><input name="name" size="35" value=""><br>
E-mail address<br><input name="email" size="35" value=""><br>
<br>Message<br><textarea name="text" cols="50" rows="10"></textarea><br><br>
<input type="submit" value="Send message!">
</form>

 

Line 8 is

[/b]
$op = $_POST['op'];

 

line 74

 

<?php print $status; ?>

 

Looking around and reading posts here , op is not used ?

 

it is

if ($_POST[op] ?

 

or use isset ?

 

Can someone please explain how to change it so it works as i am certainly not a coder , but am i on the right track , i believe it is something about an array not being set first or something ?

 

Thanks for the help i appreciate it , i have managed to solve one other problem already by a kind member saying use so and so , but not saying where or how lmao , if i don't do trial and error i am never going to learn , so thanks if you can help out :)

 

Edit

 

I think i have spotted another error in this , isn't if(!eregi suppose to be if(!preg_match ?

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/
Share on other sites

In this code:

$op = $_POST['op'];

You are trying to assing the element of the $_POST array that has a key of 'op'. But this key doesn't exist, so you are getting an error.

 

Before trying to use this key, you need to check if it exists:

if(isset($_POST['op'])
{
 $op = $_POST['op'];

 

As a side note, I couldn't help wonder if this thread was somehow related to transexuals :)

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1403873
Share on other sites

lmao , point taken as explained is very old code , at least i was on the right tracks as such , i just needed to see how it looked ,

 

Ha ha i guess above would only apply in china to lady boys lol :)

 

Damn now getting

 

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\videos\contact.php on line 9

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1403876
Share on other sites

HI cpd , yes i did copy and paste but from notepad++ the <br><br>

 

would not be in my code just here as it does that when pop it in code tags

 

Ok i am led to believe as a } bracket or a semi colon is missing , but maybe i am way of the mark , i am a total novice , so a easy mistake for you to spot but over my head , i will do as you suggest and look at the parenthesis and trial and error it , thanks :)

 

EDIT

ok is due to having a

if($op == 'contact')
{

 

{ but not a } before it yes ? , so i have to discover where to place it to work as one would open the command as such and the other close it ?

 

Sorry for being a total noob , but got to start somewhere

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1403917
Share on other sites

Won't let me edit the line above but <br> is there as i believe is uded in html as a line break durrrrrrr , if i put a ) after

if(isset($_POST['op']))

 

it goes to end but since no close as such i get this , i am struggling a bit , please help

 

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\videos\contact.php on line 87

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1403921
Share on other sites

I aploigise for posting again but it won't let me make a edit after i have done so already

 

Ok , after some googling i discover using isset checks if a variable is set , i changed my code with the help of haku's post

 

So mine is now

if (isset($_GET['op']) && $_GET["op"] == "contact")

 

this resolves my error but yet again , i now have a new one

 

Notice: Undefined variable: status in C:\xampp\htdocs\videos\contact.php on line 72

 

that line is

 

<?php print $status; ?>

 

So i am guessing i have to define that as well now ?

 

Can someone just tell me if code i placed is ok , or have i completely messed it up , hence why i get this , or just the fact that the code i am using is so old and needs a major reworks , i am starting to understand i think that all commands can't be null they have to be assigned as such to work , but my knowledge is 0

 

Am i at least on the right track ?

 

I won't post no more until i solve this as don't want to get a warning for posting to much , cheers

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1403930
Share on other sites

Ok i think i have solved it

 

I had it as

 

Noname.jpg

When sending i got a access violation error , so back to the drawing board

 

Discovered yet more variables needed setting

 

My code is now after a lot of work

 

<?php


// Change these two variables to meet your needs.


$myemail = '[email protected]';
$subject = 'Change this contact subject';


if (isset($_GET['op']) && $_GET["op"] == "contact")
{
$name = stripslashes($_POST[name]);
$email = stripslashes($_POST[email]);
$text = stripslashes($_POST[text]);
$referrer = $_POST[referer];
$remote_host = $_SERVER[REMOTE_ADDR];
$server = $_SERVER[sERVER_NAME];
$browser = $_SERVER[HTTP_USER_AGENT];


if(!preg_match("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$",$email))
{
if (!empty($status)) {
$status = "We're sorry, but you've entered an incorrect email address.<br>";
}
}
if(!$name)
{
if (!empty($status)) {
$status .= "Please enter your name.<br>";
}
}
if(!$text)
{
if (!empty($status)) {
$status .= "Please enter a message.<br>";
}
}


if (!empty($status)) {
if(!$status)
{
$header = "From: $emailrnReply-To: $emailrn";

$message = "
Name: $name
Referer: $referer
Site: $server
Remote Host: $remote_host
Remote Browser: $browser

$text
";

if(mail($myemail, $subject, $message, $header))
{
if (!empty($status)) {
$status = "Thank you for your Feedback!!<br><br>";
}
}
else
{
if (!empty($status)) {
$status = "There was a problem sending your feedback, please try again later.<br><br>";
}
}

}
else
{
if (!empty($status)) {
$status .= "Please press <u>back</u> on your browser to resubmit.<br><br>";
}
}
}
}


// Now check the referer page and ensure it's a proper URL


$referer = $_SERVER['HTTP_REFERER'];


if(!preg_match('#^http\:\/\/[a-z0-9-]+.([a-z0-9-]+.)?[a-z]+#i', $referer))
{
unset($referer);
}


?>


<?php if (!empty($status)) {
print $status;
} ?>


<form method="post" action="<?php if (!empty($_SELF)) {
print $_SELF;
} ?>">
<input type="hidden" name="op" value="contact">
<input type="hidden" name="referrer" value="<?php print $referer; ?>">
Name<br><input name="name" size="35" value=""><br>
E-mail address<br><input name="email" size="35" value=""><br>
<br>Message<br><textarea name="text" cols="50" rows="10"></textarea><br><br>
<input type="submit" value="Send message!">
</form>

 

I had to make changes like this for it to work

 

<form method="post" action="<?php if (!empty($_SELF)) {
print $_SELF;
} ?>">

 

Happy now as i have

 

Noname2.jpg

It appears to work as well now , no errors given , just have to log into my email now and see if i have a test post , can someone just check over my code and tell me if see any other errors ?

 

Thanks for the help seems i might be able to do this php thing after all if pointed to the right place to look ?

:tease-03:

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1403939
Share on other sites

Cheers will take a look Love2c0de

 

Just waiting to see if it did indeed send to my email address now , all i have to do is now add my index page to it so it look slike part of the site :)

 

Can you just skim over the code above see if can spot anything cheers :)

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1403946
Share on other sites

I'm not the best at debugging php code, but just as a rule of thumb I would stick your $_POST indexes in single quotes.

$_POST['name'];

 

EDIT: I think you do have to explicitly set the double or single quotes and its returning an undefined constant error

 

That's another great debugging tool - var_dump(). Tells you the type and value of a variable and key/values of arrays.

 

hope it helps.

 

Regards,

 

L2c

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1403947
Share on other sites

Thanks for the help seems i might be able to do this php thing after all if pointed to the right place to look ?

 

I salute you for being so persistent - very well done. There are many individuals who give up at the first error but through your persistence you've corrected it and learnt a lot.

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1403957
Share on other sites

Stooney thanks so much for this ,, will try it , i thought that was weird and was going to google a answer but you beat me to it , i was just looking on the php website at different letters and stuff and checking what functions they perform

 

Getting there slowly

Link to comment
https://forums.phpfreaks.com/topic/272793-op-_postop/#findComment-1404066
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.