Jump to content

Database information retrieved using form values using PHP


Recommended Posts

Hi guys,

 

Newbie to the forums here....

 

i have just started out using PHP to develop websites and I am having a little problem getting formation from a database. What I am looking to do is, using a form I want to get data from a DB called events depending on variables i.e.location, time or event.

 

So, if the user selects the location on the form - say America - I want to be able to display form data only with the events in America.

 

So, its like .. .Form data (location)  -- form listing (only events from chosen location)

 

I have managed to get a form to populate the database, I can retrieve ALL the form data using a recordset, but I unable to retrieve and display the data, nor am I able to locate a tutorial for this...

 

Any help would be GREATLY APPRECIATED!!!!! 

 

Richie

Link to comment
Share on other sites

Hi  LittleBearer ... thanks so much for your help there... this is what I have so far... 

 

if(Search){
 
mysql_connect("localhost", "root" , "root") or die (mysql_error());
echo "Connected to MySQL <br/> <hr/>";
 
mysql_select_db("users")or die (mysql_error());
echo "conncted to DB users <br/> <hr/>";
 
$query = "SELECT * FROM events";
$result = mysql_query($query) or die (mysql_error());
 
while($row =  mysql_fetch_array($result)){
echo $row['EventName'] . "-" . $row['location'];
echo "<br />";
}
}
else
echo " Found nothing";
?>
 
<form action="SearchTest.php" method="get" id="Search">
<select name="location">
  <option value="sligo">sligo</option>
  <option value="galway">galway</option>
</select>
<input name="submit" type="button" value="submit" />
</form>
 
Results are as follows:



Connected to MySQL 
conncted to DB users 
1111-sligo
1111ccc-galway
Dundalk 10K run-
Fun Run for all -
Richie-
run4444-
Run4Fun-
hhhgggggggggggg-dublin
Runningzzzzz-dublin
   sligo   galway   

 

 

Using the website you gave me, I have altered the code to:

 

<?php
// Make a MySQL Connection
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());
echo "connected.....";
 
// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM events
 WHERE location ='galway'") or die(mysql_error());  
 
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table 
echo $row['location']." - ".$row['EventName'];
?>
 
this displays the first result.....
 
Thanks again
Link to comment
Share on other sites

I have got this far, if anyone would like to add assistance:

 

$location = $_POST['location'];
if(LocationForm){
 
mysql_connect("localhost", "root" , "root") or die (mysql_error());
echo "Connected to MySQL <br/> <hr/>";
 
mysql_select_db("users")or die (mysql_error());
echo "conncted to DB users <br/> <hr/>";
 
$query = "SELECT * FROM events Where location = '$location'";
$result = mysql_query($query) or die (mysql_error());
 
while($row =  mysql_fetch_array($result)){
echo $row['EventName'] . "-" . $row['location'];
echo "<br />";
}
}
else
echo "nothing";
 
?>
 
        <form action="SearchTest.php" method="$_POST['location']" id="LocationForm">
        <select name="location">
          <option value="sligo">sligo</option>
          <option value="galway">galway</option>
        </select>
        <input name="submit" type="button" value="submit" />
        </form>
 
Which returns a blank value as the form is not inputting a value. If I manually input a value for location I can get the required results.

As, I said, I would appreciate any help here...;o))
Link to comment
Share on other sites

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.