Jump to content

reCAPTCHA + Webring php = trouble from email


Imokon

Recommended Posts

Hello there,

 

I browsed your forums after scouring the net and the recaptcha forums and I found a few things on reCAPTCHA but nothing that I think helps with what I am looking for. I will try to explain this to the best of my ability;

 

I am working on a site with a webring php script, I have the reCAPTCHA up and running, everything works fine. The problem arises when I get emails from the process.php that let me know who submitted a request to join the webring, and whether to approve or delete their application.

 

Now what I believe is that the reCAPTCHA script which is placed at the top of the process.php script, it is interfering (obviously) with everything the process does (which it shouldn't?) including what it does when the person trying to join the ring (as it should).

 

With that said, how would I place the reCAPTCHA script in the body of the email being sent to me if I can't obviously include it (recaptchalib.php) which it needs to run? I was thinking maybe I can validate my action that way - OR - is there a way to limit the reCAPTCHA script in the process.php to only affect the form submissions and not the links that i need to click on from my end?

 

Any help is greatly appreciated. I am self-taught and by no means an expert so excuse any ignorance :/

 

Here is the link to said form (no frontal nudity whatsoever but just incase not safe for work) http://mirrormatter.imokon.com/join.php

 

And here is my process source code;

 

<?php
require_once('recaptchalib.php');
$privatekey = "##########################";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
?>


<?
require("config.php");

if($_POST["action"]=="submit")
{
	$added=$_POST['added'];
	$password=$_POST['password'];
	$name=$_POST['name'];
	$email=$_POST['email'];
	$site_name=$_POST['site_name'];
	$url=$_POST['url'];
	$description=$_POST['description'];

	$sql = "INSERT INTO $db_table (added, password, name, email, site_name, url, description) VALUES ('$added', '$password', '$name', '$email', '$site_name', '$url', '$description')";
	$result = mysql_query($sql);

	$sql = "SELECT * FROM $db_table ORDER BY id DESC LIMIT 1";
	$result = mysql_query ($sql);
	while ($row = mysql_fetch_array($result))
		{
			$id = $row['id'];
			$password = $_POST['password'];
			$to = $_POST['email'];
			$from = "From: $admin_email";
			$subject = "$ring_name Submission";
			$message = "Thanks for joining the $ring_name webring!  Here is your login info, keep this in a safe place!\n\nSite ID: $id\nPassword: $password\n\nDon't forget to put up the ring code on your site as soon as possible!  You will not be added to the ring until I find the ring code on your site.\n\nHere's the code:\n\n<a href='http://mirrormatter.imokon.com/index.php?id=1&action=prev'><</a> <a href='http://mirrormatter.imokon.com/index.php?action=rand'>?</a> <a href='http://mirrormatter.imokon.com/index.php?action=home'>Mirror|Matter</a> <a href='http://mirrormatter.imokon.com/index.php?action=list'>#</a> <a href='http://mirrormatter.imokon.com/index.php?id=1&action=next'>></a>\n\nThanks!\n$admin_name\n$ring_url";
			$name = $_POST['name'];
			$url = $_POST['url'];
			$admin_message = "$name has joined $ring_name!  To check this site for your ring code, go to:\n$url\n\nTo approve this new site, go to:\n$ring_url/process.php?id=$id&action=approve\n\nAlternatively, to remove this site, go to:\n$ring_url/process.php?id=$id&action=remove";
			if(mail($to,$subject,$message,$from))
				{
					mail($admin_email,$subject,$admin_message,"From: $to");
					print"<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "Thanks for your submission!  We're taking you back to the main page!";
				}
			else
				{
					echo "There was a problem with your submission. Please check that you filled in the form correctly.";
				}
		}
}

elseif($_POST["action"]=="modify")
{
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$password1 = $row['password'];
			$password2 = $_POST['password'];

			if($password1 == $password2)
				{
					mysql_query("UPDATE $db_table SET name='$name', email='$email', site_name='$site_name', url='$url', description='$description' WHERE id='$id'");
					print"<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "Thanks for your modification!  We're taking you back to the main page!";
				}

			else
				{
					echo "There was a problem with your submission. Please check that you filled in the form correctly.";
				}
		}
}

elseif($_POST["action"]=="remove")
{
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$password1 = $row['password'];
			$password2 = $_POST['password'];

			$to = $row['email'];
			$url = $row['url'];

			if($password1 == $password2)
				{
					mysql_query("DELETE FROM $db_table WHERE id=$id");

					$from = "From: $admin_email";
					$subject = "Site Deleted From $ring_name";
					$message = "Your site has been deleted from $ring_name upon your request.  Sorry you decided to go!\n\n$admin_name\n$index_php";
					$admin_message = "The site located at $url has been deleted upon the owner's request.";
					if(mail($to,$subject,$message,$from))
						{
							mail($admin_email,$subject,$admin_message,"From: $to");
							print"<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
							echo "You've been deleted from $ring_name.  Sorry to see you go!";
						}
					else
						{
							echo "There was a problem with your submission. Please check that you filled in the form correctly.";
						}
				}

			else
				{
					echo "There was a problem with your submission. Please check that you filled in the form correctly.";
				}
		}
}

elseif($_POST["action"]=="approve")
{
	$id = $_POST['id'];
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$to = $row['email'];
			$subject = "$ring_name Approval";
			$message = "Your site has been approved in the $ring_name webring!  Thanks for joining!\n\n$admin_name\n$index_php";

			if($_POST['password'] == $admin_password)
				{
					mysql_query("UPDATE $db_table SET queue='1' WHERE id=$id");
					print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "Thanks for your approval!  We're taking you back to the main page!";
					mail($to,$subject,$message,"From: $admin_email");
				}
			else
				{
					echo "Wrong password.";
				}
		}
}

elseif($_POST["action"]=="delete")
{
	$id = $_POST['id'];
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$to = $row['email'];
			$site = $row['site_name'];
			$subject = "$ring_name Deletion";
			$message = "Your site has been deleted from the $ring_name webring!  If you have any questions about why your site was deleted, respond to this email.\n\n$admin_name\n$index_php";

			if($_POST['password'] == $admin_password)
				{
					mysql_query("DELETE FROM $db_table WHERE id=$id");
					print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "$site has been deleted from the webring!";
					mail($to,$subject,$message,"From: $admin_email");
				}
			else
				{
					echo "Wrong password.";
				}
		}
}

elseif($_GET["action"]=="approve")
{
	echo "Please enter your admin password:<br><br><form method=\"post\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"password\" name=\"password\"><input type=\"submit\" name=\"action\" value=\"approve\"></form>";
}

elseif($_GET["action"]=="remove")
{
	echo "Please enter your admin password:<br><br><form method=\"post\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"password\" name=\"password\"><input type=\"submit\" name=\"action\" value=\"delete\"></form>";
}

else
{
	echo "No variable passed.";
}



?>

Link to comment
Share on other sites

The reCaptcha is running everytime your script runs because it is not between one of your set of IF tags. You should put the reCaptcha script between whichever IF clause is run when a user tries to register to the webring.

 

If you have it just in the 'root' of the PHP script, and not between IF tags, it is run every time the php script is referenced regardless of whether and IF is called or not.

Link to comment
Share on other sites

I have three if's I want it to apply to, the Submit, Modify, and the first Remove.

 

The rest of the If's are 2 Approves, Delete, and the 2nd Remove.

 

Where would I place the reCAPTCHA script? or do I put it at every If I want it to apply to?

Link to comment
Share on other sites

I just placed it where I wanted it and I get this error;

 

Parse error: syntax error, unexpected T_ELSEIF in /home/imokon/mirrormatter/process.php on line 57

 

 


<?
{
require("config.php");

if($_POST["action"]=="submit")
require_once('recaptchalib.php');
$privatekey = "##################";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}


