Forum Moderators: coopster
I'm new to this forum. It's great! I'm also new php/mysql. Here goes... Remember..I am very new to this. I hope I don't waste your time.
These are two scripts I tried to create, by using bits and pieces from other scripts. My mission is for site visitors to leave a message or comment that will be added to our database. Database is called: News_Articles; Table: ccds_news. Table has six fields(6), which includes the (ID).
Thanks in Advance
Senmar
SMA
Submit an Article
<?
$DBhost = "";
$DBuser = "";
$DBpass = "";
$DBName = "News_Articles";
$table = "ccds_news";
$dbconn=mysql_connect("localhost","",""); or die("Unable to connect to database");
mysql_select_db("$DBName"); or die("Unable to select database $DBName");
$results=mysql_query("INSERT INTO $ccds_news (article_title, author_name, date_created, content, url)
VALUES("'$article_title"','"$author_name"','"$date_created"',"'$content"',"'$url"')");
or die(mysql_error());
mysql_close();
print "<html><body><center>";
print "<p>Thankyou For Your Comments<p>";
print "Article Name: $article_name<br>";
print "Author Name: $author_name<br>";
print "Date: $date_created";
print "Content: $content";
print "URL: $url";
print "</body></html>";
?>
$DBhost = "";
$DBuser = "";
$DBpass = "";
$DBname = "News_Articles";
$table = "ccds_news";
$dbconn=mysql_connect("localhost", "myself", "youbet"); OR DIE("DB connection unavailable");
mysql_select_db( "News_Articles") or die( "Unable to select database");
?>
Search DataBase
<?
$XX = "No Record Found, to search again please close this window";
//query details table begins
$query = "SELECT * FROM ccds_news
while ($row = @mysql_fetch_array($query))
{
$id=$_POST["id"];
$article_title=$_POST["article_title"];
$author_name=$_POST["author_name"];
$date_created=$POST["date_created"];
$content=$_POST["content"];
$url=$_POST["url"];
//table layout for results
print ("<tr>");
print ("<td>$article_title</td>");
print ("<td>$author_name</td>");
print ("<td>$date_created</td>");
print ("<td>$content</td>");
print ("<td>$url</td>");
print ("</tr>");
}
//below this is the function for no record!
if (!$variable1)
{
print ("$XX");
}
//end
?>
Something which occurs to me when reading your post: where's the question?
Thanks for responding. My question should have been; why am I getting this Internal Server Error; and are there problems with my script?
Uploading to server... The scripts are contained in the "cgi-bin" folder in my httpdocs. I uploaded the scripts using MS Frontpage 2002. Maybe the problem lies with using Frontpage? Should I have used an FTP application to upload the scripts.
Question? Should the scripts also be in the "cgi-bin" folder located on my webhost's server, because when I click on the folder on their server, it's empty.
HELP PLEASE..
Thanks in Advance,
Senmar
SMA
[edited by: coopster at 3:18 pm (utc) on Sep. 21, 2004]
[edit reason] removed specifics [/edit]
<?phpSave it as "mypage.php" in the root directory of your public pages. Now try to open the file in your web browser. You should lots of PHP information listed on the page. Does that work?
phpinfo();
?>
I ran the <?phpinfo();?> and it worked. I ran a few minors php scripts and they worked also. I had to remove all the php scripts from the cgi-bin folder, and put them the directory with my httpdocs.
Now...I have a couple scripts I need help with. The php script below suppose to let the visitor post a news article on our website; and upon submitting the article, a thankyou screen should appear with the information they submitted. When I tested the message.html form, the results.php page was blank. Can you please explain what I am doing wrong here?
1. results.php
(Submit Article)
<?php
$DB_host = "localhost";
$DB_user = "";
$DB_pass = "";
$DB_Name = "News_Articles";
$DB_table = "ccds_news";
$dbconn=mysql_connect("localhost","",""); or die("Unable to connect to database");
mysql_select_db("$News_Articles"); or die("Unable to select database $DB_Name");
$results=mysql_query("INSERT INTO $ccds_news (article_title, author_name, date_created, content, url)
VALUES("'$article_title"','"$author_name"','"$date_created"',"'$content"',"'$url"')");
or die(mysql_error());
mysql_close();
print "<html><body><center>";
print "<p>Thankyou For Your Comments<p>";
print "Article Name: $article_name<br>";
print "Author Name: $author_name<br>";
print "Date: $date_created";
print "Content: $content";
print "URL: $url";
print "</body></html>";
?>
The next script is a search database php script. I know there are errors in this script. Help! I also got a blank page when hit I hit the submit button on the html form doc. Help me please. (If you can)
2. script.php
(Search Database)
<?
$hostname = "localhost";
$username = "";
$password = "";
$dbName = "News_Articles";
$usertable = "ccds-news";
$show_all = `Select * From ccds_news`;
mysql_connect($localhost, $, $) OR DIE(mysql_error ());
mysql_select_db( "$News_Articles") or die( mysql_error());
//query details table begins
mysql_query( $Show_all) or die (mysql_erros());
$results = `mysql_query($Show_all) or die (mysql_error())`;
while ($row = mysql_fetch_array($results))
{
$view_ccds_news = ID_number:` .$row["id"]; <br/>
$view_ccds_news = article_title:` .$row["article_title"]; <br/>
$view_ccds_news = author_name:` .$row["author_name"]; <br/>
$view_ccds_news = date_created:` .$row["date_created"]; <br/>
$view_ccds_news = content:` .$row["content"];<br/>
$view_ccds_news = url:` .$row["url"];<br/>
//table layout for results
}
echo (`$view_ccds_news`);
print ("<tr>");
print ("<td>$variable1</td>");
print ("<td>$variable2</td>");
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("<td>$variable5</td>");
print ("</tr>");
}
//below this is the function for no record!
if (!$variable1)
{
}
//end
?>
<center>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000080">
<tr>
<td width="60"><b>id</b></td>
<td width="150"><b>article_title</b></td>
<td width="70"><b>author_name</b></td>
<td width="150"><b>date_created</b></td>
<textarea name="content" cols="50" rows="10">Content</textarea>
<td width="150"><b>url</b></td>
</tr>
</table>
</center>
Thanks in Advance,
Senmar