Jump to content

Stumped as to why I can't query properly from a form!


Recommended Posts

Hi,

I am fairly new to PHP and I got an issue which I can not solve, I can realy use some help.

 

I created a form that GETs two input variables and spits to another script that I created which querries, fetches and displays data from a DB. The problem is that if I select my first non empty option from (name="from" and name="to') everything works fine, however if I choose a any other option from name="to" other than "LC & I Berlin..." nothing happens on the querry side.

 

Here is my form.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php include("includes/connect.php"); ?>
</head>
<body>

<form action="test2_php.php" method="GET">
Where are you calling from : 
<select name="from">
<option></option>
<option value="LC & I Berlin Office">LC & I Berlin Office</option>
<option value="Germany">Germany</option>
</select>
Where are you calling to: 
<select name="to">
<option></option>
<option value="LC & I Berlin Office">LC & I Berlin Office</option>
<option value="Germany">Germany</option>
<option value="LC & I SAS Douarnenez-Office">LC & I SAS Douarnenez - Office</option>
<option value="LC & I SAS Levallois-Office">LC & I SAS Levallois - Office</option>
<option value="Media5 Europe–Office">Media5 Europe – Office</option>
<option value="Canada">Canada</option>
<option value="United States">United States</option>
<option value="France">France</option>
<option value="My Mailbox">My Mailbox</option>
</select>
<input type="submit" value="Submit">
</form>	
</body>
</html>

End of Code

 

Here is my post script running the querry. I've included comments for ease of reading

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php include("includes/connect.php"); ?>
</head>
<body>
<?php
// Check to see if the values were seleted, if one of them is missing then display message.
if (($_GET["from"] != NULL) AND ($_GET["to"] != NULL)) {
echo "You are calling from: ";
echo $_GET["from"];
echo "<br />";
echo "You are calling to: " ;
echo $_GET["to"] . "<br/>";
} else {
echo "Did you forget something! Please go back and fill in the missing details." . "<br />" ;
}

// Assign the input selection to variables.
$infrom = $_GET["from"];
$outto = $_GET["to"];

// Print out the varibales for testing
echo "<br /> Variable definition check";
echo "<br />from " . $infrom . "<br />";
echo "to " . $outto. "<br /><br />";

// Fetch the results the voip_lagasse DB for rows outto and infrom
$query = "SELECT * FROM voip_lagasse WHERE (outto = '$outto') AND (infrom = '$infrom')"; 
$result = mysql_query($query);

// Test to see if query worked properly
if (!$result)
{
die ("Could not query the database: <br />". mysql_error());
}
// Print out the results from the rows instruct, comment and digit
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                                echo $row[instruct]. '<br />';
	       echo $row[comment]. '<br />'; 						       echo $row[digit]. '<br />';
}

?>
</body>
</html>

END of Code

 

Thank's for your time... cheers

you forgot the quotes in your associative array in the 2nd file at the bottom:

 

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo $row['instruct']. '<br />';
    echo $row['comment']. '<br />';
    echo $row['digit']. '<br />';
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.