Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-05-2010, 03:52 AM   PM User | #1
oxygenproject
New Coder

 
Join Date: Feb 2010
Posts: 81
Thanks: 23
Thanked 0 Times in 0 Posts
oxygenproject is an unknown quantity at this point
My form goes back to the home page!

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 Code:
<?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!
oxygenproject is offline   Reply With Quote
Old 03-05-2010, 04:53 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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?
mlseim is offline   Reply With Quote
Old 03-05-2010, 05:01 AM   PM User | #3
Ndogg
Regular Coder

 
Join Date: Jun 2009
Posts: 272
Thanks: 76
Thanked 2 Times in 2 Posts
Ndogg can only hope to improve
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> idk
Ndogg is offline   Reply With Quote
Old 03-05-2010, 06:44 AM   PM User | #4
oxygenproject
New Coder

 
Join Date: Feb 2010
Posts: 81
Thanks: 23
Thanked 0 Times in 0 Posts
oxygenproject is an unknown quantity at this point
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..
oxygenproject is offline   Reply With Quote
Old 03-05-2010, 09:38 AM   PM User | #5
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
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
Code:
<form id="form1" name="form1" method="post" action="index.php?m=admin&view=create">
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 03-05-2010, 10:48 AM   PM User | #6
oxygenproject
New Coder

 
Join Date: Feb 2010
Posts: 81
Thanks: 23
Thanked 0 Times in 0 Posts
oxygenproject is an unknown quantity at this point
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
oxygenproject is offline   Reply With Quote
Old 03-05-2010, 12:28 PM   PM User | #7
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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).
mlseim is offline   Reply With Quote
Old 03-05-2010, 12:36 PM   PM User | #8
oxygenproject
New Coder

 
Join Date: Feb 2010
Posts: 81
Thanks: 23
Thanked 0 Times in 0 Posts
oxygenproject is an unknown quantity at this point
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 Code:
<?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;
 }
}
?>
oxygenproject is offline   Reply With Quote
Old 03-05-2010, 07:32 PM   PM User | #9
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:55 AM.


Advertisement
Log in to turn off these ads.