Forum Moderators: coopster

Message Too Old, No Replies

cant figure out what the error is

submitting form data to a database

         

surrealillusions

2:43 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



I get the error from this line here

$query = "INSERT INTO user (host, Name, Email, Comments, select_priv, insert_priv, update_ priv) VALUES ('http://www.example.com', '$name', '$email', '$message', 'Y', 'Y', 'Y')";
mysql_query($query) or die('Error, insert query failed');

As it comes up with "Error, insert query failed" on the page. So, the script is 'working', as i've eliminated all the parse errors and such, but i'm not sure why this isn't working.

name, email and comments are the only things on the form to submit. And i'm doing this on my website, not locally. So have i got everything right? This is the first time i've attempted a thing like this...

thanks

:)

jatar_k

8:09 pm on Jan 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that's usually a looping/counting problem

what's your display code?

surrealillusions

8:17 pm on Jan 23, 2008 (gmt 0)

10+ Year Member



Heres what i use to output the information

<?php
include 'database/config.php';
include 'database/opendb.php';
// collect data from table
$data = mysql_query ("SELECT * FROM guestbook")
or die (mysql_error());
$info = mysql_fetch_array ( $data );

while ($info = mysql_fetch_array( $data ))
{
echo "<p>Name: " .$info['Name'] . "</p>";
echo "<p>Comment: " .$info['Comments'] . "<br />-------------------------------</p>";
}
?>

:)

jatar_k

11:46 pm on Jan 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



this is why

$info = mysql_fetch_array ( $data );

while ($info = mysql_fetch_array( $data ))

take out the first one

surrealillusions

8:13 pm on Jan 24, 2008 (gmt 0)

10+ Year Member



Thanks..but its not doing the trick..i would like the most recent result on top.

:)

jatar_k

8:23 pm on Jan 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well if you remove that line you will get all the results, when you call mysql_fetch_array twice before you output once, that's why it doesn't show the first result

normally you would use ORDER BY in your select query to get them in some kind of order but you don't have anything to order them by as of yet ;)

date or id would work

surrealillusions

8:57 pm on Jan 24, 2008 (gmt 0)

10+ Year Member



Thanks

However i cant get order by to work. I've searched for various tutorials around the net on order by, but none seem to work for me.

When i'm not getting parse errors and the like, i get this -

Unknown column 'date' in 'order clause'

From this line

$data = mysql_query ("SELECT DATE(CURRENT_TIMESTAMP) FROM guestbook ORDER BY date")

Why is this wrong? Do i need to set the date and time first?
Different tutorials write different things on how to order the results. Or do i need to set the date when writing the form data to the database and then order the results using

SELECT * FROM guestbook ORDER BY date

:)

jatar_k

10:39 pm on Jan 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you need to order it by a column but you have nothing chronological to order them by hence why I wrote

normally you would use ORDER BY in your select query to get them in some kind of order but you don't have anything to order them by as of yet

you did mention adding a date column, though even a unique auto incremented id would work (both of which you would need to add to the table)

as it stands you have name, email and comment. None of these give you anything much to order by except alphabetical.

This 37 message thread spans 2 pages: 37