PHP, javascript, a dropdown menu, and MSSQL database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
misslilbit02
Forum Newbie
Posts: 9
Joined: Mon Sep 18, 2006 3:57 pm

PHP, javascript, a dropdown menu, and MSSQL database

Post by misslilbit02 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I have a form. That has multiple drop downs but I'm only concerned about one for this issue. the options in this drop down box is blank, submitted, open and closed. The default selected is submitted. I want when the user changes this drop down box that an email is sent to them saying that their work order status has changed and the status to be changed in the database accordingly.

I want  to use javascript and php which I know is possible but I can't get it to work so I resorted to this code which doesn't work. Could someone please help me accomplish this. I maybe going about this all wrong so please help me get my head on straight.
I have things commented out to see if thing work or not. It was for testing purposes.

Code: Select all

<select name="test" onchange="window.location=('reditproblem.php?test=' + this.options[this.selectedIndex].value)">
				<?php
			  if (isset($GET['test']) && $GET['test']=='open')
			  { 
			    mssql_query("UPDATE problems SET status='open' WHERE id='$id2'") or die('Error, update query failed');
			  
			   /*$from = "KCSIT@Keisercollege.edu";
    		   $to = "bnikki@keisercollege.edu";
    		   $subject = "Keiser Support";
    		   $rep_name = "Nikki Barnard";
		       $body = "Hi Nikki, 
  			   You have been assigned a work order.";
			   mail($to, $subject, $body, "From: $from");*/
			  }
			  else if (isset($GET['test']) && $GET['test']=='closed'){
			  mssql_query("UPDATE problems SET status='closed' WHERE id='$id2'") or die('Error, update query failed');
			  
			  }

			   mssql_close($connect);?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

When you submit your form, have you written any code to process the form? The code you posted isn't the correct way to do what your trying to accomplish. For what purpose are you using the javascript?

Divide your page up similar to this..

Top of file

Code: Select all

<?php
if ((!empty($_POST['action'])) && ($_POST['action'] == 'changeStatus'))
{
  // validate the posted data..
  // update the database..
  // send a notification email
  // generate a status message
}
?>
Bottom of file

Code: Select all

<form name="statusChanger" method="post" action="#">
<select name="status">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="hidden" name="action" value="changeStatus" />
<input type="submit" value="Save Status" />
</form>
We won't write the code for you, but we are more than happy to help. That should be a good start. If you need more help I would encourage you to download a copy of the PHP manual. It is searchable and contains many clear examples.
moonmoon
Forum Newbie
Posts: 3
Joined: Sat Feb 02, 2008 1:58 am

Re: PHP, javascript, a dropdown menu, and MSSQL database

Post by moonmoon »

We won't write the code for you, but we are more than happy to help. That should be a good start. If you need more help I would encourage you to download a copy of the PHP manual. It is searchable and contains many clear examples.
its great. :D
Post Reply