Jump to content

achilles1971

Members
  • Posts

    16
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

achilles1971's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. <?php ## Blog Manager?> <?php if (isset($_POST['submitted']) == 1) { if ($_GET['id'] == '') { if ($_POST['title'] =='' || $_POST['body'] == '') { header('Location: index.php?page=blog'); } else { $title = $_POST['title']; $date = $_POST['date']; $body = $_POST['body']; $q = "INSERT INTO blog (title, date, body) VALUES ('$title', '$date', '$body')"; } }else { $q = "UPDATE blog SET title = '$_POST[title]', date = '$_POST[date]', body = '$_POST[body]' WHERE id = '$_POST[id]'"; } $r = mysqli_query($dbc, $q); } ?> < h2>ATOM.CMS Blog Manager</h2> <div class="col sidebar"> <ul class="nav_side"> <li><a href="?page=blog">+ Add Post</a></li> <?php $q = "SELECT * FROM blog ORDER BY date ASC"; $r = mysqli_query($dbc, $q); if ($r) { while ($link = mysqli_fetch_assoc($r)) { echo '<li><a href="?page=blog&id='.$link['id'].'">'.$link['title'].'</a></li>'; } } ?> </ul> < /div> < div class="col editor"> < h1> <?php if (isset($_GET['id'])) { $q = "SELECT * FROM blog WHERE id = '$_GET[id]' LIMIT 1"; $r = mysqli_query($dbc, $q); $opened = mysqli_fetch_assoc($r); echo 'Editing: '.$opened['title']; } else { echo 'Add a New Blog Post'; } ?> < /h1> <form action="?page=blog&id=<?php if (isset($_GET['id'])){echo $opened['id'];} ?>" method="post"> <table class="gen_form"> <tr> <td class="gen_label"><label>Blog title: </label></td> <td><input class="gen_input" type="text" size="30" name="title" value="<?php if (isset($_GET['id'])){echo $opened['title'];} ?>" /></td> </tr> <tr> <td class="gen_label"><label>Blog date: </label></td> <td><input class="gen_input" type="text" size="30" name="date" value="<?php if (isset($_GET['id'])){echo $opened['date'];} ?>"/></td> </tr> <tr> <td class="gen_label"></td> </tr> <tr> <td colspan="2" class="gen_label"><label>Blog body: </label></td> </tr> <tr> <td colspan="2"><textarea id="page_body" name="body" cols="90" rows="24"><?php if (isset($_GET['id'])){echo $opened['body'];} ?></textarea></td> </tr> <tr> <td colspan="2"><input class="gen_submit" type="submit" name="submit" value="Save Changes" /></td> </tr> <input type="hidden" name="submitted" value="1" /> <input type="hidden" name="id" value="<?php if (isset($_GET['id'])){echo $opened['id'];} ?>" /> </table> </form> <?php ?> </div> Two problems: 1. The timestamp being inserted into the database is 0000-00-00 00:00:00 2. The body content is being inserted into the database with paragraph tags around it (I am using Redactor WYSIWYG for the body field). What could be causing these two issues?
  2. Okay...here is the solution: <?php ## Blog Manager?> <?php if (isset($_POST['submitted']) == 1) { if ($_GET['id'] == '') { if ($_POST['title'] =='' || $_POST['body'] == '') { header('Location: index.php?page=blog'); } else { $title = $_POST['title']; $date = $_POST['date']; $body = $_POST['body']; $q = "INSERT INTO blog (title, date, body) VALUES ('$title', '$date', '$body')"; } }else { $q = "UPDATE blog SET title = '$_POST[title]', date = '$_POST[date]', body = '$_POST[body]' WHERE id = '$_POST[id]'"; } $r = mysqli_query($dbc, $q); } ?> <h2>ATOM.CMS Blog Manager</h2> <div class="col sidebar"> <ul class="nav_side"> <li><a href="?page=blog">+ Add Post</a></li> <?php $q = "SELECT * FROM blog ORDER BY date ASC"; $r = mysqli_query($dbc, $q); if ($r) { while ($link = mysqli_fetch_assoc($r)) { echo '<li><a href="?page=blog&id='.$link['id'].'">'.$link['title'].'</a></li>'; } } ?> </ul> </div> <div class="col editor"> <h1> <?php if (isset($_GET['id'])) { $q = "SELECT * FROM blog WHERE id = '$_GET[id]' LIMIT 1"; $r = mysqli_query($dbc, $q); $opened = mysqli_fetch_assoc($r); echo 'Editing: '.$opened['title']; } else { echo 'Add a New Blog Post'; } ?> </h1> <form action="?page=blog&id=<?php if (isset($_GET['id'])){echo $opened['id'];} ?>" method="post"> <table class="gen_form"> <tr> <td class="gen_label"><label>Blog title: </label></td> <td><input class="gen_input" type="text" size="30" name="title" value="<?php if (isset($_GET['id'])){echo $opened['title'];} ?>" /></td> </tr> <tr> <td class="gen_label"><label>Blog date: </label></td> <td><input class="gen_input" type="text" size="30" name="date" value="<?php if (isset($_GET['id'])){echo $opened['date'];} ?>"/></td> </tr> <tr> <td class="gen_label"></td> </tr> <tr> <td colspan="2" class="gen_label"><label>Blog body: </label></td> </tr> <tr> <td colspan="2"><textarea id="page_body" name="body" cols="90" rows="24"><?php if (isset($_GET['id'])){echo $opened['body'];} ?></textarea></td> </tr> <tr> <td colspan="2"><input class="gen_submit" type="submit" name="submit" value="Save Changes" /></td> </tr> <input type="hidden" name="submitted" value="1" /> <input type="hidden" name="id" value="<?php if (isset($_GET['id'])){echo $opened['id'];} ?>" /> </table> </form> <?php ?> </div> Two problems: 1. The timestamp being inserted into the database is 0000-00-00 00:00:00 2. The body content is being inserted into the database with paragraph tags around it (I am using Redactor WYSIWYG for the body field). What could be causing these two issues?
  3. I am working through a Create a CMS tutorial and I am on the very last step, but I am hung up. My code is below. It is supposed to pull up a blank form when you want to add a new blog post and it is supposed to populate the field when you want to edit a previous blog post. That all works fine. The edit a blog post functionality works as it should. My problem is when I submit a new blog post, the data does not get sent to the database. Any ideas where I may have gone wrong? Aaron <?php ## Blog Manager?> <?php if (isset($_POST['submitted']) == 1) { if ($_GET['id'] == '') { $q = "INSERT INTO blog (title, date, body) VALUES ('$_POST[title]', '$_POST[date]', '$_POST[body]'"; }else { $q = "UPDATE blog SET title = '$_POST[title]', date = '$_POST[date]', body = '$_POST[body]' WHERE id = '$_POST[id]'"; } $r = mysqli_query($dbc, $q); } ?> <h2>ATOM.CMS Blog Manager</h2> <div class="col sidebar"> <ul class="nav_side"> <li><a href="?page=blog">+ Add Post</a></li> <?php $q = "SELECT * FROM blog ORDER BY date ASC"; $r = mysqli_query($dbc, $q); if ($r) { while ($link = mysqli_fetch_assoc($r)) { echo '<li><a href="?page=blog&id='.$link['id'].'">'.$link['title'].'</a></li>'; } } ?> </ul> </div> <div class="col editor"> <h1> <?php if (isset($_GET['id'])) { $q = "SELECT * FROM blog WHERE id = '$_GET[id]' LIMIT 1"; $r = mysqli_query($dbc, $q); $opened = mysqli_fetch_assoc($r); echo 'Editing: '.$opened['title']; } else { echo 'Add a New Blog Post'; } ?> </h1> <form action="?page=blog&id=<?php if (isset($_GET['id'])){echo $opened['id'];} ?>" method="post"> <table class="gen_form"> <tr> <td class="gen_label"><label>Blog title: </label></td> <td><input class="gen_input" type="text" size="30" name="title" value="<?php if (isset($_GET['id'])){echo $opened['title'];} ?>" /></td> </tr> <tr> <td class="gen_label"><label>Blog date: </label></td> <td><input class="gen_input" type="text" size="30" name="date" value="<?php if (isset($_GET['id'])){echo $opened['date'];} ?>"/></td> </tr> <tr> <td class="gen_label"></td> </tr> <tr> <td colspan="2" class="gen_label"><label>Blog body: </label></td> </tr> <tr> <td colspan="2"><textarea id="page_body" name="body" cols="90" rows="24"><?php if (isset($_GET['id'])){echo $opened['body'];} ?></textarea></td> </tr> <tr> <td colspan="2"><input class="gen_submit" type="submit" name="submit" value="Save Changes" /></td> </tr> <input type="hidden" name="submitted" value="1" /> <input type="hidden" name="id" value="<?php if (isset($_GET['id'])){echo $opened['id'];} ?>" /> </table> </form> </div>
  4. SQL was throwing an error because the fields are case sensitive. Since I wasn't using the same case, there was no data.
  5. OK, I changed it to the following: if (isset($_GET['page'])) { $pg = $_GET['page']; }else{ $pg = 'home'; } Now I get two unidentified index errors in the following lines; echo '<h1>'.$page['title'].'</h1>'; echo '<div class="content_body">'.$page['body'].'</div>';
  6. Isn't that what is happening inside the "check if page variable is set" comment at the top?
  7. SELECT * FROM `pages` WHERE `NAME` = '' AND `STATUS` = 1 LIMIT 1 That's what I'm talking about...no $pg single quotes after `NAME`=
  8. Nothing... It's like $pg is not getting passed to the query
  9. Thanks for the reply, Jessica. The query returns no errors.
  10. I am working through a php CMS tutorial and I can't get my data to display. It's like my variable ($pg) is invisible. If I uncomment the first include in the content div, I get an error that content/.php can't be found (notice the missing file name). I am passing the values of home, blog, contact and gallery through the URL. I have home.php, blog.php, contact.php and gallery.php in a folder called content. Each of the files contains lorem ipsum text and that's all. I have added an error check and I get no errors...just an empty div. My code is as follows: <?php // Setup document: include ('config/setup.php'); //--------------------------------------------------- //Check if page variable is set if ($_GET['page']='') { $pg = 'home'; }else{ $pg = $_GET['page']; } //--------------------------------------------------- ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Dynamic Sites LLC</title> <link rel="stylesheet" type="text/css" href="css/styles.css"> </head> <body> <div class="header temp_block"> <?php include ('template/header.php');?> </div> <div class="nav_main temp_block"> <?php include ('template/nav_main.php');?> </div> <div class="content temp_block"> <?php //include ('content/' . $pg . '.php'); // database connection, query $q = "SELECT * FROM pages WHERE name = '$pg' AND status = 1 LIMIT 1"; $r = mysqli_query($dbc, $q); $page = mysqli_fetch_assoc($r); echo '<h1>'.$page['title'].'</h1>'; echo '<div class="content_body">'.$page['body'].'</div>'; ?> </div> <div class="footer temp_block"> <?php include ('template/footer.php');?> </div> </body> </html> My nav_main.php is as follows: <?php ## Main Navigation ?> <a href="index.php?page=home">Home</a> - <a href="index.php?page=gallery">Gallery</a> - <a href="index.php?page=blog">Blog</a> - <a href="index.php?page=contact">Contact Us</a> Any help would be appreciated. Aaron
  11. I have gone over posts time and again to no avail. I have checked for white spaces, output buffering is on in php.ini. Any help would be appreciated. Here is the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Eatnlocal.com</title> <?php ob_start(); $name = $_POST['name']; $restaurant = $_POST['restaurant']; $email = $_POST['email']; ?> </head> <body> <?php if (strlen($name) > 0 && strlen($restaurant) > 0 && strlen($email) > 0){ header("Location: http://www.eatnlocal/info/info_ad.php"); exit(); } else{ echo "Please enter all information. Click "?><a href = "index.php">Here</a><?php echo" to go back."; } ?> </body> </html> Here is the warning: Warning: Cannot modify header information - headers already sent by (output started at /home/content/41/5771941/html/info/eatnlocal_validate.php:6) in /home/content/41/5771941/html/info/eatnlocal_validate.php on line 17
  12. Here is my form: <FORM action="eatnlocal_validate.php" method="post"> <P> Name: <INPUT type="text" id="name"><BR> Restaurant name: <INPUT type="text" id="restaurant"><BR> Email: <INPUT type="text" id="email"><BR> <input type="submit" value="Submit" name="submit"> </P> </FORM> Here is my eatnlocal_validate.php: <?php if (isset($_POST['name']) && isset($_POST['restaurant']) && isset($_POST['email'])){ $name = $_POST['name']; $restaurant = $_POST['restaurant']; $email = $_POST['email']; header("Location: info_ad.php"); } else{ echo "Please enter all information. Click "?><a href = "info_form.php">Here</a><?php echo" to go back."; } ?> When I enter info into all three fields, I still get the else function. What am I doing wrong? Thanks
×
×
  • 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.