ClanKiller.com
http://forums.clankiller.com/

PHP + Drop down menu's.
http://forums.clankiller.com/viewtopic.php?f=24&t=1423
Page 1 of 1

Author:  Mole [ Fri Sep 16, 2005 12:35 pm ]
Post subject:  PHP + Drop down menu's.

Lets just say, I have a HTML form, with a drop down menu.

I pass the stuff in the menu, to the database just fine.

But it doesn't pull from the database at the other end (Read here It says, "location" instead of the info in the field.

Here's the form:

Code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />

<title>Paint-Zone</title>
</head>

<body class="main" topmargin="0" leftmargin="0">

<div id="banner">

<? include("banner.php"); ?>

</div>

<div id="bodymenu">
<? include("menutable.php"); ?>
</div>

<div id="bodycontent">


<form action="fieldconfirm.php" method="post">
Enter the name of the field: <input type="text" name="name" /><br />
Enter the location of the field:
<select name="location"><br />
<option value="Birmingham">Birmingham</option>
<option value="Manchester">Manchester</option>
<option value="London">London</option>
<option value="North Yorkshire">North Yorkshire</option>
</select><br />
Enter the phone number of the field: <input type="text" name="number" /><br />
Enter the email address of the field: <input type="text" name="email" /><br />
<label>Type a short summary:<br />
<textarea name="summary" rows="10" cols="40">
</textarea></label>
<input type="submit" value="Go!"/>
</form>



</div>





</body>
</html>


Here's the Confirm page

Code:
 <html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />

<title>Paint-Zone</title>
</head>

<body class="main" topmargin="0" leftmargin="0">

<div id="banner">

<? include("banner.php"); ?>

</div>

<div id="bodymenu">
<? include("menutable.php"); ?>
</div>

<div id="bodycontent">

<?php
$dbcnx = @mysql_connect('ahem', 'ahem', 'ahem');
if (!$dbcnx) {
 echo 'Unable to connect to the ' .
     'database server at this time.' ;
 exit();
}



// Select the database
if (!@mysql_select_db('paintzone')) {
 exit('Unable to locate the ' .
     'database at this time.');
}

// Write to the fields
   
if (isset($_POST['summary'])) {
             $name= addslashes(htmlentities($_POST['name']));
            $location= addslashes(htmlentities($_POST['location']));
            $number= addslashes(htmlentities($_POST['number']));
            $email= addslashes(htmlentities($_POST['email']));
            $summary= addslashes(htmlentities($_POST['summary']));
$sql = "INSERT INTO arena(name, location, number, email, summary) VALUES ('$name', '$location', '$number', '$email', '$summary')";
   if (@mysql_query($sql)) {
     echo 'The field has been added';
         echo "$location";
       
   } else {
     echo '<p>Error adding submitted review: ' .
        mysql_error() . '</p>';
   }
 }





// Query All entries
 $result = @mysql_query('SELECT * FROM arena');
 if (!$result) {
   echo ('<p>Error performing query: ' .
       mysql_error() . '</p>');
 }
?>


</div>





</body>
</html>


And here's the output page

Code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />

<title>Paint-Zone</title>
</head>

<body class="main" topmargin="0" leftmargin="0">

<div id="banner">

<? include("banner.php"); ?>

</div>

<div id="bodymenu">
<? include("menutable.php"); ?>
</div>

<div id="bodycontent">

<?php
$dbcnx = @mysql_connect('stuff', 'stuff', 'stuff');
if (!$dbcnx) {
 echo 'Unable to connect to the ' .
     'database server at this time.' ;
 exit();
}



// Select the database
if (!@mysql_select_db('paintzone')) {
 exit('Unable to locate the ' .
     'database at this time.');
}




// Query All entries
 $result = @mysql_query('SELECT * FROM arena');
 if (!$result) {
   echo ('<p>Error performing query: ' .
       mysql_error() . '</p>');
 }
 else
 {


print $_POST['location'];

                    $number_of_records = mysql_num_rows($result);
                    $name = mysql_result($result,$number_of_records-1,"name");
                    $location = mysql_result($result,$number_of_records-1,"location");
                    $number = mysql_result($result,$number_of_records-1,"number");
                    $email = mysql_result($result,$number_of_records-1,"email");
                    $summary = mysql_result($result,$number_of_records-1,"summary");
           
            echo '<table width="600" cellspacing="0" border="2"><tr><td><center>' .$name .'</center></td><td><center>' .location .'<br /></center></td></tr><tr><td colspan="2"><center> ' .$number .' <br /><br /></center></td></tr><tr><td colspan="2"><center>' .$email .'</center></td></tr><tr><td colspan="2"><center>' .$summary .'</center></td></tr></table><br /><br /><br />';

                    $name = mysql_result($result,$number_of_records-2,"name");
                    $location = mysql_result($result,$number_of_records-2,"location");
                    $number = mysql_result($result,$number_of_records-2,"number");
                    $email = mysql_result($result,$number_of_records-2,"email");
                    $summary = mysql_result($result,$number_of_records-2,"summary");
                   
            echo '<table width="600" cellspacing="0" border="2"><tr><td><center>' .$name .'</center></td><td><center>' .location .'<br /></center></td></tr><tr><td colspan="2"><center> ' .$number .' <br /><br /></center></td></tr><tr><td colspan="2"><center>' .$email .'</center></td></tr><tr><td colspan="2"><center>' .$summary .'</center></td></tr></table><br /><br /><br />';

           
                    $name = mysql_result($result,$number_of_records-3,"name");
                    $location = mysql_result($result,$number_of_records-3,"location");
                    $number = mysql_result($result,$number_of_records-3,"number");
                    $email = mysql_result($result,$number_of_records-3,"email");
                    $summary = mysql_result($result,$number_of_records-3,"summary");
           
            echo '<table width="600" cellspacing="0" border="2"><tr><td><center>' .$name .'</center></td><td><center>' .location .'<br /></center></td></tr><tr><td colspan="2"><center> ' .$number .' <br /><br /></center></td></tr><tr><td colspan="2"><center>' .$email .'</center></td></tr><tr><td colspan="2"><center>' .$summary .'</center></td></tr></table><br /><br /><br />';
}
?>




</div>





</body>
</html>

Author:  Pig [ Fri Sep 16, 2005 1:18 pm ]
Post subject: 

Perhaps
Code:
<center>' .location .'<br />

should be
Code:
<center>' .$location .'<br />


Try using pastebin for big paste jobs like this.

http://pastebin.com/365774

Author:  Mole [ Fri Sep 16, 2005 1:31 pm ]
Post subject: 

Yeah, I figured it out just now with some help - though both me and pev are cirtain the I had the $ in there originally, but Hey, I guess not.

Thanks for that link, nice tool that *bookmarks*

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/