{


	$added=$_POST['added'];
	$password=$_POST['password'];
	$name=$_POST['name'];
	$email=$_POST['email'];
	$site_name=$_POST['site_name'];
	$url=$_POST['url'];
	$description=$_POST['description'];

	$sql = "INSERT INTO $db_table (added, password, name, email, site_name, url, description) VALUES ('$added', '$password', '$name', '$email', '$site_name', '$url', '$description')";
	$result = mysql_query($sql);

	$sql = "SELECT * FROM $db_table ORDER BY id DESC LIMIT 1";
	$result = mysql_query ($sql);
	while ($row = mysql_fetch_array($result))
		{
			$id = $row['id'];
			$password = $_POST['password'];
			$to = $_POST['email'];
			$from = "From: $admin_email";
			$subject = "$ring_name Submission";
			$message = "Thanks for joining the $ring_name webring!  Here is your login info, keep this in a safe place!\n\nSite ID: $id\nPassword: $password\n\nDon't forget to put up the ring code on your site as soon as possible!  You will not be added to the ring until I find the ring code on your site.\n\nHere's the code:\n\n<a href='http://mirrormatter.imokon.com/index.php?id=1&action=prev'><</a> <a href='http://mirrormatter.imokon.com/index.php?action=rand'>?</a> <a href='http://mirrormatter.imokon.com/index.php?action=home'>Mirror|Matter</a> <a href='http://mirrormatter.imokon.com/index.php?action=list'>#</a> <a href='http://mirrormatter.imokon.com/index.php?id=1&action=next'>></a>\n\nThanks!\n$admin_name\n$ring_url";
			$name = $_POST['name'];
			$url = $_POST['url'];
			$admin_message = "$name has joined $ring_name!  To check this site for your ring code, go to:\n$url\n\nTo approve this new site, go to:\n$ring_url/process.php?id=$id&action=approve\n\nAlternatively, to remove this site, go to:\n$ring_url/process.php?id=$id&action=remove";
			if(mail($to,$subject,$message,$from))
				{
					mail($admin_email,$subject,$admin_message,"From: $to");
					print"<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "Thanks for your submission!  We're taking you back to the main page!";
				}
			else
				{
					echo "There was a problem with your submission. Please check that you filled in the form correctly.";
				}
		}
}

elseif($_POST["action"]=="modify")
{
require_once('recaptchalib.php');
$privatekey = "##################";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}

{
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$password1 = $row['password'];
			$password2 = $_POST['password'];

			if($password1 == $password2)
				{
					mysql_query("UPDATE $db_table SET name='$name', email='$email', site_name='$site_name', url='$url', description='$description' WHERE id='$id'");
					print"<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "Thanks for your modification!  We're taking you back to the main page!";
				}

			else
				{
					echo "There was a problem with your submission. Please check that you filled in the form correctly.";
				}
		}
}

elseif($_POST["action"]=="remove")
{
require_once('recaptchalib.php');
$privatekey = "##################";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
{
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$password1 = $row['password'];
			$password2 = $_POST['password'];

			$to = $row['email'];
			$url = $row['url'];

			if($password1 == $password2)
				{
					mysql_query("DELETE FROM $db_table WHERE id=$id");

					$from = "From: $admin_email";
					$subject = "Site Deleted From $ring_name";
					$message = "Your site has been deleted from $ring_name upon your request.  Sorry you decided to go!\n\n$admin_name\n$index_php";
					$admin_message = "The site located at $url has been deleted upon the owner's request.";
					if(mail($to,$subject,$message,$from))
						{
							mail($admin_email,$subject,$admin_message,"From: $to");
							print"<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
							echo "You've been deleted from $ring_name.  Sorry to see you go!";
						}
					else
						{
							echo "There was a problem with your submission. Please check that you filled in the form correctly.";
						}
				}

			else
				{
					echo "There was a problem with your submission. Please check that you filled in the form correctly.";
				}
		}
}

elseif($_POST["action"]=="approve")
{
	$id = $_POST['id'];
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$to = $row['email'];
			$subject = "$ring_name Approval";
			$message = "Your site has been approved in the $ring_name webring!  Thanks for joining!\n\n$admin_name\n$index_php";

			if($_POST['password'] == $admin_password)
				{
					mysql_query("UPDATE $db_table SET queue='1' WHERE id=$id");
					print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "Thanks for your approval!  We're taking you back to the main page!";
					mail($to,$subject,$message,"From: $admin_email");
				}
			else
				{
					echo "Wrong password.";
				}
		}
}

elseif($_POST["action"]=="delete")
{
	$id = $_POST['id'];
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$to = $row['email'];
			$site = $row['site_name'];
			$subject = "$ring_name Deletion";
			$message = "Your site has been deleted from the $ring_name webring!  If you have any questions about why your site was deleted, respond to this email.\n\n$admin_name\n$index_php";

			if($_POST['password'] == $admin_password)
				{
					mysql_query("DELETE FROM $db_table WHERE id=$id");
					print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "$site has been deleted from the webring!";
					mail($to,$subject,$message,"From: $admin_email");
				}
			else
				{
					echo "Wrong password.";
				}
		}
}

