It is currently Thu Mar 28, 2024 4:02 am



Reply to topic  [ 3 posts ] 
PHP + Drop down menu's. 
Author Message
Minor Diety
User avatar

Joined: Fri Apr 11, 2003 5:09 pm
Posts: 4003
Location: Walsall, West Mids, UK
Reply with quote
Post 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>

_________________
Games to complete:
GTA IV [100%] (For Multiplayer next!)
Fallout 3 [50%]
Rock Band [35%]
http://www.cafepress.com/SmeepProducts


Fri Sep 16, 2005 12:35 pm
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
Perhaps
Code:
<center>' .location .'<br />

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


Try using pastebin for big paste jobs like this.

http://pastebin.com/365774


Fri Sep 16, 2005 1:18 pm
Profile YIM WWW
Minor Diety
User avatar

Joined: Fri Apr 11, 2003 5:09 pm
Posts: 4003
Location: Walsall, West Mids, UK
Reply with quote
Post 
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*

_________________
Games to complete:
GTA IV [100%] (For Multiplayer next!)
Fallout 3 [50%]
Rock Band [35%]
http://www.cafepress.com/SmeepProducts


Fri Sep 16, 2005 1:31 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.