• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

Form not working, wont submit to database!

Hi there,

I have an issue with my form, I am trying to submit the data in the form to my database. However when clicking "proceed >" nothing happens.

Thanks for any help.
<form name="join" method="post" action="process.php" onsubmit="return setTotal();">
		      
			   <? mysql_select_db("newff") or die(mysql_error()); 
 $data = mysql_query("SELECT * FROM users") 
 or die(mysql_error());  ?>
			  
			  <table bgcolor="#F0EFEF" border="0" cellpadding="8" cellspacing="5" class="upcomingborder">
			  <tr>
			  <td bgcolor="#000000" align="right" class="upcomingborder"><font class='upcomingw'>Your Name:</font></td>
			  <td class="upcomingborder">
			  <input class="inputmain" type="text" name="fullname" maxlength="50" readonly value="<? echo $myuser->getName(FALSE); ?>">
			  </td>
			  </tr>
			  <tr>
			  <td bgcolor="#000000" align="right" class="upcomingborder"><font class='upcomingw'>Choose a Team Name: (25 max)</font></td>
			  <td class="upcomingborder">
			  <input class="inputmain" type="text" name="teamname" maxlength="25" value="">
			  </td>
			  </tr>
			  <tr>
			  <td bgcolor="#000000" align="right" class="upcomingborder"><font class='upcomingw'>Choose a League:</font></td>
			  <td class="upcomingborder">
			  <select class="selecto" name="league" onChange="calcBudget(this.form);">
                          <option></option>
                          <option value="Premier Smash-10">Premier Smash - £10.00</option>
                          <option value="Goals Galore-20">Goals Galore - £20.00</option>
                        </select>
			  </td>
			  </tr>
			  <tr> 
                      <td bgcolor="#000000" align="right" class="upcomingborder"><font class='upcomingw'>Your Order Total:</font></td>
                      <td class="upcomingborder">£ 
                        <input class="inputorder" type="text" name="ordert" maxlength="5" readonly value="0" />
                        .00 </td>
                    </tr>
			  </table>
		
		<input type="button" value="Proceed >" class="subut" />
	</form>

Open in new window

<?
$fullname $_POST['fullname'];
$teamname $_POST['teamname'];
$league $_POST['league'];
$ordert $_POST['ordert'];

mysql_select_db ("newff");

$query = "INSERT INTO upcoming_leagues_users (id, fullname, team_name, league_name, order_total) VALUES ('0', '$fullname', '$teamname', '$league', '$ordert') ";
mysql_query($query) or die ('Error joining a league, Please try again or contact us for help!');

echo "You have successfully joined a league!";
?>

Open in new window

0
james130c
Asked:
james130c
  • 4
  • 2
  • 2
  • +2
4 Solutions
 
kelvinwkwCommented:
<input type="submit" value="Proceed >" class="subut" />
0
 
james130cAuthor Commented:
Thanks, well now it submits but to a page cannot be displayed... any ideas? I would like for it when it is submit to go to another page.
0
 
kelvinwkwCommented:
$fullname = $_POST['fullname'];
$teamname = $_POST['teamname'];
$league = $_POST['league'];
$ordert = $_POST['ordert'];

the equal sign went missing. ^^
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
james130cAuthor Commented:
Hi there, Thanks for that.

Also is there a way to store the information (for example) once i submit it goes to process.php... but once on this page if i refresh or something by mistake etc.. it just completely forgets my data etc.. and i get an error.
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
Can we assume you have a mysql_connect somewhere in your process.php file?
0
 
james130cAuthor Commented:
Yes there is a connect...
0
 
Mark BradyCommented:
james - The easiest way to remember form data across multiple webpages is to use php sessions().

What they do is you open/start a session on each of your php script that you need to share data between.

Once you submit a form, all those form values get POSTED or sent via GET to the form but they also are gathered inside "session" variables. You can recall them anywhere at any time as long as you call for "session_start() at the start of each page you want to use them on.

Here's a quick example..

Copy this text and save the file as "session.php"

<?php // session.php - include with ALL documents you need to work with php sessions()
session_start();
if(is_array($_REQUEST)) {
  foreach($_REQUEST as $key => $value){
    $_SESSION[$key] = $value;
    }
}
?>
Put that script inside your web folder somewhere and remember the path to it.