elseif($_GET["action"]=="approve")
{
	echo "Please enter your admin password:<br><br><form method=\"post\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"password\" name=\"password\"><input type=\"submit\" name=\"action\" value=\"approve\"></form>";
}

elseif($_GET["action"]=="remove")
{
	echo "Please enter your admin password:<br><br><form method=\"post\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"password\" name=\"password\"><input type=\"submit\" name=\"action\" value=\"delete\"></form>";
}

else
{
	echo "No variable passed.";
}



?>


Link to comment
Share on other sites

Try using this instead. You'd gotten a little lost with your if's and elseif's

 

<?
require("config.php");

if($_POST["action"]=="submit"){
require_once('recaptchalib.php');
$privatekey = "##################";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
	$added=$_POST['added'];
	$password=$_POST['password'];
	$name=$_POST['name'];
	$email=$_POST['email'];
	$site_name=$_POST['site_name'];
	$url=$_POST['url'];
	$description=$_POST['description'];

	$sql = "INSERT INTO $db_table (added, password, name, email, site_name, url, description) VALUES ('$added', '$password', '$name', '$email', '$site_name', '$url', '$description')";
	$result = mysql_query($sql);

	$sql = "SELECT * FROM $db_table ORDER BY id DESC LIMIT 1";
	$result = mysql_query ($sql);
	while ($row = mysql_fetch_array($result))
		{
			$id = $row['id'];
			$password = $_POST['password'];
			$to = $_POST['email'];
			$from = "From: $admin_email";
			$subject = "$ring_name Submission";
			$message = "Thanks for joining the $ring_name webring!  Here is your login info, keep this in a safe place!\n\nSite ID: $id\nPassword: $password\n\nDon't forget to put up the ring code on your site as soon as possible!  You will not be added to the ring until I find the ring code on your site.\n\nHere's the code:\n\n<a href='http://mirrormatter.imokon.com/index.php?id=1&action=prev'><</a> <a href='http://mirrormatter.imokon.com/index.php?action=rand'>?</a> <a href='http://mirrormatter.imokon.com/index.php?action=home'>Mirror|Matter</a> <a href='http://mirrormatter.imokon.com/index.php?action=list'>#</a> <a href='http://mirrormatter.imokon.com/index.php?id=1&action=next'>></a>\n\nThanks!\n$admin_name\n$ring_url";
			$name = $_POST['name'];
			$url = $_POST['url'];
			$admin_message = "$name has joined $ring_name!  To check this site for your ring code, go to:\n$url\n\nTo approve this new site, go to:\n$ring_url/process.php?id=$id&action=approve\n\nAlternatively, to remove this site, go to:\n$ring_url/process.php?id=$id&action=remove";
			if(mail($to,$subject,$message,$from))
				{
					mail($admin_email,$subject,$admin_message,"From: $to");
					print"<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "Thanks for your submission!  We're taking you back to the main page!";
				}
			else
				{
					echo "There was a problem with your submission. Please check that you filled in the form correctly.";
				}
		}
}
elseif($_POST["action"]=="modify")
{
require_once('recaptchalib.php');
$privatekey = "##################";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$password1 = $row['password'];
			$password2 = $_POST['password'];

			if($password1 == $password2)
				{
					mysql_query("UPDATE $db_table SET name='$name', email='$email', site_name='$site_name', url='$url', description='$description' WHERE id='$id'");
					print"<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "Thanks for your modification!  We're taking you back to the main page!";
				}

			else
				{
					echo "There was a problem with your submission. Please check that you filled in the form correctly.";
				}
		}
}
elseif($_POST["action"]=="remove")
{
require_once('recaptchalib.php');
$privatekey = "##################";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$password1 = $row['password'];
			$password2 = $_POST['password'];

			$to = $row['email'];
			$url = $row['url'];

			if($password1 == $password2)
				{
					mysql_query("DELETE FROM $db_table WHERE id=$id");

					$from = "From: $admin_email";
					$subject = "Site Deleted From $ring_name";
					$message = "Your site has been deleted from $ring_name upon your request.  Sorry you decided to go!\n\n$admin_name\n$index_php";
					$admin_message = "The site located at $url has been deleted upon the owner's request.";
					if(mail($to,$subject,$message,$from))
						{
							mail($admin_email,$subject,$admin_message,"From: $to");
							print"<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
							echo "You've been deleted from $ring_name.  Sorry to see you go!";
						}
					else
						{
							echo "There was a problem with your submission. Please check that you filled in the form correctly.";
						}
				}

			else
				{
					echo "There was a problem with your submission. Please check that you filled in the form correctly.";
				}
		}
}
elseif($_POST["action"]=="approve")
{
	$id = $_POST['id'];
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$to = $row['email'];
			$subject = "$ring_name Approval";
			$message = "Your site has been approved in the $ring_name webring!  Thanks for joining!\n\n$admin_name\n$index_php";

			if($_POST['password'] == $admin_password)
				{
					mysql_query("UPDATE $db_table SET queue='1' WHERE id=$id");
					print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "Thanks for your approval!  We're taking you back to the main page!";
					mail($to,$subject,$message,"From: $admin_email");
				}
			else
				{
					echo "Wrong password.";
				}
		}
}
elseif($_POST["action"]=="delete")
{
	$id = $_POST['id'];
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))
		{
			$to = $row['email'];
			$site = $row['site_name'];
			$subject = "$ring_name Deletion";
			$message = "Your site has been deleted from the $ring_name webring!  If you have any questions about why your site was deleted, respond to this email.\n\n$admin_name\n$index_php";

			if($_POST['password'] == $admin_password)
				{
					mysql_query("DELETE FROM $db_table WHERE id=$id");
					print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
					echo "$site has been deleted from the webring!";
					mail($to,$subject,$message,"From: $admin_email");
				}
			else
				{
					echo "Wrong password.";
				}
		}
}
elseif($_GET["action"]=="approve")
{
	echo "Please enter your admin password:<br><br><form method=\"post\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"password\" name=\"password\"><input type=\"submit\" name=\"action\" value=\"approve\"></form>";
}
elseif($_GET["action"]=="remove")
{
	echo "Please enter your admin password:<br><br><form method=\"post\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"password\" name=\"password\"><input type=\"submit\" name=\"action\" value=\"delete\"></form>";
}
else
{
	echo "No variable passed.";
}
?>

