//flex table opened by JP

Click to See Complete Forum and Search --> : Beginner PHP Problem


dfrieber
08-10-2005, 11:29 AM
Hi all,

So in my most recently designed webpage, I have a journal which I want to format in php so that I may update it simply by entering data into a form. I have learned php as best I could and threw it together. But it doesn't work.

What I have is index.html (http://www.accentsbydesign.net/frieber/update/index.html) (the page the html form displays on note: only the "journal" form is currently active), update_journal.php (http://www.accentsbydesign.net/frieber/update/update_journal.php) (the page that the form on index.html submits to), and index.php (http://www.accentsbydesign.net/frieber/index.php) (the page on which the journal lies).

Since you won't be able to read my php on update_journal.php and index.php, i've copied and pasted the php on each page here:

update_journal.php

<?

$link = mysql_connect('localhost', 'xxxxxxxxx', 'xxxxxxxx');

$db_select = mysql_select_db('accentsbydesign_net_-_journal', $link);



mysql_query("INSERT INTO news (`journal_id`,`journal_titleofentry`,`journal_entr y`,`journal_date`,`journal_time`,`journal_songname `,`journal_bandname`) VALUES ('{$_POST[journal_id]}','{$_POST[journal_titleofentry]}','{$_POST[journal_entry]}','{$_POST[journal_date]}','{$_POST[journal_time]}','{$_POST[journal_songname]}','{$_POST[journal_bandname]}')");

echo "$_POST[journal_id] <br/> $_POST[journal_titleofentry] <br/> $_POST[journal_entry] <br/> $_POST[journal_date] <br/> $_POST[journal_time] <br/> $_POST[journal_songname] <br/> $_POST[journal_bandname] <br/>";


?>

index.php



<?

$link = mysql_connect('localhost', 'xxxxxx', 'xxxxxx');

$db_select = mysql_select_db('accentsbydesign_net_-_journal', $link);

$result = mysql_query('SELECT * FROM `news` order by id desc', $link);

// if (!$link) { die("you suck at php"); }

//echo mysql_stat($link);

//echo mysql_num_rows($result);

while($fed_row = mysql_fetch_row($result)) {

$obit_list .= "

<font class=\"heading\">$fed_row[1]</font><br>

$fed_row[2]
<br>

</ul>
<font class=\"date\">posted <b>".date("l, F jS, Y", strtotime($fed_row[3]))."</b> at <b>$fed_row[4]</b></font><br>
<font class=\"current_music\">while listening to <b>$fed_row[5]</b> by <b>$fed_row[6]</b></font><br><br>
<center><img src=\"dotted.gif\"></center><br> ";

}
echo "$obit_list";

mysql_close($link);
?>



So there it is. Im so new at php that i dont even know if this is a problem that can be solved here, or if knowledge of the database is necessary.

All help is greatly appreciated!

-dan

ps: in the php coding above, i have replaced my username and password with "xxxxxxx"

ps2: as youll notice on index.php, i receieve the following message:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/virtual/site231/fst/var/www/html/frieber/index.php on line 36

maybe this is assist in the solution to my problem, maybe not. thanks anyways!

rraehal
08-10-2005, 03:21 PM
Was the space here intentional:

mysql_query("INSERT INTO news (`journal_id`,`journal_titleofentry`,`journal_entr y`

That could cause an error. Maybe it just posted that way in the code section on this forum.

Is there any additional lines in your code on index.php? You only have 35 lines posted. I am also new to PHP and MySQL. I have never used the functions you have here:

<font class=\"date\">posted <b>".date("l, F jS, Y", strtotime($fed_row[3]))."</b> at <b>$fed_row[4]</b></font><br>
<font class=\"current_music\">while listening to <b>$fed_row[5]</b> by <b>$fed_row[6]</b></font><br><br>
<center><img src=\"dotted.gif\"></center><br> ";


I do not see anything that I would have typed different to write that script. Maybe more experinced guys here can help.

CompGeek01
08-10-2005, 09:35 PM
Sounds like your query is failing, possibly from the reason mentioned above by rraehal.

mysql_query("SELECT * FROM `test_table` WHERE 1") or die( mysql_error() );

You might try incorporating the "or die" method, it'll print a fairly descriptive message about what went wrong where.

dfrieber
08-11-2005, 02:02 PM
hi guys,

thanks a lot for the help, unfortunately that space was only created when i put the coding into this message board - its not there in the pages themselves....

CompGeek01
08-11-2005, 02:05 PM
Did you try incorporating my suggestion?

ScaryBinary
08-11-2005, 02:39 PM
$result = mysql_query('SELECT * FROM `news` order by id desc', $link);

You've got some funky things going on with your quotes, too. I don't think you need the weird single quotes around your table name....try
$result = mysql_query('SELECT * FROM news order by id desc', $link);

Alternatively you could use double quotes around the entire SQL statement if you want to use single quotes somewhere else in the statement....
$result = mysql_query("SELECT * FROM 'news' order by id desc", $link);

Not sure if that'll fix the issue or not, but it's worth a shot. If you use the "or die(mysql_error())" method noted above it should let you know if it's your SQL text that is bad.