Open ANY other php script (in this case, your FORM webpage (it must be a .php page not html).

Place this line as the very first line of code on the page after the opening tag.

<?php
include("session.php");

/// the rest of your form data..

?>

Now do the same thing in the php script that "accepts" the form data. Place that include line as the first line of code.

Now to access any of the sent data you do it like this.

For example, if you sent on your form 'firstName', 'lastName' , 'email' you would usually get them like this in the script..

$firstName = addslashes($_POST['firstName']);

or

$firstName = mysql_real_escape_string($_POST['firstName']);

and so on for each posted variable.. You can also use $_REQUEST['firstName'] which will get both POST and GET methods.

Anyhow, the point is, now you also can get those variables like this.

$firstName = $_SESSION['firstName'];

The "$_SESSION[]" variable is a super-global variable and it is available for use publically and inside functions and classes as well.

Now that you understand that, in your php web form, this is how you make sure the form remembers the input data in case the user has to go back to the form to correct something.

The form for eg:

<form method="POST" action="your_php_script.php">
<input type="text" name="firstName" value="<?php echo $firstName;?>" /> First Name<br />
<input type="text" name="lastName" value="<?php echo $lastName;?>" /> Last Name<br />
<input type="text" name="email" value="<?php echo $email;?>" /> Email address<br />
<input type="submit" value="send mail" />

Now fill out the form and click "send mail" button. Do whatever you want with the data in the receiving script. Now go back to the form and refresh the page with the "reload" button.

See how the information you entered is still there in the form fileds? That is because there is an active "session()" running on that page and the variables are still holding the form data.

Sites that use login's for their users also mainly use php sessions to track the logged in user around their website. How else are you supposed to know if a user is logged in or not right?

To clear out the session variables there are several methods. First, you could unset the variables that you want cleared like this.

unset($_SESSION['firstName']);
and so on for each of the session vaRIABLES (OR WRITE A SIMPLE LOOP FUNCTION TO UNSET EACH VARIABLE EXCEPT FOR PERHAPS THE USERNAME - sorry the caps lock key was on....

To kill the entire session including the variables and the session itseft use this:

session_destroy();

On a typical website where users need to login and logout, the main logout code is a simple "session_destroy()" command that closes the entire php session down and clears all variables (only the session variables).

Before you can use session_destroy() you must first have a valid/current session running so on a logout page you would use something like this:

<?php //logout.php
include("session.php");  // start by opening a new php session()
session_destroy();         // destroy it along with all of its variables/data
header("location: index.php"); // redirect the webpage back to the login page (or somewhere else)
exit(); // exit this script;
?>

you could also all some cleanup code in here that either records the users logout time and stores that in the database if you track those things but if so, this is where you would do it.

I hope this has been some help to you.


0
 
james130cAuthor Commented:
Hi thank you, Ive increased the points to 350 however because I realise i have been asking for help with other things not originally in my  post.

If you could possibly help me with what happens during the submit of the form also that would be great. So here is my form setup and PHP code.

So basically my form works, when submitted as normal... however we all know things dont always go to plan for people filling out forms. So If the form is left empty I check for that error and if so it displays it. I would really like to .1 be able to add a few more common error checks to the form such as ilegal charcatars @:;#./\? etc...

But also my main problem is because my code for error check is right below my form the error message seems to only be able to be played below too. This is creating problems because when i submit the form leaving the fields blank i get the error indeed but its a long page and the form is right at the bottom. So it looks like its been submit fine... until u scroll down and u then see the error.

Is there a way around this, like a way to jump the page down to the bottom if there an error or even be able to display the error else where on the page.

Thanks.
<form name="join" method="post" action="leagues.php" onsubmit="return setTotal();">
		      
			   			  
			  <table bgcolor="#F0EFEF" border="0" cellpadding="8" cellspacing="5" class="upcomingborder">
			  <tr>
			  <td bgcolor="#000000" align="right" class="upcomingborder"><font class='upcomingw'>Your Name:</font></td>
			  <td class="upcomingborder">
			  <input class="inputmain" type="text" name="fullname" maxlength="50" readonly value="<? echo $myuser->getName(FALSE); ?>">
			  </td> 
			  </tr>
			  <tr>
			  <td bgcolor="#000000" align="right" class="upcomingborder"><font class='upcomingw'>Choose a Team Name: (25 max)</font></td>
			  <td class="upcomingborder">
			  <input class="inputmain" type="text" name="teamname" maxlength="25" value="<?php echo $teamname;?>">
			  </td>
			  </tr>
			  <tr>
			  <td bgcolor="#000000" align="right" class="upcomingborder"><font class='upcomingw'>Choose a League:</font></td>
			  <td class="upcomingborder">
			  <select class="selecto" name="league" onChange="calcBudget(this.form);">
                          <option></option>
                          <option value="Premier Smash-10">Premier Smash - £10.00</option>
                          <option value="Goals Galore-20">Goals Galore - £20.00</option>
                        </select>
			  </td>
			  </tr>
			  <tr> 
                      <td bgcolor="#000000" align="right" class="upcomingborder"><font class='upcomingw'>Your Order Total:</font></td>
                      <td class="upcomingborder">£ 
                        <input class="inputorder" type="text" name="ordert" maxlength="5" readonly value="0" />
                        .00 </td>
                    </tr>
			  </table>
			  <input type="hidden" name="user_id1" value="<? echo " $info1[user_id] "; ?>">
		<br /><input type="hidden" name="submitted" value="1">
		<input type="submit" value="Proceed >>" class="subut1" />
	</form>

Open in new window

<?		if ($_POST['submitted']==1) {
    $errormsg = ""; //Initialize errors
    if ($_POST[teamname]){
        $teamname = $_POST[teamname]; //If title was entered
    }
    else{
        $errormsg = "Sorry there was an error. Please enter a Team Name.";
    }
    if ($_POST[league]){
        $league = $_POST[league]; //If comment was entered
    }
    else{
        if ($errormsg){ //If there is already an error, add next error
            $errormsg = $errormsg . " Also please select a Fantasy League!";
        }else{
            $errormsg = "Sorry there was an error. Please select a Fantasy League.";
        }
    }
}

//If all fields present
if ($teamname && $league){
   
// load the variables form address bar
$fullname = $_POST['fullname'];
$teamname = $_POST['teamname'];
$league = $_POST['league'];
$ordert = $_POST['ordert'];
$user_id1 = $_POST['user_id1'];

// remove the backslashes that normally appears when entering " or '
$fullname = stripslashes($fullname); 
$teamname = stripslashes($teamname); 
$league = stripslashes($league);
$ordert = stripslashes($ordert);
$user_id1 = stripslashes($user_id1);
 

mysql_select_db ("newff");

$query = "INSERT INTO upcoming_leagues_users (id, user_id, fullname, team_name, league_name, order_total) VALUES ('0', '$user_id1', '$fullname', '$teamname', '$league', '$ordert') ";
mysql_query($query) or die ("<br /><div class='dberror'>Sorry there was an error when attempting to join a league! Please try again or if the problem continues please contact us and we will assist you! 
<hr /> A Common reason for this is that you already have a pending league, if this is the case please be patient as your current league and team are still being setup. This will normally take 1-2 hours at the most. You may enter more leagues once your current league has been setup. </div> <br /> <div class='subl'> <font class='white'>Please <a href='leagues.php'>Go Back</a>. </font> </div> </div></td>
</tr>
</table>		
</div>

<div id='bottom_content'></div>");

echo "<meta http-equiv=\"refresh\" content=\"0; URL=$WEB_ROOT/complete_payment.php\" /><title></title></head><body></body></html>";
		// header("Location: $DOC_ROOT/");
		exit;
   
}
if ($errormsg){ //If any errors display them
    echo "<br /> <div class=\"dberror\">$errormsg</div>";
}
?>

Open in new window

0
 
Ray PaseurCommented:
What you're wrestling with here has been handled by others before, so please let me recommend this excellent little book.  It will not make you a pro, but it will give you something of a foundation in how PHP and MySQL work.  Very readable with great examples and a code library that you can copy and modify for your own use. Now in its fourth printing, it has been a permanent part of my professional library since Edition One.
http://www.sitepoint.com/books/phpmysql4/

If you're looking for client authentication, this article may help.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

Best regards, ~Ray
0
 
Mark BradyCommented:
Hi Ray

You can't ask more than one question inside another question. Please stick to the rule here on
EE and if you need help with your form we would love to help you but it must be in  new question. These questions are stored in the database so others can search for similar issues and hopefully they will find the answers in EE questions already solved.

So try and keep your question to the one problem if you can. Also, raising points to 350 may seem like a big deal but a question like yours where you really need quite a lot of help, should be a 500 point question. I'm not giving you a lecture, just trying to help you understand how experts-exchange works.

Your original question asked "Why your form was not Submitting".

That has been answered by experts. Please select the answer that best helped you solve the problem (your typing was the culprit) and close this question out.

If you want help with the rest of the process, think of what you need and form a new question. Keep in mind what I said about the points to. Experts will more than likely skip over a question that is going to take them some time to answer fully and the points are low so keep that in mind.

I hope this has been of some help to you and thanks for listening.
0
 
Ray PaseurCommented:
Hi, @elvin66.  It's not my question :-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now