PDA

View Full Version : Form Submission


masterofollies
10-13-2007, 01:24 AM
Hi, I am trying to get a form to work correctly. This is what it looks like

http://img237.imageshack.us/my.php?image=sssll5.jpg

I set it up to be a chance, so if you click the correct button, you win something. This is in a function called digging2. After the button is pressed, I want to send it over to the function thedig. Which will check the submits, to see which was pressed, and put the show the result. But when you click any of the buttons, it shows a blank page. This is the coding part of function thedig which is the submitted part.

function thedig() {
global $userrow;
$update2query = doquery("UPDATE {{table}} SET location='Harvesting Spirits' WHERE id='".$userrow["id"]."' LIMIT 1", "users");

$spirits = rand(1,3);

if (isset($_POST["submit"])) {
$page = "<table width='100%'><tr><td class='title'>Harvested Young Spirits</td></tr></table>";
$page .= "You have harvested $spirits Young Spirits!";
$updatequery = doquery("UPDATE {{table}} SET spirits='$spirits' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
display($page, "Harvested Spirits");

} elseif (isset($_POST["submit2"])) {
$page = "<table width='100%'><tr><td class='title'>Bad Dig</td></tr></table>";
$page .= "You didn't find anything!";
display($page, "Bad Dig");

}
elseif (isset($_POST["submit3"])) {
$page = "<table width='100%'><tr><td class='title'>Bad Dig</td></tr></table>";
$page .= "You didn't find anything!";
display($page, "Bad Dig");
}
elseif (isset($_POST["submit4"])) {
$page = "<table width='100%'><tr><td class='title'>Bad Dig</td></tr></table>";
$page .= "You didn't find anything!";
display($page, "Bad Dig");
}
elseif (isset($_POST["submit5"])) {
$page = "<table width='100%'><tr><td class='title'>Bad Dig</td></tr></table>";
$page .= "You didn't find anything!";
display($page, "Bad Dig");
}
elseif (isset($_POST["submit6"])) {
$page = "<table width='100%'><tr><td class='title'>Bad Dig</td></tr></table>";
$page .= "You didn't find anything!";
display($page, "Bad Dig");
}
$userquery = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["id"]."' LIMIT 1", "users");
$userrow = mysql_fetch_array($userquery);


display($page,"Digging for Spirits");

}


This is some vial coding for what i'm doing. Any help?

Fumigator
10-13-2007, 06:48 AM
Hrmm, too bad you aren't checking your queries to see if they worked or not.

Do you have any PHP error reporting turned on? A blank page isn't helpful to you or us. At least echo the $_POST array or something.

masterofollies
10-13-2007, 02:39 PM
So would I do it like this?

}
elseif (isset($_POST["submit6"])) {
$page = "<table width='100%'><tr><td class='title'>Bad Dig</td></tr></table>";
$post = $_POST
$page .= "$post <br /><br />";
$page .= "You didn't find anything!";
display($page, "Bad Dig");
}

masterofollies
10-13-2007, 04:50 PM
Here is the coding for function digging2. This is where it shows the buttons.

