Page 2 of 5
Posted: Tue Mar 01, 2005 1:28 am
by n00b Saibot
I honestly advise you Smackie, get your PHP manual and read up all section and try all examples. try a little tweaking in them, then again try them out. That way you learn a lot and firm your hold on the matter. If possible grab a good book on PHP for yourself. Maybe a 21-dayer or something like that.
Posted: Tue Mar 01, 2005 1:39 am
by Smackie
first of all alot of people learn that way but im not like other people i learn by other ways like showing more then they show is the way i learn...
but smpdawg i just ran into a warning::
Warning: Missing argument 2 for getparm() in /home/haunted/public_html/Poetry/poems.php on line 16
Posted: Tue Mar 01, 2005 1:48 am
by feyd
you need to pass in the second argument to getParm()
Posted: Tue Mar 01, 2005 1:50 am
by n00b Saibot
or change getParm defination to
Code: Select all
function getParm($VariableName, $Default='') {
return (isset($_GETї$VariableName])) ? $_GETї$VariableName] : $Default;
}
Posted: Tue Mar 01, 2005 1:51 am
by Smackie
i fixed it on my own but thank you....
Posted: Fri Mar 04, 2005 7:07 pm
by Smackie
Well i finally got it somewhat going but im still running into problems for some reason

i keep running into a error
error
Parse error: parse error, unexpected T_VARIABLE in /home/haunted/public_html/Poetry/poetry.php on line 22
and i made a field to see if the alphabet script would work but it doesnt it only shows the alphabet and non of the stuff in the database for some reason

Posted: Fri Mar 04, 2005 7:37 pm
by smpdawg
My normal declaration for that function would have had the $Default = "" but didn't make in this post for some reason. I guess that is what happens when you code late.
Posted: Fri Mar 04, 2005 8:03 pm
by Smackie
i dont know whats the problem is thats making the error but i can probably figure that one out but can someone help me figure out why the alphabet script isnt showing the stuff stored in database?
Posted: Fri Mar 04, 2005 8:05 pm
by feyd
*sigh* export of structure and some data please. Your current query as well.
Posted: Fri Mar 04, 2005 8:10 pm
by Smackie
here is the 2 scripts..
here is poems.php script
Code: Select all
<?php
// This function makes the alphabetic list which the links.
function drawAddressList() {
$seperator = "-";
// Loop through all 26 characters.
for ($i = 1; $i <= 26; $i++) {
$letter = chr($i + 64);
echo $seperator . "<a href='{$_SERVERї'PHP_SELF']}?letter={$letter}'>{$letter}</a>";
}
echo $seperator . '<br />';
}
// This function gets a parameter or the default.
function getParm($VariableName, $Default) {
return (isset($_GETї$VariableName])) ? $_GETї$VariableName] : $Default;
}
drawAddressList();
// Connect to MySQL - use your user name and password.
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Connects to the database that has the user table.
$db_selected = mysql_select_db('database', $link);
if (!$db_selected) {
die ('Can''t use table : ' . mysql_error());
} else {
if ($letter != '') {
$letter_query = "SELECT * FROM `dbUsers` WHERE `username` REGEXP '^$letter.*' ORDER BY `username`";
$letter_result = mysql_query($letter_query);
if ($letter_result != false) {
while ($letter_row = mysql_fetch_assoc($letter_result)) {
// Do something in here with the rows you get.
// Maybe use the information from the user table to fill another recordset with the poems.
}
}
}
}
?>
here is poetry.php script
Code: Select all
<?
if(isset($_GETї'commented']))
{
// Tell the user it has been submitted (optional)
echo('Your comment has been posted.');
// Set Mysql Variables
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'database';
$table = 'db table';
// Set global variables to easier names
$username = $_GETї'uname'];
$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 $table values('$username','$poem',''';
mysql_query($add_all) or die(mysql_error());
}
else
{
// If the form has not been submitted, display it!
?>
<form method='get' action='<? echo'$PHP_SELF'; ?>'>
Name : <input type='text' name='username'><br><br>
Comment : <input type='text' name='poem'><br><br>
<input type='hidden' name='commented' value='set'>
<input type='submit' value='Post your comment'>
</form>
<?
}
?>
Posted: Fri Mar 04, 2005 8:37 pm
by smpdawg
Wrong
Code: Select all
$add_all = 'INSERT INTO $table values('$username','$poem',''';
Maybe right
Code: Select all
$add_all = "INSERT INTO $table values("$username","$poem","")";
Is there really a 3rd field in the database that you want to be blank? If not, use this instead.
Code: Select all
$add_all = "INSERT INTO $table values("$username","$poem")";
Posted: Fri Mar 04, 2005 8:49 pm
by Smackie
alright that fixed one of the problems but caused another one

now when i click submit button it comes up page cant be displayed and this goes into the Address box
it shouldnt send it to another page it should be sending it to the database and the page should go direct to the poem.php page...
and any tips on fixing up the poem.php page?
Posted: Fri Mar 04, 2005 8:57 pm
by smpdawg
Fix this
Code: Select all
<form method='get' action='<? echo'$PHP_SELF';
Should be this.
Code: Select all
<form method='get' action='<? echo $PHP_SELF;
Posted: Fri Mar 04, 2005 9:00 pm
by Smackie
Posted: Fri Mar 04, 2005 9:05 pm
by smpdawg
Did you get any error message when the form was submitted?
If you don't speciify the field names in an INSERT query, you must add them all. So how many fields are in $table and what are they?