Page 1 of 1
Form posting problem
Posted: Sat Mar 19, 2005 11:41 pm
by Smackie
I am having a problem in a form it wont submit the data to the database... i dont get any errors.. here is the script
Code: Select all
<?php
ob_start();
if ((isset($_GET['poet_poet_id']) == true) && (isset($_Get['poemname']) == true) && (isset($_GET['poem']) == true))
{
// Tell the user it has been submitted (optional)
echo('Your comment has been posted.');
// Set Mysql Variables
$host = 'localhost';
$user = 'haunted_smackie';
$pass = '*********';
$db = 'haunted_poetry';
$tb = 'poems';
// Set global variables to easier names
$add_all = "INSERT into poems (poet_id, poemname, poem) values ('$poetid', '$poemname','$poem')";
$poem_id = $_SESSION['poet_id'];
$poemname = $_GET['poemname'];
$poem = $_GET['poem'];
// Connect to Mysql, select the correct database, and run teh query which adds the data gathered from the form into the database
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$add_all = "INSERT into poems (poet_id, poemname, poem) values ('$poetid', '$poemname','$poem')";
mysql_query($add_all) or die(mysql_error());
}
else
{
echo $add_all;
// If the form has not been submitted, display it!
?>
<form method='get' action='<? echo $PHP_SELF; ?>'>
Poem Name: <input type='text' name='poemname'><br><br>
Poem: <br>
<textarea name='poem' cols='50' rows='10'></textarea><br><br>
<input type='submit' value='Post your poem'>
</form>
<?
}
?>
feyd | Please review how to post code using Code: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Sat Mar 19, 2005 11:50 pm
by thegreatone2176
two things first
1) edit your password out on public forums
2) global variables are bad to use as im sure everyone else will post about
also
i dont think your if will be true ever because where do you ever get
$_GET['poet_poet_id']
and you have
Code: Select all
if ((isset($_GET['poet_poet_id']) == true)
you can just do
last whats your final
<?
}
?>
about ?
Posted: Sat Mar 19, 2005 11:58 pm
by Smackie
it was suppose to be $_GET['poet_id'] but see i have 2 tables in db 1 is for the login and the other is for the id, poem, and poem name and poet_id should link the two tables together.......
Posted: Sun Mar 20, 2005 12:01 am
by Smackie
this
<?
}
?> just to show that the script is done thats all it shouldnt hurt the script any i dont think it hasnt messed up my other scripts that i have done.....
Posted: Sun Mar 20, 2005 4:07 am
by thallish
hey
first off all then the statement in line 18 is unnecessary. You have it in line 26.
In line 19 you set the variable $poem_id but in line 26 you use a variable in the variable $poetid as a value. I believe that's the problem.
regards thallish
Posted: Sun Mar 20, 2005 6:51 am
by phpScott
If that doesn't fix it, but I think it will, echo out your query to the screen then run it directly agianst your db and see if it spits out any errors at you, could be simple spelling or wront column name.
phpscott
Posted: Sun Mar 20, 2005 9:08 am
by feyd
poet_poet_id, poet_id, poem_id, and $poetid may all be potential sources of confusion about this.
Sanitize your inputs. You don't know where they've been

Posted: Sun Mar 20, 2005 9:41 pm
by Smackie
yeah i seen that i did that i fixed them but its still not posting anything

Posted: Mon Mar 21, 2005 4:59 am
by thallish
can you post your editted code then
thallish
Posted: Mon Mar 21, 2005 6:44 pm
by Smackie
Code: Select all
<?php
session_start();
if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: http://www.hauntedgraveyard.net/Poetry/ ... /login.php");
}
if ((isset($_SESSION['poet_id'])) && (isset($_Get['poemname']) == true) && (isset($_GET['poem']) == true))
{
// Tell the user it has been submitted (optional)
echo('Your comment has been posted.');
// Set Mysql Variables
$host = 'localhost';
$user = 'haunted_smackie';
$pass = '*****';
$db = 'haunted_poetry';
$tb = 'poems';
// Set global variables to easier names
$poet_id = $_SESSION['poet_id'];
$poemname = $_GET['poemname'];
$poem = $_GET['poem'];
// Connect to Mysql, select the correct database, and run teh query which adds the data gathered from the form into the database
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$add_all = "INSERT into poems (poemname, poem) values ('$poemname','$poem')";
mysql_query($add_all) or die(mysql_error());
}
else
{
echo $add_all;
// If the form has not been submitted, display it!
?>
<form method='get' action='<? echo $PHP_SELF; ?>'>
Poem Name: <input type='text' name='poemname'><br><br>
Poem: <br>
<textarea name='poem' cols='50' rows='10'></textarea><br><br>
<input type='submit' value='Post your poem'>
</form>
<?
}
?>
feyd | Please review how to post code using Code: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Mon Mar 21, 2005 7:19 pm
by infolock
thegreatone2176 wrote:
last whats your final
<?
}
?>
about ?
that ends his "ELSE" statement...
Anyways, try this. I've added comments where I changed the code...
Code: Select all
<?php
session_start();
if (!$_SESSIONї"e;valid_user"e;])
{
// User not logged in, redirect to login page
Header("e;Location: http://www.hauntedgraveyard.net/Poetry/ ... php"e;);
}
//The following If(isset statement has been changed. You had some extra () marks and unecessary == true
//statements. Also, you should be using a $_POST instead of a $_GET as you aren't passing anything via
//a url..
if ((isset($_SESSIONї'poet_id']) && isset($_POSTї'poemname']) && isset($_POSTї'poem']))
{
// Tell the user it has been submitted (optional)
echo('Your comment has been posted.');
// Set Mysql Variables
$host = 'localhost';
$user = 'haunted_smackie';
$pass = 'deketazz';
$db = 'haunted_poetry';
$tb = 'poems';
// Set global variables to easier names
$poet_id = $_SESSIONї'poet_id'];
$poemname = $_GETї'poemname'];
$poem = $_GETї'poem'];
// Connect to Mysql, select the correct database, and run teh query which adds the data gathered from the form into the database
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
//moved your entire sql statement into $add_all since you aren't doing anything else with this query anyways.
$add_all = mysql_query("e;INSERT into poems (poemname, poem) values ('"e;.$poemname."e;','"e;.$poem."e;')"e;) or die(MySQL_Error());
}
else
{
//Removed your echo $add_all statement. This is because you will NOT be able to echo out that
//variable due to the fact that it is only defined when the IF statement rings true. Here, you are
//trying to say "e;when the IF statement fails, echo what I have assigned for $add_all"e;..leaving you with
//nothing to be echo'ed..
//changed the Form's method to POST instead of GET.
?>
<form method='POST' action='<? echo $PHP_SELF; ?>'>
Poem Name: <input type='text' name='poemname'><br><br>
Poem: <br>
<textarea name='poem' cols='50' rows='10'></textarea><br><br>
<input type='submit' value='Post your poem'>
</form>
<?
}
?>
hope this helps.
Posted: Mon Mar 21, 2005 8:15 pm
by feyd