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

  • SEARCH
  • Home
  • 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 8002093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:15:51+00:00 2026-06-04T16:15:51+00:00

// query $sql = INSERT INTO tool (title,details) VALUES (:title,:details) ; $q = $conn->prepare($sql);

  • 0
// query
$sql = "INSERT INTO tool (title,details) VALUES (:title,:details) ";
$q = $conn->prepare($sql);
$q->execute(array(':details'=>$details,
                  ':title'=>$title));

Been having trouble with this all day, I’ve finally got it down to this. If I use the above code, it will just add a new post to the database. This is supposed to be used for editing a post, so obviously I need to edit existing information:

// query
$post = htmlspecialchars($_GET['story']);
$sql = "UPDATE  tool SET (title,details) VALUES (:title,:details) WHERE id = $post";
$q = $conn->prepare($sql);
$q->execute(array(':details'=>$details,
                  ':title'=>$title));

‘id’ is a column in the database. I need it to update the title, and details, for that specific post. I’m just not sure what syntax I’m supposed to be using here.

Thanks for any answers!

===== Second question:

Now I’m back to my old error. Whenever I edit a post, it will lose the title and details, only once. The first time I edit the post, I lose all information, but the rest of the times it will work just fine. Any idea why? Heres the code:

Form from the edit page(may or may not be important, I don’t know):

$name = $_SESSION['Username'];
if (in_array($name, $allowedposters)) {
$results = mysql_query("SELECT * FROM tool WHERE id = $post");
    while($row = mysql_fetch_array($results)){


$title= $row['title'];
$details= $row['details'];
$date= $row['date'];
$author= $row['author'];
$id= $row['id'];



echo "<a href=story.php?id=";
echo $post;
echo ">Cancel edit</a> <br><br><b>";
echo $title;
echo "</b> <br><br>";
echo '
<form action="edit-new.php?story=';
echo $id;
echo '" method="post" enctype="multipart/form-data">
<textarea rows="1" cols="60" name="title" wrap="physical" maxlength="100">';
echo $title;
echo '</textarea><br>';
?>



<textarea rows="30" cols="60" name="details" wrap="physical" maxlength="10000">
<?php 
echo $details;
echo '</textarea><br>';

echo '<label for="file">Upload featured image:</label><br>
      <input type="file" name="file" id="file" />';
echo'<br><input type="submit" />';
}

} else {
  echo "Not enough permissions.";
}
?>

Here is the SQL, inserting into DB:

<?php
   $post = htmlspecialchars($_GET['story']);
   $title = mysql_real_escape_string($_POST['title']);
   $details = mysql_real_escape_string($_POST['details']);
      echo "B<br>";
      echo $_POST['title'];
      echo '<br>';
      echo $_POST['details'];
      echo $post;
      echo "<br><br>";


// configuration
$dbtype     = "mysql";
$dbhost     = "localhost";
$dbname     = "zzzz";
$dbuser     = "zzzzz";
$dbpass     = "zzzzzz";

// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);

// new data


// query
$sql = "UPDATE  tool SET title=:title, details=:details WHERE id = :postid";
$q = $conn->prepare($sql);
$q->execute(array(
  ':details'=>$details,
  ':title'=>$title,
  ':postid' => $post
));




?>
  • 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-06-04T16:15:53+00:00Added an answer on June 4, 2026 at 4:15 pm

    Fix your sql UPDATE syntax

    $sql = "UPDATE  tool SET title=:title, details=:details WHERE id = :postid";
    $q = $conn->prepare($sql);
    $q->execute(array(
      ':details'=>$details,
      ':title'=>$title,
      ':postid' => $post
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I'm tring the following sql query : $sql = mysql_query(INSERT INTO feeds (FileLocation,Title,feeddate,nameofuploader,type)
I have comma-separated values. I need a query to insert into SQL Server 2008
My goal is sql-escaping in bulk-insert query. Eg: INSERT INTO log VALUES (0,5,-7,'str'), (4,0,0,'str'),
The following SQL query: INSERT INTO `database`.`table` (`param1`, `param2`) VALUES ( 'Новости Томска –
I have this SQL query: insert into messages (message, hash, date_add) values ('message', 'hash',
I tried the below sql query INSERT INTO test.ACT_QUERY values(2139,2,'SELECT ''D'',ORDER_ID from dual'); When
I have an SQL query that goes like this: $stmt = $dbh->prepare(INSERT INTO Places
In my SQL query: insert into Tbl_EmpMovement_T values ( '004101', '2011-8-26', CONVERT(datetime,convert(varchar(10),'2011-8-26',120)+' ' +
I am getting the following error when try to save. SQL Query: INSERT INTO
I have a query as follows: String SQL = insert into table (id, name)

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.