caroline Posted April 22, 2006 Share Posted April 22, 2006 hi!im using mysql and php to create a blog type system.im using 2php pages and one html page - , addentry.php, weblog.php, and weblog.htmlive been following a tutorial online on how to do it buit ive run into problems when trying to add my own code. ill give everyone a look a the code and maybe you could help me out cos im stumped! :)addentry.php:<?php if ($HTTP_POST_VARS['submit']) { mysql_connect("localhost","root",""); mysql_select_db("test1"); $entrytitle=$HTTP_POST_VARS['entrytitle']; $authorName=$HTTP_POST_VARS['authorName']; $entrytext=$HTTP_POST_VARS['entrytext']; $query ="INSERT INTO weblog (entrytitle, authorName, entrytext)"; $query.=" VALUES ('$entrytitle','$authorName','$entrytext')"; $result=mysql_query($query); if ($result) echo "<b>Successfully Posted!</b>"; else echo "<b>ERROR: unable to post.</b>"; } ?><?php mysql_connect("localhost","root",""); mysql_select_db("test1"); $query ="SELECT entrytitle, authorName, entrytext"; $query.=" DATE_FORMAT(entrydate, '%M %d, %Y') AS date"; $query.=" FROM weblog ORDER BY entrydate DESC LIMIT 10"; $result=mysql_query($query); while (list($entrytitle,$authorName,$entrytext,$entrydate) = mysql_fetch_row($result)) { echo "<dt><b>$entrytitle $authorName ($entrydate)</b></dt>"; echo "<p align='justify'>$entrytext</p>"; } ?> ive a html form setup to add in the data - the weblog.html page. Ive got the adding into the database part functioning, the data is getting added. But the problem is i cant get the data to display from the db in the weblog.php page. all ive modified to the tutorial has been the "authorName". it works fine without this in it. heres the database im using:CREATE TABLE weblog ( entrydate timestamp(14) NOT NULL, entrytitle varchar(100) default NULL, authorName varchar(20) NOT NULL default '', entrytext text, contactID smallint(6) default NULL, email varchar(30) NOT NULL default '', picfile tinytext NOT NULL, PRIMARY KEY (entrydate)) TYPE=MyISAM;im yet to use some the fields ive setup in the db - just trying to get a few working first!. i keep recieving this same error:Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:\phpdev\www\public\backup\weblog.php on line 50i hope someone can help. thanks!!Caroline xxx Quote Link to comment https://forums.phpfreaks.com/topic/8132-dragging-data-into-a-php-page/ Share on other sites More sharing options...
fenway Posted April 22, 2006 Share Posted April 22, 2006 First, you should never connect as root, even for testing, from a PHP script -- make a test user if need be.Second, your error is here:[code]$query ="SELECT entrytitle, authorName, entrytext"; $query.=" DATE_FORMAT(entrydate, '%M %d, %Y') AS date"; $query.=" FROM weblog ORDER BY entrydate DESC LIMIT 10"; [/code]If you were to echo this $query, you'd see that you don't have a comma before the DATE_FORMAT() expression. Calling mysql_error() if the query fails is a good way to find these syntax errors during testing. Quote Link to comment https://forums.phpfreaks.com/topic/8132-dragging-data-into-a-php-page/#findComment-29663 Share on other sites More sharing options...
caroline Posted April 23, 2006 Author Share Posted April 23, 2006 thanks!do you mean put a comma here:$query.=" [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--],[!--colorc--][/span][!--/colorc--]DATE_FORMAT(entrydate, '%M %d, %Y') AS date";or here:$query.=" DATE_FORMAT(entrydate, '%M[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--],[!--colorc--][/span][!--/colorc--] %d, %Y') AS date"; sorry if that sounds stupid :) Quote Link to comment https://forums.phpfreaks.com/topic/8132-dragging-data-into-a-php-page/#findComment-29814 Share on other sites More sharing options...
fenway Posted April 23, 2006 Share Posted April 23, 2006 The former -- the latter will simply affect the formatting itself. Quote Link to comment https://forums.phpfreaks.com/topic/8132-dragging-data-into-a-php-page/#findComment-29860 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.