Jump to content

blog entry system


begna112

Recommended Posts

ok this is probably going to sound complicated so let me organize from the beginning: 1) i am new to web design, have been taking a web design class or about two months and am way ahead of the rest of the class. 2) i decided to build a blog from scratch. 3) everything was fine until i tried to put it on the internet (public internet not just apache server) 4) i hate MySQL and PHPMyAdmin cause i cant figure them out. 5) this is just my first try at creating a website so i am really just going for functionality more than finesse

 

thats everything. what i am trying to do is create an entry system. wherein i have a form in which i enter: the month(drop box), day (textarea), year (dropbox), and time(textarea), the table inside my database which has already been created (dropbox), the title of the entry (textarea), and the entry itself (textarea)

 

now heres my source code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Profile entry system tryout</title>
<link rel="stylesheet" type="text/css"
href="profile.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div id="Sitename">Colby's World</div>
<div id="Naviarea"><div id="Navibar"> <span style="color:rgb(50,74,82); font-size:14pt">Navigation bar</span>
<ul>
<li><a href="index.php"> Home Page</a></li>
<li><a href="blogpicspage.php">Pics/Videos</a></li>
<li><a href="bloghappeningspage.php">Happenings</a></li>
</ul>
</div></div>
<!--<div id="linksads">My Friends</div>-->
<div id="updates"><h2> Blog Entry System</h2> POSTING<hr>
<?php


$password="password";
  print "<h2 align=\"center\">Logon to add new posts</h2>";
// If password is valid let the user get access
if (isset($_POST["password"]) && ($_POST["password"]=="$password")) {
if (isset($_POST['submit'])) {

    $month = htmlspecialchars(strip_tags($_POST['month']));
    $date = htmlspecialchars(strip_tags($_POST['date']));
    $year = htmlspecialchars(strip_tags($_POST['year']));
    $time = htmlspecialchars(strip_tags($_POST['time']));
    $title = htmlspecialchars(strip_tags($_POST['title']));
    $entry = $_POST['entry'];
    $tableentry = $_POST['tableentry'];

    $timestamp = strtotime($month . " " . $date . " " . $year . " " . $time);

    $entry = nl2br($entry);

    if (!get_magic_quotes_gpc()) {
        $title = addslashes($title);
        $entry = addslashes($entry);
    }

    mysql_connect ('localhost', 'user', 'password') ;
mysql_select_db ('databasename');


    $sql = "INSERT INTO  `databasename `.`$tableentry` (`id` ,`timestamp` ,`title` ,`entry`) VALUES (NULL ,  '$timestamp',  '$title',  '$entry')";

echo $sql;

    $result = mysql_query($sql);

    if ($result != false) {
        print "Your entry has successfully been entered into the database.";
    }

    mysql_close();
}
?>

<?php
$current_month = date("F");
$current_date = date("d");
$current_year = date("Y");
$current_time = date("H:i");
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<p><strong><label for="month">Date (month, day, year):</label></strong>

<select name="month" id="month" >
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>

<input type="text" name="date" id="date" size="2" value="00" />

<select name="year" id="year">
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2010">2011</option>
<option value="2010">2012</option>
</select>

<strong><label for="time">Time:</label></strong> <input type="text" name="time" id="time" size="5" value="HH:mm" /></p>

<select name="tableentry" id="tableentry" >
<option value="bloghomepage">Blog Home Page</option>
<option value="blogpicspage">Blog Pics Page</option>
<option value="bloghappeningspage">Blog Happenings Page</option>
</select>

<p><strong><label for="title">Title:</label></strong> <input type="text" name="title" name="title" size="40" /></p>

<p><textarea cols="80" rows="20" name="entry" id="entry"></textarea></p>

<p><input type="submit" name="submit" id="submit" value="Submit"></p>

</form>
<?php
}
else
{
// Wrong password or no password entered display this message
if (isset($_POST['password']) || $password == "") {
  print "<p align=\"center\"><font color=\"red\"><b>Incorrect Password</b><br>Please enter the correct password</font></p>";}
  print "<form method=\"post\"><p align=\"center\">Please enter your password for access<br>";
  print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>";
}

?>
<BR>
</div></div>
</body>
</html>

 

 

in my db i have a table called bloghomepage with columns already. i added an attachment which pictures the columns.

 

i cannot for some reason insert a row into the table using this code remotely. i have no idea why. from everything ive looked up or seen or been taught. this. should. work.

 

i can insert rows manually from inside phpmyadmin but not from this code and i dont know y.

 

please dont comment on the rudimentary login system unless it will solve the problem of the posting. thank you.

 

should i include the css file for it?

 

my site if you want to see the formatting is colbysworld.netau.net (there are no pictures yet cause i am trying to fix this.)

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

I just spent ages typing some text only to find the topic has been moved and renamed without leaving a shadow and I thought it'd been deleted!

 

Why hate MySQL?

 

Can you use a spreadsheet?

 

Has anyone told you MySQL is just like playing with Excel spreadsheets?

 

You've got your columns across the top - these are your MySQL "fields" and you've got your rows down the left which are your MySQL row numbers - auto index/primary key. Instead of you just looking at a cell and reading the information MySQL needs to be told where to look which is where English-like sentences are given to it.

 

As for phpMyAdmin - first time I looked at that I was wary of clicking anything but it's just practice - that's all it is. After a bit of playing with them you'll see there's not that much to them.

 

When posting code it's strongly advised to use the [code] and [/code] tags to surround code like this:

<?php
echo 'PHP is color coded and formatting is preserved';
?>
HTML stays one color

Link to comment
Share on other sites

i really have no idea. where would i post. its like 2 am in the morning and ive been slaving over this for hours. feel free to tell me where to redirect this or go ahead and redirect it for me. i was hoping some1 would just see it and say something like "oh u screwed up ur syntax here" or "oh you gotta reference this differently here" etc etc. but now im tired. thanks for looking at it. ill be back tomorrow

 

could it possibly be getting the table name from the form? is my form screwing it up? thats all i can think it might be if it isnt the mysql

 

srry i just got what you were asking. no there is only one database. one table thats it

 

Link to comment
Share on other sites

dunno why you didn't get an error for the space after "databasename "

 

but anyway...you say you've only got one database

you've already selected it using mysql_select_db

 

so you don't need to clarify it again in the SQL

"INSERT INTO  `databasename `.`$tableentry` (`id` ,`ti.....

 

just try

"INSERT INTO  `$tableentry` (`id` ,`ti

 

and if that doesn't work...then I dunno.

 

If there's only one table why do you need a variable to hold the tableentry anyway....just put it explicity

"INSERT INTO  `yourtablenamehere` (`id` ,`ti

Link to comment
Share on other sites

i removed the database name as you said. then i removed the quotes around the $tableentry hoping it would just recognize the variable..

 

like so:

$sql = "INSERT INTO $tableentry (`id` ,`timestamp` ,`title` ,`entry`) VALUES (NULL ,  '$timestamp',  '$title,  $entry')";

 

this is wat i got:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(`id` ,`timestamp` ,`title` ,`entry`) VALUES (NULL , '1239264906', '', '')' at line 1

 

and its the same even if i remove the quotes around $timestamp, title and entry

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.