Jump to content


Photo

resetting $_POST variables


  • Please log in to reply
5 replies to this topic

#1 nothix

nothix
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 09 April 2006 - 06:14 PM

I have my page setup with selects populated from a mySQL db to allow the user to select an instructor, course, day, time, room, and max students. Once all have been selected, 2 submit buttons load, 1 allowing the user to submit the data to the db inserting the information into the class table, and the other one resetting the page, basically setting all the selects to the first option(which is something like "Select Instructor") and setting all of the ___selected=0. I've tried many different ways to do this but non of them seemed to have any effect on the page. Also, my submit does not add the tuple to the table, and I'm not sure why that is either. Thanks for any help in advance, and sorry for the ugly format.


<?php
....
....
....
 if(($instructorselected==1)&&($courseselected==1)&&($dayselected==1)&&
     ($timeselected==1)&&($roomselected==1)&&($maxselected==1))
  {
    print "<input type=submit value='YES(submit)' onClick=addClass() /> or ";
    print "<input type=submit value='NO(reset)' onClick=resetPage() /> <br>";
  }

function resetPage(){
  //$instructorselect="";
  //$instructorssn = "";
  //$coursenum = "";
  //$dayletter = "";
  //$timenum = "";
  //$roomnum = "";
  //$maxnum6 = "";
  //print "<script LANGUAGE=\"Javascript\">instructorselect.reset()</SCRIPT>";
  //print "<form method=POST action=$PHP_SELF>";
  //print "\'Javascript:submit()\'";
};

function addClass(){
  $sectionnum = mysql_query ("SELECT COUNT(*) FROM class WHERE course=$coursenum") or die(mysql_error());
  mysql_query ("INSERT INTO class VALUES ('$sectionnum','$coursenum','$dayletter','$timenum','$roomnum','$maxnum','$instructorssn')") or die(mysql_error());
};

?>


#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 09 April 2006 - 06:27 PM

Why have 2 submit buttons?

have one to submit the requested data to the database and replace the other submit button with a nice and simple reset button?

<input type="reset"> should do the trick.
follow me on twitter @PHPsycho

#3 nothix

nothix
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 09 April 2006 - 06:39 PM

[!--quoteo(post=363065:date=Apr 9 2006, 01:27 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 9 2006, 01:27 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Why have 2 submit buttons?

have one to submit the requested data to the database and replace the other submit button with a nice and simple reset button?

<input type="reset"> should do the trick.
[/quote]

I'm afraid I've tried the reset button and it did nothing. It seems like no matter what I put in my onClick functions nothing happens besides the page being reloaded. Is my syntax incorrect, or is there a better way to do the submit and reset?

PS thanks for the quick reply

#4 nothix

nothix
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 09 April 2006 - 07:05 PM

It seems that doing something as simple as this:
print "<input type=submit value='NO(reset)' onClick='$instructorselected=0' /> <br>";
doesnt even work. It should set $instructorselected=0 and reload the page, not allowing the submit buttons to be shown any more.


Is there simply a way to force a select to a certain value?

such as

print "<select name=testselect>";
print "<option value=1>1</option>";
print "<option value=2>2</option>";
print "<option value=3>3</option>";
print "</select>";

$testselect.selected = 1;


#5 nothix

nothix
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 09 April 2006 - 08:52 PM

can anyone help me with my problem? I've been trying to figure this out for hours =(

#6 nothix

nothix
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 10 April 2006 - 02:21 PM

bump




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users