function digging2() { //Digging for Young Spirits for drop forging
global $userrow;
$update2query = doquery("UPDATE {{table}} SET location='Harvesting Spirits' WHERE id='".$userrow["id"]."' LIMIT 1", "users");

//Changing the succuss buttons into different areas
$change = rand(1,100);

if ($change >= "1" && $change <= "20") {
$title = "Digging for Young Spirits";
$page = "<table width='100%' border='1'><tr><td class='title'>Digging for Young Spirits</td></tr></table><p>";
$page .= "<p><center>Click on a button below to attempt to harvest young spirits.</center><p>";
$page .= "<form action='index.php?do=thedig' method='POST'><table width='75%'>";
$page .= "<center><input type='submit' name='submit' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit2' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit3' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit4' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit5' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit6' value='Dig Here'><br />";
$page .= "</center></table><br /><br />";
$page .= "<center>You can return to the <a href=\"graveyard.php?do=main\">Graveyard</a></center>";
}

elseif ($change >= "21" && $change <= "40") {
$title = "Digging for Young Spirits";
$page = "<table width='100%' border='1'><tr><td class='title'>Digging for Young Spirits</td></tr></table><p>";
$page .= "<p><center>Click on a button below to attempt to harvest young spirits.</center><p>";
$page .= "<form action='index.php?do=thedig' method='POST'><table width='75%'>";
$page .= "<center><input type='submit' name='submit3' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit5' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit2' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit4' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit6' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit' value='Dig Here'><br />";
$page .= "</center></table><br /><br />";
$page .= "<center>You can return to the <a href=\"graveyard.php?do=main\">Graveyard</a></center>";
}

elseif ($change >= "41" && $change <= "60") {
$title = "Digging for Young Spirits";
$page = "<table width='100%' border='1'><tr><td class='title'>Digging for Young Spirits</td></tr></table><p>";
$page .= "<p><center>Click on a button below to attempt to harvest young spirits.</center><p>";
$page .= "<form action='index.php?do=thedig' method='POST'><table width='75%'>";
$page .= "<center><input type='submit' name='submit5' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit6' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit2' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit3' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit4' value='Dig Here'><br />";
$page .= "</center></table><br /><br />";
$page .= "<center>You can return to the <a href=\"graveyard.php?do=main\">Graveyard</a></center>";
}

elseif ($change >= "61" && $change <= "80") {
$title = "Digging for Young Spirits";
$page = "<table width='100%' border='1'><tr><td class='title'>Digging for Young Spirits</td></tr></table><p>";
$page .= "<p><center>Click on a button below to attempt to harvest young spirits.</center><p>";
$page .= "<form action='index.php?do=thedig' method='POST'><table width='75%'>";
$page .= "<center><input type='submit' name='submit4' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit5' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit6' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit2' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit3' value='Dig Here'><br />";
$page .= "</center></table><br /><br />";
$page .= "<center>You can return to the <a href=\"graveyard.php?do=main\">Graveyard</a></center>";
}

else {
$title = "Digging for Young Spirits";
$page = "<table width='100%' border='1'><tr><td class='title'>Digging for Young Spirits</td></tr></table><p>";
$page .= "<p><center>Click on a button below to attempt to harvest young spirits.</center><p>";
$page .= "<form action='index.php?do=thedig' method='POST'><table width='75%'>";
$page .= "<center><input type='submit' name='submit4' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit6' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit3' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit5' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit2' value='Dig Here'><br />";
$page .= "</center></table><br /><br />";
$page .= "<center>You can return to the <a href=\"graveyard.php?do=main\">Graveyard</a></center>";
}

display($page,"Digging for Spirits");

}

_Aerospace_Eng_
10-13-2007, 05:12 PM
Post the code for the doquery function.

masterofollies
10-13-2007, 05:52 PM
Which one? I use alot of them.

Inigoesdr
10-13-2007, 05:58 PM
The one that's used in the code you posted, and starts with function doquery(.

masterofollies
10-13-2007, 06:28 PM
I found it in lib

function doquery($query, $table) { // Something of a tiny little database abstraction layer.

include('config.php');
global $numqueries;
$sqlquery = mysql_query(str_replace("{{table}}", $dbsettings["prefix"] . "_" . $table, $query)) or die(mysql_error());
$numqueries++;
return $sqlquery;

}

masterofollies
10-14-2007, 11:59 PM
*bump*

Fumigator
10-15-2007, 02:31 AM
Do you have any PHP error reporting turned on? A blank page isn't helpful to you or us. At least echo the $_POST array or something.

Still waiting...

masterofollies
10-15-2007, 03:02 AM
You cannot use $_POST because it's a complete white page. Won't show anything.

Fumigator
10-15-2007, 03:05 AM
print "<pre>";
print_r ($_POST);
print "</pre>";

masterofollies
10-15-2007, 02:56 PM
Tried it and it still gives a blank white screen. It's as if no information is being carried. Like nothing to display.

Fumigator
10-15-2007, 03:49 PM
Good, then you found your problem. Your form is not being submitted properly.

masterofollies
10-15-2007, 06:41 PM
*sigh* but how can I fix this? All I want to do is have 6 buttons shown. Only 1 of them is the correct one. The other 5 are misses. So when your correct it takes you to a page and says Blah blah you dug up some young spirits, and if you miss it says like You dug a hole and didn't find anything. That's it

Fumigator
10-15-2007, 06:53 PM
I appreciate your problem, but what can we do? If your form isn't even submitting correctly, you need to troubleshoot where your process is failing. Is your script named index.php? That's the script that the HTTP POST request is going to send your form data to. What other issues are at work here? We can't see your environment, you have to do some digging. What does the source code look like on your form page? Does the HTML validate? Are there Javascript errors? We're shooting in the dark here.

aedrin
10-15-2007, 07:05 PM
An empty white page that shows nothing in the source - no matter what you add to the code - means you have a syntax or some other critical type of error in your code. Turn on error_reporting.

Also, I advise you to look at your code again, and consider why you have to copy and paste so much. You're writing very inefficiently.

Not to mention it would be very easy to cheat in your game. Look at the source code, look for the button with the right name and press it.

masterofollies
10-15-2007, 09:41 PM
Well I don't know what else to do, I gave all the coding possible that I know of. It's just a simple submit form. People like Aerospace are professional and know this stuff. I will try another forum where people are more knowledgeable.

aedrin
10-15-2007, 11:07 PM
You didn't do what was asked of you. How are we supposed to help?

masterofollies
10-15-2007, 11:36 PM
Because every single other submit form works fine on my site. I have like 10 - 15 of them. This one isn't working. So I know they work fine, it's just a broken link or a piece of wrong coding in this, which I cannot find.

_Aerospace_Eng_
10-15-2007, 11:38 PM
You are right, I do know this stuff but I'm with the others on this one. It sounds like you are getting a fatal error but you have error reporting turned off. Add this to the top of your page that you submit to
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);


If you are getting any errors that snippet will allow you to see them.

Fumigator
10-15-2007, 11:56 PM
I will try another forum where people are more knowledgeable.

Well that puts YOU on my ignore list! :p

I can only help you as much as you are capable of learning.

The other thing you can do is pay me $100 to fix your crappy code for you.

masterofollies
10-16-2007, 02:41 AM
Notice: Undefined index: login in /home/rodgameo/public_html/graveyard.php on line 27

Notice: Undefined offset: 1 in /home/rodgameo/public_html/graveyard.php on line 118

Notice: Undefined index: muggingxp in /home/rodgameo/public_html/lib.php on line 237

Notice: Undefined index: mugging in /home/rodgameo/public_html/lib.php on line 238

Notice: Undefined index: inventitemslist in /home/rodgameo/public_html/lib.php on line 424

Notice: Undefined variable: mailimage in /home/rodgameo/public_html/lib.php on line 482

_Aerospace_Eng_
10-16-2007, 03:07 AM
See? You have some errors. Now we need to see the code for graveyard.php and lib.php

Inigoesdr
10-16-2007, 03:25 AM
See? You have some errors.

Not a chance. The people here are not knowledgeable enough.

masterofollies
10-16-2007, 04:47 AM
I fixed this error

Notice: Undefined offset: 1 in /home/rodgameo/public_html/graveyard.php on line 118

But none of those errors have anything to do with this form. But I figured out a patch for it (in my mind) I hope it works. I will need to add an extra 30 lines or so to it. I am a beginner and that's why it looks so bad. If I posted some of my other work, it'd look better, but I like to be short and sweet. I am the only coder for my website, so I don't need comments.

aedrin
10-16-2007, 04:14 PM
If I posted some of my other work, it'd look better, but I like to be short and sweet. I am the only coder for my website, so I don't need comments.

Comments is a secondary thing.