Link to comment
Share on other sites

Almost there! I finally reached the page now where I need to put in my password to confirm approval of a site, but then I get this error;

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/imokon/mirrormatter/process.php on line 137

Link to comment
Share on other sites

The error is occuring here

 

$id = $_POST['id'];
	$sql = "SELECT * FROM $db_table WHERE id=$id";
	$result = mysql_query($sql);
	while ($row = mysql_fetch_array($result))

 

Check the the form is sending the ID correctly as a post and not a get and that it's also called id and not ID or iD or Id.

Link to comment
Share on other sites

I guess I am lost here.

 

This is the email where I am to approve a site (apparently it's id "4")

 

imokon has joined Mirror|Matter! To check this site for your ring code, go to: http://menstruosity.com

To approve this new site, go to: http://mirrormatter.imokon.com/process.php?id=4&action=approve

Alternatively, to remove this site, go to: http://mirrormatter.imokon.com/process.php?id=4&action=remove

 

 

So I am assuming it already assigned the id?

 

Edit: Everything in the database is fine.. hmm....

 

It says post where it should in this section;

 

            echo "Please enter your admin password:<br><br><form method=\"post\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"password\" name=\"password\"><input type=\"submit\" name=\"action\" value=\"approve\"></form>";
   }
elseif($_GET["action"]=="remove")
   {
      echo "Please enter your admin password:<br><br><form method=\"post\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"id\" value=\"$id\"><input type=\"password\" name=\"password\"><input type=\"submit\" name=\"action\" value=\"delete\"></form>";
   }

Link to comment
Share on other sites

After rereading this thread a couple more times I realized my last reply was just completely out of context. Anyway I guess I am still stumped even though I have a bit of a better understanding of what the error mysql_fetch_array() is.

 

I've double checked that the value for "id" is consistent throughout.

I've tried mysql_fetch_array($result, MYSQL_ASSOC)) and other modifications just incase the fetching wasn't fetching the right way?

 

I've tried to, clear the database and start over just incase...

 

