Forum Moderators: coopster

Message Too Old, No Replies

MYSQL not saving input data?

The main page can read the mysql, but mysql shows blank..

         

criTiKAL

5:39 am on Sep 10, 2008 (gmt 0)

10+ Year Member



Ok, I know for a fact that my index can read the mysql data, because I have tested it by manually adding data into the fields.. Now, when I try to do it through forms like making a post, the mysql database is not saving the data that I input? Here is the code.

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 &amp; 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]

omoutop

8:12 am on Sep 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



On the add_post.php try the following:

$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

criTiKAL

1:53 pm on Sep 10, 2008 (gmt 0)

10+ Year Member



I had done what you said. I hit submit after I entered test into the fields and this is what I got on the add_post page(after I clicked submit from the create_topic.php)

Array
(
[PostRequest] => Post Request
)

Successful!
Back to Container Requests

But still no information being saved into the MySql?

omoutop

2:19 pm on Sep 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



nope wrong....
accordin to original code you expect to see at least 20+ post data... you only saw one - or did you delete the rest for convenience?

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

criTiKAL

2:51 pm on Sep 10, 2008 (gmt 0)

10+ Year Member



I did that, and still posted the same information. :/

criTiKAL

7:30 pm on Sep 10, 2008 (gmt 0)

10+ Year Member



Thats what I was thinking, but I have a working CMS that was coded from webspell on the same mysql and server host.. I cannot figure this out.. :/

criTiKAL

11:58 pm on Sep 11, 2008 (gmt 0)

10+ Year Member



Anyone else got any suggestions?

sonjay

12:17 am on Sep 12, 2008 (gmt 0)

10+ Year Member



Well, you don't have any form fields. This is your entire form:

<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.

criTiKAL

7:20 am on Sep 13, 2008 (gmt 0)

10+ Year Member



Ok, I get what your saying, but how do I go upon making them all into forms? I am pretty much teaching myself how to do this, without any books, you guys are my only help at the moment. Do I make every single entry its own form? Or is there an easier way of doing that?

criTiKAL

8:08 am on Sep 13, 2008 (gmt 0)

10+ Year Member



Nevermind, I am totally getting it now! Thanks! Now I need to set up an edit page, and a delete deal..