Connect to database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
khan
Forum Newbie
Posts: 2
Joined: Wed May 19, 2010 2:13 am

Connect to database

Post by khan »

Hi, I just started learning and looking for help.
On one of my computer the following code is working; php files in c:apache\htdocs\TTSystems and database in c:apache\mysql\data\TTSystems.
I installed Xampp on a new computer. Copied all php files in c:xampp\htdocs\TTSystems, and database files in c:xampp\mysql\data\TTSystem.
Now my following code is populating the list box with the values retreived from table "TroppoGroup", but not printing the selected option (Group_Selection). Please help me!!!

Code: Select all

<form name="form1" method="post" action="file:htdoc/Troppo_Screen.php">
          <p>&nbsp;</p>
          <p align="center"><font face="Century Gothic">Function Types</font> 
            <select name="Group_Selection">
              <option value></option>
              <?php
				$db = mysql_connect("localhost", "abc", "xyz");

				mysql_select_db("mnop",$db);

				$resultID = mysql_query("Select Group_options FROM TroppoGroup", $db);


				while ($row = mysql_fetch_row($resultID))
					{
    					foreach ($row as $field)
      						{
    
        						print "<option value = $field> $field";
           
      						} 

   						print "</option>";

					}

				?>
            </select>
          </p>
          <p align="center"> 
            
			<input type="submit" name="Submit" value="Select">
          </p>
        </form>
		<font size="2" face="Century Gothic">
        <?php
		   if ($Group_Selection == "Under-5-years-Troppo")
		   		{
		       		$dash = "-";		
					$Group_Selection = str_replace($dash, " ",$Group_Selection);
					print "<b>$Group_Selection.</b><br>";
Last edited by Benjamin on Wed May 19, 2010 4:12 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Connect to database

Post by Benjamin »

It looks like a register_globals issue. You'll need to use the $_GET and $_POST superglobals.

http://www.php.net/manual/en/language.v ... lobals.php
http://php.net/manual/en/security.globals.php
khan
Forum Newbie
Posts: 2
Joined: Wed May 19, 2010 2:13 am

Connect to database

Post by khan »

[text]Thanks a lot! I inseted "Group_Selection=$_POST['Group_Selection'];" in the 2nd form and it started working. Thanks again [/text]
Post Reply