Jump to content

MjM8082

Members
  • Posts

    92
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

MjM8082's Achievements

Member

Member (2/5)

0

Reputation

  1. What exactly does mysql_real_escape_string do? And please give examples not just what it is. Thanks
  2. I didn't need like basically anything you guys mentioned... I got it working with this code... include "connect_to_mysql.php"; if (isset($_POST['submit'])) { $title = $_POST['title']; $content = $_POST['content']; $post_id = $_GET['post_id']; $sql = "UPDATE posts SET title ='". $title ."', content ='". $content ."'WHERE post_id = $post_id"; mysql_query($sql); I was just looking for basic code like this from the start, you guys made it seem so confusing when it was just missing a few "" here and there.
  3. Here is my code exactly how it looks in my program. <form action="" method="post"> Title<input type="text" name="title" value="<?php echo $row['title']; ?>" /><br/></br> Content</br><textarea name="content" cols="50" rows="10"><?php echo $row['content']; ?></textarea><br/> <input type="hidden" name="post_id" value="<?php $_GET['post_id'] ?>" /> <input type="submit" name="submit" value="Edit" /> <input type="button" value="Back" ONCLICK="window.location.href='edit_post.php'"/> </form> </font> </p> <?php include "connect_to_mysql.php"; if (isset($_POST['submit'])) { $post_id = isset($_POST['post_id']) $_POST['post_id'] : ''; $title = isset($_POST['title']) mysql_real_escape_string($_POST['title']) : ''; $content = isset($_POST['content']) mysql_real_escape_string($_POST['content']) : ''; if ( $post_id > 0 ){ $sql = ("UPDATE posts SET title='$title', content='$content' WHERE post_id = $post_id"); mysql_query($sql); echo 'Post has been updated!</a><br /></br>'; } ?>
  4. Just wondering what the best program is for coding. I use Notepad++ What do you use ones are the best?
  5. I've been messing around with the things you mentioned but I seem to still be getting a error because nothing is changing in the database when I hit update.
  6. I got the text box problem to work.. I'm working on my update statement now. Here is my code <form action="" method="post"> Title<input type="text" name="title" value="<?php echo $row['title']; ?>" /><br/></br> Content</br><textarea name="content" cols="50" rows="10"><?php echo $row['content']; ?></textarea><br/> <input type="hidden" name="post_id" value="<?php $post_id; ?>" /> <input type="submit" name="submit" value="Edit" /> </form> </font> </p> <?php if (isset($_POST['submit'])) { $post_id = (int)$_GET['post_id']; $sql = ("UPDATE posts SET 'title'='$_POST[title]', content='$_POST[content]' WHERE post_id = '$post_id'"); echo 'Post has been updated!</a><br /></br>'; } ?> Having trouble getting it to work. Is the update statement similar to a INSERT statement?
  7. Okay I will make those changes. Right now I'm not worrying about it updating in the database, first I just want to information to display into and fill the form from the database.
  8. When I click on the post I want to update it brings me to the next page to a blank form. I'm trying to make it so the form has all the information from the database in it so the user and change it and then click update. For some reason my form just keeps showing up blank and wont display the database data. Here is the update page that includes the form... <?php include "connect_to_mysql.php"; if (!isset($_POST['submit'])) { $post_id = (int)$_GET['post_id']; $sql = mysql_query ("SELECT * FROM posts WHERE post_id = '$post_id'"); $results = mysql_query($sql); $row = mysql_fetch_array($results); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Title<input type="text" name="title" value="<?php echo $row['title']; ?>" /><br/> Content<input type="text" name="content" value="<?php echo $row['content']; ?>" /><br/> <input type="hidden" name="id" value="<?php $post_id; ?>" /> <input type="submit" name="submit" value="Edit" /> </form> </font>
  9. Hey thanks man, so would this work the same way if I wanted to delete the title of the post from the database instead of the entire row?
  10. I created a blog and what I am trying to delete a post when I click the delete button underneath the post. I have messed around with this for a while and can't seem to figure out why it is not working. Here is my code on the post page... include "connect_to_mysql.php"; $sql = "SELECT * FROM posts ORDER BY time_posted DESC"; $results = mysql_query($sql); while($row = mysql_fetch_array($results)) { echo "</br>"; echo "</br>"; echo $row['title'] ."</br>"; echo $row['date_posted'] . "<br />"; echo $row['time_posted'] ."</br></br>"; echo $row['content'] . "<br /></br>"; echo "<a href=\"delete_post.php?post_id=" . $row['post_id'] . "\">Delete</a>"; Here is my delete_post page. include "connect_to_mysql.php"; // SQL query $sql = mysql_query ("DELETE FROM posts WHERE post_id = '$post_id'"); echo 'Post has been deleted! </br></br>Go to blog home!<a href="index.php">Click Here</a><br /></br>'; Just so you know post_id is the name of the id's in the database.. so I know my names are not wrong.
  11. Notice: Undefined index: title in /home6/projeev1/public_html/maddykelley/blankpage.php on line 18 Notice: Undefined index: content in /home6/projeev1/public_html/maddykelley/blankpage.php on line 19 These are the errors I am getting
  12. Sorry, I am new to PHP and trying out my first time with phpmyadmin and mysql, so this is one of my first select statements, so I'm just trying to work with the knowledge I have right now.
  13. Okay I tried the new code you posted and now I just get a blank page :-\
  14. Thanks for the reply, after trying that code I still came out with the same output ... $title "; } ?> That is all that appears on the page
  15. Sorry, to be more specific my output just gives me this.... $title "; } ?> That is it. I messed around with my code multiple times and I have even tried the $sql instead of $query.
×
×
  • 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.