Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 549301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:10:12+00:00 2026-05-13T11:10:12+00:00

Greetings I made the following php script so that I could edit text and

  • 0

Greetings I made the following php script so that I could edit text and it would save to a db for future use. However I’m hitting a slight snag at the update / insert queries. I’m not sure what I’m doing wrong but only one of the commands will execute. I’m not sure if this is a hosting issue or am I doing something wrong.

Any ideas?

if (isset($_SESSION["logged"]) && $_SESSION["logged"]==1){  
    if ($_POST['action']=="edit"){
        $query=mysql_query("select * from page where active=1 AND heading='".$_POST['selectedpage']."'");
        $row = mysql_fetch_array($query, MYSQL_ASSOC);

        echo "<h1>HTML Editor </h1><br>";
        echo "<form name='saveform' action='./action.php'  method='post'>";
        echo "<textarea rows='100' cols='100' name='updateBox'>".$row['content']."</textarea>";
        echo "<br><input name='action' type='submit' value='save edit'>";
        echo "<input name='heading' type='hidden' value='".$row['heading']."'>";
        echo "</form>";
    } else if($_POST['action']=="save edit"){
        $query=mysql_query("UPDATE page SET active='0' where heading='".$_POST['heading']."'");
        $query=mysql_query("INSERT into page(heading,content,active) values('".$_POST['heading']."','".$_POST['updateBox']."','1')");
        echo "<p>Changes saved succesfully!</p>";
        echo "$_POST['updateBox']";
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:10:12+00:00Added an answer on May 13, 2026 at 11:10 am

    If you call echo mysql_error($query) after each query you run, you will be able to see if there is an error with that query. There could be a problem with your query content.

    You are not performing any sanitizing for SQL injection, so if your content has a quotation mark in it, it will break your query. This is fairly dangerous (your queries are vulnerable to SQL injection from user input), and you should consider using mysql_real_escape_string on all your query variables, or switching to the PDO or MySQLi drivers. These drivers support query binding, which is an excellent method to prevent SQL injection.

    Edit for editorialism 🙂

    As an aside, it’s generally pretty easy to come up with a quick database wrapper or function handler to handle these kind of errors for you automatically. I use a class-based wrapper, but if you didn’t want to go that far just now, you could do something like this:

    //very quick-and-dirty
    function queryOrDie($query)
    {
        $query = mysql_query($query);
        if (! $query) exit(mysql_error());
        return $query;
    }
    

    You could just pass all your queries through that, and you’d have an easier time of debugging it. There are a lot of database wrapper classes out there too, I’d highly recommend you take a poke around. They make life much easier. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 300k
  • Answers 300k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Properties like IsPostback depend on the Page where the user… May 13, 2026 at 8:03 pm
  • Editorial Team
    Editorial Team added an answer Session data is stored by your server. Iframes are just… May 13, 2026 at 8:03 pm
  • Editorial Team
    Editorial Team added an answer Does ByteArrayOutputStream.close() really release the memory? No. It does absolutely… May 13, 2026 at 8:03 pm

Related Questions

Greetings, SO. I have some code which I've made attempts at compiling using gcc,
Greetings! I have some HTML that may or may not be valid. If the
Greetings. I have been looking at Literate Programming a bit now, and I do
Greetings fellow earthlings. I'm researching methods of caching data retrieved from various database tables
Greetings: I have put together a RESTful web service in .NET 3.5 that takes

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.