I have made a real effort to understand what the code is exactly trying to say and I guess what is really stumping me now is back to what you said about getting and posting and how to double check...?

Link to comment
Share on other sites

Basically the code isn't finding the entry in the database. Say you have and ID column in your table with values of 1, 2 and 3. If you search for value 4 then it will give you this error as mySQL hasn't found a record with ID 4 and as such there is no array to fetch.

Link to comment
Share on other sites

I guess what's boggling my mind is that I looked at the table and it has id as "id", all the applicants info, etc. It was already populated when I submitted info in the first stage.

 

Do I have to redefine the values seen here from earlier in the code, like add another $sql and $result somewhere?

 

      $sql = "INSERT INTO $db_table (added, password, name, email, site_name, url, description) VALUES ('$added', '$password', '$name', '$email', '$site_name', '$url', '$description')";
      $result = mysql_query($sql);

      $sql = "SELECT * FROM $db_table ORDER BY id DESC LIMIT 1";
      $result = mysql_query ($sql);
      while ($row = mysql_fetch_array($result))

 

Also here's a screencap of the table (keep in mind I cleaned out the database, so the id I was trying to approve this time was "1".

 

[attachment deleted by admin]

Link to comment
Share on other sites

Well, once you have that done, to populate your $id variable you should just do this:

 

      $sql = "INSERT INTO $db_table (added, password, name, email, site_name, url, description) VALUES ('$added', '$password', '$name', '$email', '$site_name', '$url', '$description')";
      $result = mysql_query($sql);
      $sql = "SELECT * FROM $db_table ORDER BY id DESC LIMIT 1";
      $result = mysql_query ($sql);
      $id = $result['id']; //replace id with whatever the name of your id column is

Link to comment
Share on other sites

I thought the column was already "id" from what I've seen?

 

 

And I place this code where exactly? Do I have to edit it manually each time?

      $id = $result['id']; //replace id with whatever the name of your id column is

Link to comment
Share on other sites

Here's what the code looks like now. I got past the approval thing it accepted it etc etc, but when I go to the members page the site is not there.

 

elseif($_POST["action"]=="approve")
   {
      $id = $_POST['id'];
      $sql = "SELECT * FROM $db_table WHERE id=$id";
      $result = mysql_query($sql);
      $sql = "INSERT INTO $db_table (added, password, name, email, site_name, url, description) VALUES ('$added', '$password', '$name', '$email', '$site_name', '$url', '$description')";
      $result = mysql_query($sql);
      $sql = "SELECT * FROM $db_table ORDER BY id DESC LIMIT 1";
      $result = mysql_query ($sql);
      $id = $result['id']; //replace id with whatever the name of your id column is
      while ($row = mysql_fetch_array($result))
         {
            $to = $row['email'];
            $subject = "$ring_name Approval";
            $message = "Your site has been approved in the $ring_name webring!  Thanks for joining!\n\n$admin_name\n$index_php";

            if($_POST['password'] == $admin_password)
               {
                  mysql_query("UPDATE $db_table SET queue='1' WHERE id=$id");
                  print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
                  echo "Thanks for your approval!  We're taking you back to the main page!";
                  mail($to,$subject,$message,"From: $admin_email");
               }
            else
               {
                  echo "Wrong password.";
               }
         }
   }

 

It appears to work fine but when I go to the Members page there's 0 in the queue!

 

Now this is what I get on the Queue page;

 

Warning: date() expects parameter 2 to be long, string given in /home/imokon/mirrormatter/queue.php on line 27
id: 2
submitted on 

Link to comment
Share on other sites

Firstly, the $id request should be placed as shown below, not outside the while function...

 

elseif($_POST["action"]=="approve")
   {
      $id = $_POST['id'];
      $sql = "SELECT * FROM $db_table WHERE id=$id";
      $result = mysql_query($sql);
      $sql = "INSERT INTO $db_table (added, password, name, email, site_name, url, description) VALUES ('$added', '$password', '$name', '$email', '$site_name', '$url', '$description')";
      $result = mysql_query($sql);
      $sql = "SELECT * FROM $db_table ORDER BY id DESC LIMIT 1";
      $result = mysql_query ($sql);
      while ($row = mysql_fetch_array($result))
         {
            $id = $row['id'];
            $to = $row['email'];
            $subject = "$ring_name Approval";
            $message = "Your site has been approved in the $ring_name webring!  Thanks for joining!\n\n$admin_name\n$index_php";

            if($_POST['password'] == $admin_password)
               {
                  mysql_query("UPDATE $db_table SET queue='1' WHERE id=$id");
                  print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
                  echo "Thanks for your approval!  We're taking you back to the main page!";
                  mail($to,$subject,$message,"From: $admin_email");
               }
            else
               {
                  echo "Wrong password.";
               }
         }
   }

 

