PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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>
<?
}
?>
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.......
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.....
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.
<?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>
<?
}
?>
<?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>
<?
}
?>