Page 1 of 1

making a insert fields....

Posted: Tue Mar 01, 2005 2:41 am
by Smackie
alright i just got up the poem part that i wanted well im making a place where the users can go to submit there poems and well i just used my signup script and edited it alil bit it works expect for adding stuff to the database can someone find what im doing wrong??

code

Code: Select all

<?php

// dbConfig.php is a file that contains your
// database connection information. This
// tutorial assumes a connection is made from
// this existing file.
include ("dbConfig.php");


// ==== Input validation and PHP dBase code ===============================
//
// ========================================================================

if ( $_GET&#1111;"op"] == "poe" )
	&#123;
	$bInputFlag = false;
	foreach ( $_POST as $field )
		&#123;
		if ($field == "")
			&#123;
			$bInputFlag = false;
			&#125;
		else
			&#123;
			$bInputFlag = true;
			&#125;
		&#125;
	// If we had problems with the input, exit with error
	if ($bInputFlag == false)
		&#123;
		die( "Problem with your registration info. "
			."Please go back and try again.");
		&#125;

	// Fields are clear, add user to database
	//  Setup query
	$q = "INSERT INTO `dbpoems` (`username`,`poem`) "
		."VALUES ('".$_POST&#1111;"username"]."', "
		."poem('".$_POST&#1111;"poem"]."'), ";
		//  Run query
	$r = mysql_query($q);
	
	// Make sure query inserted user successfully
	if ( !mysql_insert_id() )
		&#123;
		die("Error: You stink to much so you didnt get put in there =P.");
		&#125;
	else
		&#123;
		// Redirect to thank you page.
		Header("Location: poems.php");
		&#125;
	&#125; // end if


// ==== Thank you page ====================================================
// 
// ========================================================================
elseif ( $_GET&#1111;"op"] == "thanks" )
	&#123;
	echo "<h2>Thanks for submitting your poems at Haunted Graveyard!</h2>";
                &#125;
		


// ==== Main Form =========================================================
//
// ========================================================================
else
&#123;
echo "<form action="?op=poe" method="POST">\n";
echo "Username: <input name="username" MAXLENGTH="25"><br />\n";
echo "Poem: <input type="poem" name="poem" MAXLENGTH="25"><br />\n";
echo "<input type="submit">\n";
echo "</form>\n";
	&#125;
// EOF
?>

Posted: Tue Mar 01, 2005 8:01 am
by scorphus
Hi,

I think there is a problem with your query. After the assignment

Code: Select all

$q = "INSERT INTO `dbpoems` (`username`,`poem`) "
      ."VALUES ('".$_POST&#1111;"username"]."', "
      ."poem('".$_POST&#1111;"poem"]."'), ";
the query would be something like, for example,

Code: Select all

"INSERT INTO `dbpoems` (`username`,`poem`) VALUES ('orlando', poem('bla bla bla'), "
which doesn't seem to be a valid query. You call toa function poem() and procedures are supported only on MySQL 5.0. Also you have an ending , which should be replaced by the closing ).

What is the error message if you're getting some? What is the description of the dbpoems table? What is the type the poem filed? Think you might remove that poem() function and insert the poem itself.

-- Scorphus

Posted: Tue Mar 01, 2005 8:13 am
by Smackie
See i aint getting no error.. i pulled almost that whole script out of my signup script that i made it works just fine until i try sending in the user name and poem it just goes right to the "oops you didnt get put in the database sorry"... and i dont see nothing wrong in working with it that way :?: .....

Posted: Tue Mar 01, 2005 8:19 am
by scorphus
Hmmm... let us see what error is raised by MySQL. Change the line where you send the query like this:

Code: Select all

$r = mysql_query($q) or die('MySQL error: ' . mysql_error() . '<br>Query: ' . $q);
Then show us the error. Also, what is the type of the poem field?

-- Scorphus

Posted: Tue Mar 01, 2005 8:24 am
by Smackie
MySQL error: Query was empty
Query:
thats the error i got..

the poem on is VARCHAR i think...

is there someway i can get more then 255 letters put into there so people can add there longer poems in there as well?

Posted: Tue Mar 01, 2005 8:33 am
by scorphus
Strange you're geting an empty query :o Are you sure you correctly changed the line?

So, VARCHAR, ok. What kind of data is a poem in your application? Is it just text, line by line? I'm asking this to know if it can be store into that field.

Posted: Tue Mar 01, 2005 8:36 am
by Smackie
yeah i think its text line by line im not for sure im somewhat of a newbie...
but what i posted was the full page for that....


?? :?: is there someway i can get more then 255 letters put into there so people can add there longer poems in there as well :?: ??

Posted: Tue Mar 01, 2005 8:40 am
by feyd
you don't use VARCHAR to have longer text.. TEXT, MEDIUMTEXT, LONGTEXT are for those things.

Posted: Tue Mar 01, 2005 8:44 am
by scorphus
Smackie wrote:(...) ?? :?: is there someway i can get more then 255 letters put into there so people can add there longer poems in there as well :?: ??
Ok, ok, I saw it on the last post. It seems a field of type TEXT is the best option for you. Reference: MySQL Reference Manual :: 11.4.3 The BLOB and TEXT Types

Also, what you get if you echo the query (echo $q) after the line you declare it?

Posted: Tue Mar 01, 2005 9:02 am
by Smackie
what do you mean by
Also, what you get if you echo the query (echo $q) after the line you declare it?

Posted: Tue Mar 01, 2005 9:20 am
by feyd
echo the variable $q after you set it. Tell us what you see.

Posted: Tue Mar 01, 2005 9:24 am
by scorphus
I mean, you're getting an empty query error message from MySQL. Just print the query right after you set it up. It is a kind of debugging. So just place something like this in your code:

Code: Select all

// Fields are clear, add user to database
   //  Setup query
   $q = "INSERT INTO `dbpoems` (`username`,`poem`) "
      ."VALUES ('".$_POST&#1111;"username"]."', "
      ."poem('".$_POST&#1111;"poem"]."'), ";

   //  See what the query looks like, comment to have the normal execution of the script
   die($q);
[edit]
feyd, you're too fast, man :lol:
[/edit]

Posted: Tue Mar 01, 2005 1:12 pm
by Smackie
now im just getting

Code: Select all

INSERT INTO `dbpoems` (`username`,`poem`) VALUES ('Smackie', poem('testing'),

feyd | :roll:

Posted: Tue Mar 01, 2005 1:17 pm
by feyd
well.. you're missing a closing paren .. if you don't have a stored procedure or function called 'poem' then you may get an error with that too..