List Info

Thread: php and mysql will not sync up on localhost or online yahoo/mysql pls help




php and mysql will not sync up on localhost or online yahoo/mysql pls help
user name
2006-08-03 01:28:11
pls help me i have just got a book with cd that has the
following
software

Mysql
Apache
PHP 5.0

I have setup all three following the instructions and tested
them, they
seem to work fine according to the book and i can view the
phpinfo.php
page perfectly also the localhost is up and running, i also
use Yahoo
webhosting with mysql which is also giving me the same
problems.  Mysql
on local and on yahoo are not being accessed by my PHP
files.

I have followed a step by step guide from the book to setup
a standard
forum but it just will not store information into mysql or
attempt to
retrieve it the first page addtopic.html can be viewed fine
but does
not do anything...pls help

This guide told me to create 5 files in total

addtopic.html
do_addtopic.php
replytopost.php
showtopic.php
topiclist.php

for the record on my computer and online the icons for the
php files
come up as unreconized icons is this a problem? although
both local and
yahoo host do run the phpinfo.php and test connection files
perfectly.
pls help i know they say not to print the whole php file on
this forum
but i am desperate if you can help me pls do me this favor
and help me
understand what i am doing wrong

mysql login and password = test  ,   test
the book im using is
"Sams Teach yourself PHP, MYSQL and Apache All in
One"
ISBN 0-672-32725-2

here are the files in order with there titles



1.   addtopic.html


<html>
<head>
<title>Add a Topic</title>
</head>
<body>
<h1>Add a Topic</h1>
<form method=post
action="do_addtopic.php">
<p><strong>Your E-Mail
Address:</strong><br>
<input type="text"
name="topic_owner" size=40 maxlength=150>
<p><strong>Topic Title:</strong><br>
<input type="text"
name="topic_title" size=40 maxlength=150>
<p><strong>Post Text:</strong><br>
<textarea name="post_text" rows=8 cols=40
wrap=virtual></textarea>
<p><input type="submit"
name="submit" value="Add
Topic"></p>
</form>
</body>
</html>




2.   do_addtopic.php




<?php
//check for required fields from the form
if ((!$_POST[topic_owner]) || (!$_POST[topic_title])
    || (!$POST[post_text])){
    header("location: addtopic.html");
    exit;
}

//connect to server and select database
$conn = mysql_connect("localhost",
"test", "test")
   or die(mysql_error());
mysql_select_db("test",$conn) or
die(mysql_error());

//create and issue the first query
$add_topic = "insert into forum_topics values ('',
'$_POST[topic_title]',
   now(), '$_POST[topic_owner]')";
mysql_query($add_topic,$conn) or die(mysql_error());

//get the id of the last query
$topic_id = mysql_insert_id();

//create and issue the second query
$add_post = "insert into forum_posts values ('',
'$topic_id',
  '$_POST[post_text]', now(),
'$_POST[topic_owner]')";
mysql_query($add_post,$conn) or die(mysql_error());

//Create nice message for User
$display_block = "<p>The
<strong>$topic_title</strong> topic has been
created.</p>";
?>
<html>
<head>
<title>New Topic Added</title>
</head>
<body>
<h1>New Topic Added</h1>
<?php echo $display_block; ?>
</body>
</html>





3.   replytopost.php



<?php
//connect to server and select database; we'll need it soon
$conn = mysql_connect("localhost",
"test", "test")
   or die(mysql_error());
mysql_select_db("test", $conn) or
die(mysql_error));

//check to see if we're showing the form or adding the post
if ($_POST[op] !="addpost") {
   //showing the form; check for required item in query
string
   if (!$_GET[post_id]) {
      header("location: topiclist.php");
      exit;

}

      //still have to verify topic and post
   $verify = "select ft.topic_id, ft.topic_title from
    forum_posts as fp left join forum_topics as ft on
    fp.topic_id = ft.topic_id where fp.post_id =
$_GET[post_id]";

   $verify_res = mysql_query($verify, $conn) or
die(mysql_error());
   if (mysql_num_rows($verify_res) < 1) {
   //this post of topic does not exist
   header("Location: topiclist.php");
   exit;
} else {
   //get the topic id and title
   $topic_id = mysql_result($verify_res,0,'topic_id');
   $topic_title = stripslashes(mysql_result($verify_res,
   0,'topic_title'));

   echo "
   <html>
   <head>
   <title>Post Your Reply in
$topic_title</title>
   </head>
   <body>
   <h1>Post Your Reply in $topic_title</h1>
   <form method=post
action=\"$_SERVER[PHP_SELF]\">

   <p><strong>Your E-mail
Address:</strong><br>
   <input type=\"text\"
name=\"post_owner\" size=40 maxlength=150>

   <p><strong>Post
Text:</strong><br>
   <textarea name=\"post_text\" rows=8
cols=40 wrap=virtual></textarea>

   <input type=\"hidden\"
name=\"op\"
value=\"addpost\">
   <input type=\"hidden\"
name=\"topic_id\"
value=\"$topic_id\">
   <p><input type=\"submit\"
name=\"submit\" value=\"Add
Post\"></p>
   </form>
   </body>
   </html>";
  }
} else if ($_POST[op] == "addpost") {
   //check for required items from form
   if ((!$_POST[topic_id]) || (!$_POST[post_text]) ||
   (!$_POST[post_owner])){
      header("Location: topiclist.php");
      exit;
}

   //add the post
   $add_post = "insert into forum_posts values ('',
'$_POST[topic_id]',
      '$_POST[post_text]', now(),
'$_POST[post_owner]')";
   mysql_query($add_post,$conn) or die(mysql_error());

   //redirect user to topic
   header("Location:
showtopic.php?topic_id=$topic_id");
   exit;
}
?>