Your code is actually too long. Using some basic concepts such as loops (while (http://www.php.net/manual/en/control-structures.while.php) , for (http://www.php.net/manual/en/control-structures.for.php), foreach (http://www.php.net/manual/en/control-structures.foreach.php)) and arrays (http://www.php.net/manual/en/ref.array.php).

These are some basic coding techniques that would reduce your code in size by about 80%.

if ($change >= "1" && $change <= "20") {
$title = "Digging for Young Spirits";
$page = "<table width='100%' border='1'><tr><td class='title'>Digging for Young Spirits</td></tr></table><p>";
$page .= "<p><center>Click on a button below to attempt to harvest young spirits.</center><p>";
$page .= "<form action='index.php?do=thedig' method='POST'><table width='75%'>";
$page .= "<center><input type='submit' name='submit' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit2' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit3' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit4' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit5' value='Dig Here'><br />";
$page .= "<input type='submit' name='submit6' value='Dig Here'><br />";
$page .= "</center></table><br /><br />";
$page .= "<center>You can return to the <a href=\"graveyard.php?do=main\">Graveyard</a></center>";
}

You repeat this code several times. You're only changing numbers in each. 99% of it is the same.

The simplest rule is, if - at any time - you have to copy and paste code, it can probably be done better. Here's a simple (not very effective though) way of doing what you did:


function getDigForm($title, $n1, $n2, $n3, $n4, $n5, $n6) {
$page = "<table width='100%' border='1'><tr><td class='title'>{$title}</td></tr></table><p>";
$code .= "<p><center>Click on a button below to attempt to harvest young spirits.</center><p>";
$code .= "<form action='index.php?do=thedig' method='POST'><table width='75%'>";
$code .= "<center><input type='submit' name='submit{$n1}' value='Dig Here'><br />";
$code .= "<input type='submit' name='submit{$n2}' value='Dig Here'><br />";
$code .= "<input type='submit' name='submit{$n3}' value='Dig Here'><br />";
$code .= "<input type='submit' name='submit{$n4}' value='Dig Here'><br />";
$code .= "<input type='submit' name='submit{$n5}' value='Dig Here'><br />";
$code .= "<input type='submit' name='submit{$n6}' value='Dig Here'><br />";
$code .= "</center></table><br /><br />";
$code .= "<center>You can return to the <a href=\"graveyard.php?do=main\">Graveyard</a></center>";
return $code;
}

if ($change >= 1 && $change <= 20) {
$title = "Digging for Young Spirits";
$page .= getFormCode($title, '', '1', '2', '3', '4', '5', '6');
} elseif ($change >= 21 && $change <= 40) {
$page .= getFormCode($title, '6', '', '4', '3', '5', '1', '2');
// etc.
}


Notice how clean this is?

Now, you could say that you already have it made, so why bother doing all this extra work?

Say you want to change what the form's code looks like? Now you only have to make 1 change, instead of making several and introducing the change of errors. So you have to test every version as well.

See what's happening? You have to spend time, to save time.

I am the only coder for my website, so I don't need comments.

You wouldn't be the first to change your mind.

Imagine that your site gets a little bit bigger, and you are informed of a bug somewhere in a piece of code that you haven't touched in more than a year.

You have to relearn the whole code just to even get started. Efficient? Not very.

You don't have to write stories for each 5 lines of code. The simplest method is to give a short, 1 line description of less than 10 words for each block of code that does something complicated.

If the code is obvious from reading it, then don't comment on it.


// loop over each item and store it in the backpack
foreach ($items as $item) {
$backpack->add($item);
}


See how silly that comment is? Those are unnecessary.

But if you have a large loop with several ifs and function calls, it wouldn't hurt to write up to 10 words to say what it does. You'll thank yourself for it.

masterofollies
10-16-2007, 07:18 PM
That is extremely confusing to me. It makes sense, but I haven't learned a thing about while, loop, or arrays. Maybe I should enroll in a php course.

aedrin
10-16-2007, 10:29 PM
Click on the links I gave for each of those keywords.

The PHP manual has everything you need to know.

masterofollies
10-20-2007, 04:25 PM
If fixed it, and it was so simple I couldn't see it. It was submitting to index.php instead of graveyard.php thats all.