Help - Search - Members - Calendar
Full Version: [resolved]BAB Question
Codegrrl.com Forums > Script Help > Tutorial Help
Phenix
Quick question, I was wondering how come when I try to add new fields to my blog table it works, but when I subit my blog, they don't show.

index.php

CODE
<?php include("/mnt/w0603/d08/s07/b025e6a3/www/vintage/cookiecheck.php");
include($headervar.$skin.$extension);
mysql_connect ('*****', '*****', '*****');
mysql_select_db ('d60270728');

$sql = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 1";

$result = mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" . $sql . "<br />" . mysql_error());

while($row = mysql_fetch_array($result)) {


    $date = date("l F d Y  @ g:i A", $row['timestamp']);
    $title = stripslashes($row['title']);
    $entry = stripslashes($row['entry']);
    $listening = stripslashes($row['music']);
    $reading = stripslashes($row['book']);
    $quote = stripslashes($row['quote']);

    ?>
    
    <!-- BLOG ENTRY -->
    
<div class="div" id="content">
  <table width="370" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="entrydate"><?php echo $date; ?> </td>
  </tr>
  <tr>
    <td class="entryheader"><?php echo $title; ?></td>
  </tr>
  <tr>
    <td class="entryform"><?php echo $quote; ?></td>
  </tr>
  <tr>
    <td class="entryform"><?php echo $book; ?></td>
  </tr>
  <tr>
    <td class="entryform"><?php echo $music; ?></td>
  </tr>
  <tr>
    <td class="entryform"><?php echo $entry; ?></td>
  </tr>
</table>

  
  
  
<table width="370" border="0" align="right" cellpadding="2" cellspacing="0">
  <tr>
    <td class="entryfooter"><?php

        $result2 = mysql_query ("SELECT id FROM php_blog_comments WHERE entry='$id'");
        $num_rows = mysql_num_rows($result2);

        if ($num_rows > 0) {
            echo "<a href=\"index.php?id=" . $id . "\">" .  $num_rows  . "comments</a>";
        }
        else {
            echo "<a href=\"index.php?id=" . $id . "\">Leave a comment</a>";
        } ?></td>
  </tr>
</table>

<!-- BLOG ENTRY -->

<p align="center">
<?php
$sql_prev = "SELECT * FROM php_blog WHERE id < '$id' ORDER BY id DESC LIMIT 1";
$result_prev = mysql_query ($sql_prev) or print ("Can't select previous entry id table php_blog.<br />" . $sql_prev . "<br />" . mysql_error());
while ($row = mysql_fetch_array($result_prev)) {
    $prev = $row['id'];
}if (isset($prev)) {
    // print a previous link
    printf("<a href=\"index.php?id=%s\">Previous</a> -- ", $prev);
}
else {
    // just print the word "previous"
    print "Previous -- ";
}

$sql_next = "SELECT * FROM php_blog WHERE id > '$id' ORDER BY id LIMIT 1";
$result_next = mysql_query ($sql_next) or print ("Can't select next entry id table php_blog.<br />" . $sql_next . "<br />" . mysql_error());

while ($row = mysql_fetch_array($result_next)) {
    $next = $row['id'];
}

if (isset($next)) {
    // print a next link
    printf("<a href=\"index.php?id=%s\">Next</a>", $next);
}
else {
    // just print the word "next"
    print "Next";
}    

    }

$commenttimestamp = strtotime("now");

$sql = "SELECT * FROM php_blog_comments WHERE entry='$id' ORDER BY timestamp";
$result = mysql_query ($sql) or print ("Can't select comments from table php_blog_comments.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {
    $timestamp = date("l F d Y", $row['timestamp']);
  
    print("<p>" . stripslashes($row['comment']) . "</p>");
    printf("<p>Comment by <a href=\"%s\">%s</a> @ %s</p>", stripslashes($row['url']), stripslashes($row['name']), $timestamp);
  
}





?>






<!-- COMMENT FORM -->

<form method="post" action="process.php">

<p class="content"><input type="hidden" name="entry" id="entry" value="<?php echo $id; ?>" />
<input type="hidden" name="timestamp" id="timestamp" value="<?php echo $commenttimestamp; ?>">

<table width="370" border="0" cellpadding="0" cellspacing="0" class="content">
  <tr class="commentsformtop">
    <td colspan="2"><div align="center">
      <strong>Post Comment</strong>
    </div></td>
  </tr>
  <tr class="commentslook">
    <td width="83"><label for="Name">Name:</label></td>
    <td width="299"><input type="text" name="name" id="name" size="30" /></td>
  </tr>
  <tr class="commentslook">
    <td><label for="Email">E-mail:</label></td>
    <td><input type="text" name="email" id="email" size="30" /></td>
  </tr>
  <tr class="commentslook">
    <td valign="top"><label for="URL">URL:</label></td>
    <td><input type="text" name="url" id="url" size="30" value="http://" /></td>
  </tr>
  <tr class="commentslook">
    <td valign="top">Comment:</td>
    <td><textarea cols="30" rows="5" name="comment" id="comment"></textarea></td>
  </tr>
  <tr class="commentslook">
    <td colspan="2" valign="top"><div align="center">
      <input type="submit" name="submit_comment" id="submit_comment" value="Add Comment" />
    </div></td>
  <tr class="commentsformtop">
    <td colspan="2" valign="top">&nbsp;</td>
  </tr>
</table>

</form>
<br>
</div>



submitform.php
CODE
<?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="<?php echo $current_month; ?>"><?php echo $current_month; ?></option>
<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="<?php echo $current_date; ?>" />

<select name="year" id="year">
<option value="<?php echo $current_year; ?>"><?php echo $current_year; ?></option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2008</option>
<option value="2010">2010</option>
</select>

<strong><label for="time">Time:</label></strong> <input type="text" name="time" id="time" size="5" value="<?php echo $current_time; ?>" /></p>

<p>Title:<input type="text" name="title" name="title" size="40" /></p>
<p>Currently Listening To:<input type="text" name="listening" name="listening" size="40" /></p>
<p>Currently Reading:<input type="text" name="reading" name="reading" size="40" /></p>
<p>Thoughtful:<input type="text" name="quote" name="quote" 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
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'];

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

    $entry = nl2br($entry);

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

    mysql_connect ('*****', '*****', '*****');
    mysql_select_db ('*****');

    $sql = "INSERT INTO php_blog (timestamp,title,entry) VALUES ('$timestamp','$title','$entry')";

    $result = mysql_query($sql) or print("Can't insert into table php_blog.<br />" . $sql . "<br />" . mysql_error());

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

    mysql_close();
}
?>


Any help?
Amelie
You're using the wrong names...

CODE
$listening = stripslashes($row['music']);
    $reading = stripslashes($row['book']);
    $quote = stripslashes($row['quote']);

  
  <tr>
    <td class="entryform"><?php echo $quote; ?></td>
  </tr>
  <tr>
    <td class="entryform"><?php echo $book; ?></td>
  </tr>
  <tr>
    <td class="entryform"><?php echo $music; ?></td>
  </tr>


...you need to make sure those bottom variables match the top ones, e.g. <?php echo $book; ?> should actually be <?php echo $reading; ?> since you specified $reading = stripslashes($row['book']);.

Change that bottom part of the code to this:

CODE
  <tr>
    <td class="entryform"><?php echo $quote; ?></td>
  </tr>
  <tr>
    <td class="entryform"><?php echo $reading; ?></td>
  </tr>
  <tr>
    <td class="entryform"><?php echo $listening; ?></td>
  </tr>
Phenix
That didn't work. sad.gif
Phenix
[ self resolved ] biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.