...

View Full Version : My form goes back to the home page!



oxygenproject
03-05-2010, 04:52 AM
G'day guys,

I have created a form inside the admin section of my website that inserts data into mysql.. and works a charm (its an account creation form). The only problem is that once I press submit it logs me out and returns to the home page of my web app.

So for example the url for the section i am in is: www.website.com/index.php?m=admin&view=create

when I press submit it takes me back to: index.php.

The code for the form is as follows, if that helps:


<?php
if($_POST["username"]) {
$connection = db_connect();
extract($_POST);
mysql_query("INSERT INTO `".$type."`".
"(`username`, `first_name`, `last_name`, `password`,".
"`email`, subjects".
") VALUES(".
"'$username', '$first_name','$last_name', '$password',".
"'$email', '$subjects')") or die(mysql_error());
}
?>
<form id="form1" name="form1" method="post" action="#">

<table width="465" border="0" align="center">
<tr>
<td colspan="2"><p><strong>Administration Creation Tool</strong></p>
<p><em>This allows you to add more users to your website.</em></p>
<p>&nbsp;</p></td>
</tr>
<tr>
<td width="165"><label>Username:</label></td>
<td width="290"><input name="username" type="text" id="username" size="35" /></td>
</tr>
<tr>
<td>First Name:</td>
<td><input name="first_name" type="text" id="first_name" size="35" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input name="last_name" type="text" id="last_name" size="35" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password" id="password" size="35" /></td>
</tr>
<tr>
<td><label>Email Address:</label></td>
<td><input name="email" type="text" id="email" size="35" /></td>
</tr>
<tr>
<td>Account Type:</td>
<td><select name="type" id="type">
<option value="admins" selected="selected">Web Administrator</option>
<option value="teachers">Teacher</option>
<option value="students">Student</option>
<option value="parents">parents</option>
</select></td>
</tr>
<tr>
<td>Subjects (<strong><em>teachers Only</em></strong>)</td>
<td><label>
<textarea name="subjects" cols="35" rows="5" id="subjects">ie. SUB1A,SUB1B</textarea>
</label></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="submit" id="submit" value="Submit" />
</div></td>
</tr>
</table>
</form>

Please note: I have also tried putting in different things into ACTION in the form header (ie. #, the page itself, etc)

Anyhelp would be greatly appreciated!

mlseim
03-05-2010, 05:53 AM
So what you're showing us in post #1 is only a small section of the whole script?
You mention you're only showing us the form? is that correct?

What about the rest of it?

Ndogg
03-05-2010, 06:01 AM
Lol, I dont think this will fix it but I dont see anything wrong. But, in my forms I put the <table></table> outside of the <form></form> :D idk

oxygenproject
03-05-2010, 07:44 AM
This form works fine, the only problem is that on submit it returns home. This is a form in my admin section.. I didn't include the other code as I wouldn't think it has anything relevant to this..

abduraooft
03-05-2010, 10:38 AM
So for example the url for the section i am in is: www.website.com/index.php?m=admin&view=create
Try changing the action of that form to

<form id="form1" name="form1" method="post" action="index.php?m=admin&view=create">

oxygenproject
03-05-2010, 11:48 AM
Thanks for your replies, I am going to try a few things.. I will keep you posted!

PS. Putting in the URL in the ACTION doesnt work either :)

mlseim
03-05-2010, 01:28 PM
The script you showed us in post #1 has nothing wrong with it,
so the problem has to be in the "rest of the script". You'll have to
show us all of it ... and just remove any user or password (sensitive information).

oxygenproject
03-05-2010, 01:36 PM
The website is modular.. There is an admin module which the application hits controller.php (which contains the switches and cases to point the request in the right direction).

I have added a switch in their called password which points it to the password form I have displayed above.

Here is the controller.php:


<?php
//no direct access
defined( '_OS' ) or die( 'Restricted access' );
check_authentication('admins');
// Including the Model for The pages.
include_once(MODULES_PATH.'admin/models/install.php');
include_once(MODULES_PATH.'admin/models/settings.php');
//Getting params
$action = $_GET['action'];
if(!$id)
{$id = $_GET['id'];}
if(!$view)
{$view = $_GET['view'];}
if(!action)
{;}
//Switching with the view
switch ($view)
{
case "modules":
{
switch ($action)
{
case "list":
$module = list_modules();
include(MODULES_PATH.'admin/views/modules/list.php');
break;
case "install":
include(MODULES_PATH.'admin/views/modules/install.php');
break;
case "uninstall":
if(uninstall_module($id))
{echo 'Module Uninstalled';}
break;
}
}
break;
case "settings":
{
$admin = get_admin();
include(MODULES_PATH.'admin/views/settings/settings.php');
break;
}
break;
case "password":
{
$admin = get_admin();
include(MODULES_PATH.'admin/views/settings/password.php');
break;
}
}
?>

mlseim
03-05-2010, 08:32 PM
It looks like "view" has to be one of these three: module, settings, password

If "view" is equal to "module", then "action" needs to be: list, install or uninstall

So I would expect the URL to be like:
<form id="form1" name="form1" method="post" action="index.php?view=module&action=create">

BUT ... there is no "create" ... action can only be list, install or uninstall.
I don't see anything in the switch commands for "create". It's like something is missing.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum