Forum Moderators: coopster
first we need to accept and insert the information
second we need to figure out how to display it
let's concentrate on the first one first
do you want to use a database?
if so is it mysql?
you would then need to create a database to store the information
then you would need to create a form to accept user input so you can insert that input into your database
There are some useful threads regarding using php and mysql in the PHP Forum Library [webmasterworld.com] that may help some
as far as setting up the form that is just straight html then you set the action in your form tag to target your processing script which will handle input validation and inserting the information into the database.
do you have the html form created yet?
1. they use .php for every file whether there is any php in it or not
2. the form action posts to itself (something I don't recommend and I think is a bad idea)
3. they do something with php on the page which may, or may not, be related to the form
take a look at this thread
Basics of extracting data from MySQL using PHP [webmasterworld.com] msg 5
I realize you are inserting and not extracting at the moment but steps 1, 2 and 3 are the same anytime you are interacting with mysql.
connect, select db, query
what happens from there is the only difference
in this case as long as the query doesn't fail you are done.
<input id="Trip" type="submit" name="screen" value="Trip" />
<input id="Participants" type="submit" name="screen" value="Participants" />
<input id="Body" type="submit" style="font-size:smaller;width:7em;" name="screen" value="Body" onclick="self.clicked=this.value" />
<input id="Proofread" type="submit" style="font-size:smaller;width:7em;" name="screen" value="Proofread" onclick="self.clicked=this.value" />
<input id="Submit" type="submit" style="font-size:smaller;width:7em;" name="screen" value="Submit" onclick="self.clicked=this.value" />
<input id="Reset" type="submit" style="font-size:smaller;width:7em;" name="screen" value="Reset" />
<input type="hidden" name="responsepage" value="index.php" />
<input type="text" size="29" maxlength="50" name="triplocation" value="" />
Condition:
<select name="condition" size="1">
Difficulty:
<select name="pickClass" size="1">
Organizer:
<input type="text" size="29" maxlength="50" name="leadr" value="" />
Painted gauge:
<input type="text" size="5" name="rGaugeFT" value="" /> ft.
Start:<br />
<select name="pickMonth" size="1" onchange="setDOW(true)">
<select name="pickDay" size="1" onchange="setDOW(true)">
<select name="pickYear" size="1" onchange="setDOW(true)">
<select name="pickDays" size="1" onchange="setDOW(true)">
USGS gauge:
<input type="text" size="5" name="iGaugeFT" value="" /> ft
<input type="text" size="5" name="iGaugeCFS" value="" /> cfs
Finish:
<select name="pickMonth1" size="1" onchange="setDOW(false)">
<select name="pickDay1" size="1" onchange="setDOW(false)">
<select name="pickYear1" size="1" onchange="setDOW(false)">
<select name="pickDays1" size="1" onchange="setDOW(false)">
USGS Gauge Location:
<input type="text" name="iGaugeID" value="" size="29" maxlength="50" />
<input type="text" size="29" maxlength="50" name="author" value="" /> </td>
<input type="text" size="29" maxlength="50" name="email" value="" /> </td>
<input type="hidden" name="k1" value="" />
<input type="hidden" name="k2" value="" />
<input type="hidden" name="oc1" value="" />
<input type="hidden" name="oc2" value="" />
<input type="hidden" name="c1" value="" />
<input type="hidden" name="c2" value="" />
<input type="hidden" name="air1" value="" />
<input type="hidden" name="raft" value="" />
<input type="hidden" name="rpt" value="" />
</form>
Do I need a config.php file? I am really new to this but I am determined to make it work somehow.
[edited by: jatar_k at 7:23 pm (utc) on Oct. 18, 2005]
[edit reason] trimmed extra code [/edit]
not at all, your script ill take the user input values and use those values to build a mysql insert query. That query will have to use the proper column names. The script will know both.
>> step 3
build your INSERT query [dev.mysql.com]
don't worry too much as I imagine that page is hard to understand but you should familiarize yourself with the mysql manual as well as with the PHP manual [php.net]
insert queries need to follow this form
INSERT INTO tablename (column1,column2,column3) VALUES ('value1','value2','value3')
these lists of columns can be as long as you want, they are not limited to only three. The location of the column in the first part of the query must match the location of the corresponding value in the VALUES portion of the query. It is a very common mistake to have the wrong number of values/columns or even to put them in the wrong order.
We then need a list of the columns and the names of the form elements that correspond to the columns
could you post that? not a ton of code, just the column names and what the form element name is that corresponds to it
dbcolumnname = formelementname
;)
<?
$host = "localhost";
$user = " ";
$pass = " ";
$dbname = " ";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$sql = "select * from tct where id=" . $_POST['manufacturer'] . " and manufacturer='" . $_POST['manufacturer'] . "'";
echo $sql;
?>
$sql = "select * from tct where id=" . $_POST['manufacturer'] . " and manufacturer='" . $_POST['manufacturer'] . "'";
echo $sql;
just don't worry about that bit right now
and take a look at your code post above, I ripped out all the unimportant stuff and left the elements only
so that will make it easier to map formfields to dbcols
SELECT * FROM tablename
steps involved are
1. connect to db
2. select db
3. construct query
$sql = 'SELECT * FROM tablename';
4. send query to mysql
$result = mysql_query($sql) or die ('<p>select died: ' . mysql_error());
5. extract rows
while ($row = mysql_fetch_array($result)) {
// formatting goes in here in the format of $row['colname']
// to access individual columns
}
inside your while loop is where you format your ouput, for a test to take a look at what the output is like you could put a print_r inside your while loop
$counter = 1;
while ($row = mysql_fetch_array($result)) {
echo "<p>$counter: <pre>";
print_r($row);
echo '</pre>';
$counter++;
}
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$sql = 'SELECT * FROM tripreport';
$counter = 1;
while ($row = mysql_fetch_array($result)) {
echo "<p>$counter: <pre>";
print_r($row);
echo '</pre>';
$counter++;
}