Jump to content

simple form


zsmall

Recommended Posts

I've read all the w3 tutorials and tried my hardest to understand php/mysql but it seems I have no idea how to go about starting this very simple request.

 

I simply want to save the input data from the simple html form I've created (attached) and THEN output it on my website.

 

<html>
<title> Add An Event </title>
<body>

<form name="add_event" action="add_event.php" method="post">
   <fieldset>
     Event Name:
     <input type="text" id="event_name">
     Event Venue:
     <input type="text" id="event_venue">
     </br>
     Date of Event (Format DD/MM/YYYY)
      DD:<select id="DD">
        <option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select id="MM">
        <option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
<select id="YYYY">
        <option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
</select>
     <br>
     </br>
     COST! How much are we going to have to pay? £
     <input type="text" rows="1" cols="5" id="event_cost">
     OR is it a free event?
     <input type="checkbox" id="event_cost" value="free">
     <br>
     What kind of music will there be at this event?
     <br>
     Indie<input type="checkbox" id="event_type" value="indie">
     Rock<input type="checkbox" id="event_type" value="rock">
     Cheese<input type="checkbox" id="event_type" value="cheese">
     <br>
     Drum n Bass<input type="checkbox" id="event_type" value="dnb">
     Dubstep/Grime<input type="checkbox" id="event_type" value="dubstep">
     Roots & Culture<input type="checkbox" id="event_type" value="roots">
     <br>
     Techno<input type="checkbox" id="event_type" value="techno">
     Electro<input type="checkbox" id="event_type" value="electro">
     House<input type="checkbox" id="event_type" value="house">
     
     <br>
     <br>
     What time will the event be starting?
       HH:<select id="start_hours">
        <option value="00">00</option> 
        <option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
</select>
:MM<select id="start_minutes">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select>
     <br>
     <br>
     What time will the event be finishing?
       HH:<select id="fin_hours">
        <option value="00">00</option> 
        <option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
</select>
:MM<select id="fin_minutes">
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
</select>
     <br>
     <br>
     Tell us a little about the event. This will be displayed<br>
     on the site to our users, so make it good:
     <br>
     <textarea rows="4" cols="40" id="user_desription">
     </textarea>
   </fieldset>
     <input type="submit" value="Submit">
</form>
</body>
</html>

Link to comment
Share on other sites

sdi126 asked you a question that we kind of need to know the answer of before we help you...

 

Is the code you posted add_event.php?  If not, show us the code for that page as well.

Link to comment
Share on other sites

You can go about this in 2 way's

 

1. After you submit the data to add_event.php

you can have the content get stored into your mysql database via add_event.php by id .

Then on your site you would need to pull the data by connecting to database and asking mysql for the info.

 

2. you can use the open write function in php to open a .txt and write the form content to it.

the add_event.php should be able to set your passed form fileds into variables of you choice .

 

You need a bit of php knowledge from the sounds of it! GOOGLE is your friend. 

Link to comment
Share on other sites

I'm currently trying to write this part of the website. Somebody else is putting the variables mentioned in the html form above INTO the database. I just have no idea how to go around GETTING those variables out of the mysql database and displaying them on a webpage, if you get what I mean?

 

I'm pretty confused right now and I haven't really written any coding of the php yet (anything ground), I just need somewhere to start.

 

You can go about this in 2 way's

 

1. After you submit the data to add_event.php

you can have the content get stored into your mysql database via add_event.php by id .

Then on your site you would need to pull the data by connecting to database and asking mysql for the info.

 

2. you can use the open write function in php to open a .txt and write the form content to it.

the add_event.php should be able to set your passed form fileds into variables of you choice .

 

You need a bit of php knowledge from the sounds of it! GOOGLE is your friend.

 

Just read this post, we're basically doing it using method 1. And yeah you're right, I need some php knowledge, will keep googling for more help!

Link to comment
Share on other sites

OK sounds like you just need to create the "add_event.php" page to process/output the selected information from the form you posted.

 

1) In your form you need names for these text fields:

 

     Event Name:
     
     Event Venue:
     
.
.
.
     
     

 

 

2) Here's how you would grab the values from the form after it is submitted:

 

add_event.php

foreach($_POST AS $key => $value)
{
   $$key = $value;
   echo "Created variable: " . $key . " with value => " . $value;
}
?>

 

 

Link to comment
Share on other sites

Right heres the php stuff I wrote, I'm not sure if its right. I just need to get the values taken from the mysql and display them using html. I'm still not sure how to do that...

<?php

$dbhost = 'host';
$dbuser = 'user';
$dbpass = 'pass';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = 'database';
mysql_select_db($dbname);

include 'add_night.php';
include 'night_table.php';

$query  = "SELECT name, subject, message FROM contact";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "night_name :{$row['name']} <br>" .
         "night_venue : {$row['subject']} <br>" .
         "date : {$row['message']} <br>";
	 "night_cost : {$row['message']} <br>";
	 "night_type : {$row['message']} <br>";
	 "start_hours : {$row['message']} <br>";
	 "start_minutes : {$row['message']} <br>";
	 "fin_hours : {$row['message']} <br>";
	 "fin_minutes : {$row['message']} <br>";
	 "user_description : {$row['message']} <br>";
}

include 'closedb.php';
?>

 

 

I got this off an online question. Is this the right way to go about writing it?

 

<html>
<head><title>()</title></head>
<body>
<?php
$db="mydatabase";
$link = mysql_connect("localhost");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT * FROM Nights" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>
</body>
</html>

Link to comment
Share on other sites

So what exactly is outputted to the browser?  What exactly is wrong?

 

...How does this relate to your original question?

 

If you're just using the associative return array then call it with mysql_fetch_assoc(), if  you need numerical indices use the other way.  Also add the or die(mysql_error()); at the end of the query call, like this:

 

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_assoc($result))

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.