That was probably my poor explanation rather than your understanding. See if that helps with anything. Get back to me if it doesn't.

Link to comment
Share on other sites

Ok, I copied and pasted the code you just posted. I got the same error. I went ahead and reinstalled the ring just to make sure (deleted and recreated database). I made a new submission, managed to approve it. It's not on the Members page, so I go back to the Queue and I see this error again;

 

sites in queue (2)


Warning: date() expects parameter 2 to be long, string given in /home/imokon/mirrormatter/queue.php on line 27
id: 2
submitted on

Mirror|Matter Webring id: 1
submitted on 10-16-08

 

 

So is it that the script is out of date or something?

 

Thanks for your patience.

Link to comment
Share on other sites

I got the same error;

Warning: strtotime() expects parameter 2 to be long, string given in /home/imokon/mirrormatter/queue.php on line 27
id: 2
submitted on

 

Unless I placed the code wrong?

<?
require("config.php");

$sql = "SELECT * FROM $db_table WHERE queue = '0' ORDER BY id DESC";
$result = mysql_query ($sql);

$num_rows = mysql_num_rows($result);
echo "<strong>sites in queue</strong> ($num_rows)<br /><br />";

while ($row = mysql_fetch_array($result))
{
	$added = strtotime("m-d-y",$row["added"]);
	echo '<a href="'.$row["url"].'" target="_blank">'.$row["site_name"].'</a> id: '.$row["id"].'<br /> submitted on '.$added.'<br /><br />';
}

mysql_close();
?>

 

 

it used to be;

 

<?
require("config.php");

$sql = "SELECT * FROM $db_table WHERE queue = '0' ORDER BY id DESC";
$result = mysql_query ($sql);

$num_rows = mysql_num_rows($result);
echo "<strong>sites in queue</strong> ($num_rows)<br /><br />";

while ($row = mysql_fetch_array($result))
{
	$added = date("m-d-y",$row["added"]);
	echo '<a href="'.$row["url"].'" target="_blank">'.$row["site_name"].'</a> id: '.$row["id"].'<br /> submitted on '.$added.'<br /><br />';
}

mysql_close();
?>

Link to comment
Share on other sites

In the code below, what does the variable $added get populated with?

 

elseif($_POST["action"]=="approve")
   {
      $id = $_POST['id'];
      $sql = "SELECT * FROM $db_table WHERE id=$id";
      $result = mysql_query($sql);
      $sql = "INSERT INTO $db_table (added, password, name, email, site_name, url, description) VALUES ('$added', '$password', '$name', '$email', '$site_name', '$url', '$description')";
      $result = mysql_query($sql);
      $sql = "SELECT * FROM $db_table ORDER BY id DESC LIMIT 1";
      $result = mysql_query ($sql);
      while ($row = mysql_fetch_array($result))
         {
            $id = $row['id'];
            $to = $row['email'];
            $subject = "$ring_name Approval";
            $message = "Your site has been approved in the $ring_name webring!  Thanks for joining!\n\n$admin_name\n$index_php";

            if($_POST['password'] == $admin_password)
               {
                  mysql_query("UPDATE $db_table SET queue='1' WHERE id=$id");
                  print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"3; URL=$index_php\">";
                  echo "Thanks for your approval!  We're taking you back to the main page!";
                  mail($to,$subject,$message,"From: $admin_email");
               }
            else
               {
                  echo "Wrong password.";
               }
         }
   }

 

To solve this, when adding the date to the database the first time round use this:

 

$added=time();

 

Then when querying from the database, to get the date in the format you want use this:

 

while ($row = mysql_fetch_array($result))
{
	$added = date("m-d-y",$row["added"]);
	echo '<a href="'.$row["url"].'" target="_blank">'.$row["site_name"].'</a> id: '.$row["id"].'<br /> submitted on '.$added.'<br /><br />';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.