4.   showtopic.php


<?
//check for required info from the query string
if (!$_GET[topic_id]) {
   header("Location: topiclist.php");
   exit;
}

//connect to server and select database
$conn = mysql_connect("localhost",
"test", "test")
   or die(mysql_error());
mysql_select_db("test",$conn) or
die(mysql_error());

//verify the topic exists
$verify_topic = "select topic_title from forum_topics
where
   topic_id - $_GET[topic_id]";
$verify_topic_res = mysql_query($verify_topic, $conn)
   or die(mysql_error());

if (mysql_num_rows($verify_topic_res) < 1) {
   //this topic does not exist
   $display_block = "<p><em>You have
selected and invalid Topic.
   Please <a href=\"topiclist.php\">try
again</a>.</em></p>";
} else {
   //get the topic title
   $topic_title =
stripslashes(mysql_result($verify_topic_res,0,
      'topic_title'));

   //gather the posts
   $get_posts = "select post_id, post_text,
date_format(post_create_time,
      '%b %e %Y at %r') as fmt_post_create_time,
post_owner from
      forum_posts where topic_id = $_GET[topic_id]
      order by post_create_time asc";



   $get_posts_res = mysql_query($get_posts,$conn) or
die(mysql_error());

   //create the display string
   $display_block = "
   <p>Showing posts for the
<strong>$topic_title</strong> topic:</p>

   <table width=100% cellpadding=3 cellspacing=1
boarder=1>
   <tr>
   <th>AUTHOR</th>
   <th>POST</th>
   </tr>";

   while ($posts_info = mysql_fetch_array($get_posts_res)) {
      $post_id = $posts_info['post_id'];
      $post_text =
n12br(stripslashes($posts_info['post_test']));
      $post_create_time =
$posts_info['fmt_post_create_time'];
      $post_owner =
stripslashes($posts_info['post_owner']);

      //add to display
      $display_block .= "
      <tr>
      <td width=35%
valign=top>$post_owner<br>[$post_create_time]</t
d>
      <td width=65%
valign=top>$post_text<br><br>
      <a
href=\"replytopost.php?post_id=$post_id\">&
lt;strong>REPLY TO
POST</strong></a></td>
      </tr>";
}

   //close up the table
   $display_block .= "</table>";
}
?>
<html>
<head>
<title>Posts in Topic</title>
</head>
<body>
<h1>Posts in Topic</h1>
<?php echo $display_block; ?>
</body>
</html>




5.   topiclist.php


<?php
//connect to server and select database
$conn = mysql_connect("localhost",
"test", "test")
   or die(mysql_error());
mysql_select_db("test",$conn) or
die(mysql_error());

//gather the topics
$get_topics = "select topic_id, topic_title,
date_format(topic_create_time, '%b %e %Y at %r') as
fmt_topic_create_time,
topic_owner from forum_topics order by topic_create_time
desc";
$get_topics_res = mysql_query($get_topics,$conn) or
die(mysql_error());

if (mysql_num_rows($get_topics_res) < 1) {
   //there are no topics so say so
   $display_block = "<P><em>No Topics
Exist.</em></p>";
} else {
   //create the display string
   $display_block = "
   <table cellpadding=3 cellspacing=1 boarder=1>
   <tr>
   <th>Topic Title</th>
   <th># of POSTS</th>
   </tr>";

while ($topic_info = mysql_fetch_array($get_topics_res)) {
   $topic_id = $topic_info['topic_id'];
   $topic_title =
stripslashes($topic_info['topic_title']);
   $topic_create_time =
$topic_info['fmt_topic_create_time'];
   $topic_owner =
stripslashes($topic_info['topic_owner']);

   //get number of posts
   $get_num_posts = "select count(post_id) from
forum_posts
      where topic_id = $topic_id";
   $get_num_posts_res = mysql_query($get_num_posts,$conn)
      or die(mysql_error());
   $num_posts =
mysql_result($get_num_posts_res,0,'count(post_id)');

   //Add to Display
   $display_block .= "
   <tr>
   <td><a
href=\"showtopic.php?topic_id=$topic_id\">
      
<strong>$topic_title</strong></a><br>
;
   Created on $topic_create_time by $topic_owner</td>
   <td align=center>$num_posts</td>
   </tr>";
 }

   //close the table
   $display_block .= "</table>;


 }
?>
<html>
<head>
<title>Topics in my forum</title>
</head>
<body>
<h1>Topics in My Forum</h1>
<?php echo $display_block; ?>
<p>would you like to <a
href="addtopic.html">Add a
Topic</a>?</p>
</body>
</html>


To get this information quick you can copy all the text into
a notepad
and then edit it afterwards..

it would like christmas come early if you can help me out
thank you for
your generous hard work.in advanced..thanks for reading hope
to hear
from somebody soon!!

cheers 
daniel - west bond


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "PHP & MySQL" group.
To post to this group, send email to phpmysqlgooglegroups.com
To unsubscribe from this group, send email to
phpmysql-unsubscribegooglegroups.com
For more options, visit this group at http://groups
.google.com/group/phpmysql
-~----------~----~----~----~------~----~------~--~---

php and mysql will not sync up on localhost or online yahoo/mysql pls help
user name
2006-08-03 12:37:19
try to create a simple html file first, see if it works

try to create a simple php file after also see if it also
works

lastly try to connect to your mysql, put some data their and
try to
fetch.

paste the results here if any


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "PHP & MySQL" group.
To post to this group, send email to phpmysqlgooglegroups.com
To unsubscribe from this group, send email to
phpmysql-unsubscribegooglegroups.com
For more options, visit this group at http://groups
.google.com/group/phpmysql
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )