Jump to content


Photo

dragging data into a php page


  • Please log in to reply
3 replies to this topic

#1 caroline

caroline
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 April 2006 - 07:44 PM

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




#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 April 2006 - 10:09 PM

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:

$query ="SELECT entrytitle, authorName, entrytext"; 
$query.=" DATE_FORMAT(entrydate, '%M %d, %Y') AS date"; 
$query.=" FROM weblog ORDER BY entrydate DESC LIMIT 10";
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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 caroline

caroline
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 April 2006 - 02:29 PM

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 :)


#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 23 April 2006 - 05:51 PM

The former -- the latter will simply affect the formatting itself.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users