Jump to content

dragging data into a php page


caroline

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.