Jump to content

Archived

This topic is now archived and is closed to further replies.

caroline

dragging data into a php page

Recommended Posts

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.html

ive 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 50

i hope someone can help. thanks!!

Caroline xxx


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
The former -- the latter will simply affect the formatting itself.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.