Forum Moderators: coopster
ADD_POST.PHP (this is the .php file that is used after I hit submit from the create_post.php)
-I left the MYSQL database info out of this post.
-----------------------------------------------------------------------------------------
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get data that sent from form
$datesched=$_POST['datesched'];
$unitnum=$_POST['unitnum'];
$type=$_POST['type'];
$containersize=$_POST['containersize'];
$doors=$_POST['doors'];
$cc=$_POST['cc'];
$received=$_POST['received'];
$completed=$_POST['completed'];
$other=$_POST['other'];
$contractor=$_POST['contractor'];
$orderedby=$_POST['orderedby'];
$jobcontact=$_POST['jobcontact'];
$phone=$_POST['phone'];
$jobname=$_POST['jobname'];
$address=$_POST['address'];
$city=$_POST['city'];
$directions=$_POST['directions'];
$conrentalfee=$_POST['conrentalfee'];
$delfee=$_POST['delfee'];
$pickupfee=$_POST['pickupfee'];
$relfee=$_POST['relfee'];
$extra=$_POST['extra'];
$datedelivered=$_POST['datedelivered'];
$eqdel=$_POST['eqdel'];
$datetime=date("d/m/y h:i:s"); //create date time
$sql="INSERT INTO forum_question(datesched, unitnum, type, containersize, doors, cc, received, completed, other, contractor, orderedby, jobcontact, phone, jobname, address, city, directions, conrentalfee, delfee, pickupfee, relfee, extra, datedelivered, eqdel, topic, detail, name, email, datetime)VALUES('$datesched', '$unitnum', '$type', '$containersize', '$doors', '$cc', '$received', '$completed', '$other', '$contractor', '$orderedby', '$jobcontact', '$phone', '$jobname', '$address', '$city', '$directions', '$conrentalfee', '$delfee', '$pickupfee', '$relfee', '$extra', '$datedelivered', '$eqdel', '$datesched', '$detail', '$name', '$email', '$datetime')";
$result=mysql_query($sql);
if($result){
echo "Successful!<BR>";
echo "<a href=forum_main.php>Back to Container Requests</a>";
}
else {
echo "ERROR";
}
mysql_close();
?>
-----------------------------------------------------------------------------------------
Here is my forum_main.php(this is supposed to display the input data. Unfortunately it doesn't unless you put the data in through the database manually.)
-----------------------------------------------------------------------------------------
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
}
.style2 {color: #FFFFFF}
.style3 {
font-size: 24px
}
-->
</style>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="#006600">
<td colspan="7" align="right"><div align="center" class="style1 style3">GBR & CONSTAR CONTAINER REQUESTS </div></td>
</tr>
<tr bgcolor="#006600">
<td colspan="7" align="right"><form name="form1" method="post" action="add_post.php">
<label>
<div align="left">
<input type="submit" name="PostRequest" id="PostRequest" value="New Container Request">
</div>
</label>
</form></td>
</tr>
<tr bgcolor="#006600">
<td width="5%" align="center"><span class="style1">#</span></td>
<td width="19%" align="center"><span class="style2"><strong>Date Scheduled</strong></span></td>
<td width="17%" align="center"><span class="style2"><strong>Contractor</strong></span></td>
<td width="14%" align="center"><span class="style2"><strong>Size</strong></span></td>
<td width="15%" align="center"><span class="style2"><strong>Type</strong></span></td>
<td width="13%" align="center"><span class="style2"><strong>Recieved</strong></span></td>
<td width="17%" align="center"><span class="style2"><strong>Completed</strong></span></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr bgcolor="#006600">
<td><div align="center" class="style2"><? echo $rows['id']; ?></div></td>
<td><div align="center" class="style2"><? echo $rows['datesched']; ?></div></td>
<td><div align="center" class="style2"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['contractor']; ?></a><BR>
</div></td>
<td align="center"><div align="center" class="style2"><? echo $rows['containersize']; ?></div></td>
<td align="center"><div align="center" class="style2"><? echo $rows['type']; ?></div></td>
<td align="center"><div align="center" class="style2"><? echo $rows['received']; ?></div></td>
<td align="center"><div align="center" class="style2"><? echo $rows['completed']; ?></div></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
</table>
-----------------------------------------------------------------------------------------
ALL MYSQL database information was not added for security reasons.
Here is my test site, its like a simple forum. I'm doing this for my work.
TEST SITE: <snip>
I also want to implement an Edit Post feature and a Delete function.. I want a "Are you sure you want to delete this request?" confirmation, but I have no idea how to code these.. I got the buttons, but don't know how to code the functions...
[edited by: criTiKAL at 5:56 am (utc) on Sep. 10, 2008]
[edited by: eelixduppy at 6:02 am (utc) on Sep. 10, 2008]
[edit reason] no URLs, please [/edit]
$result=mysql_query($sql) or die(mysql_error());
This will throw an error is something goes wrong.
echo "<pre>";
print_r($_POST);
echo "</pre>";
this will check what kind of data you submit via post
If all seems well, try to echo your sql and see what you get.
If all seems well, run same query directly in your phpmyadmin
Array
(
[PostRequest] => Post Request
)
Successful!
Back to Container Requests
But still no information being saved into the MySql?
Put
echo "<pre>";
print_r($_POST);
echo "</pre>";
above all else (on the very top of page) and see your array.
If all post data are coming through correct, then the problem lies in your sql
<form name="form1" method="post" action="add_post.php">
<label>
<div align="left">
<input type="submit" name="PostRequest" id="PostRequest" value="New Container Request">
</div>
</label>
</form> Of course $_POST['PostRequest'] is the only data submitted -- you don't have anything else in your form. You need to create a form field (text input, checkbox, radio button, etc.) for each bit of data you want to submit.