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 7175775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:22:20+00:00 2026-05-28T16:22:20+00:00

I am relatively new to MySQL and PHP and I have been trying to

  • 0

I am relatively new to MySQL and PHP and I have been trying to UPDATE a table for a very long time now, I’ve searched Google and SO and I still can’t figure it out.

Here is the php:

$info = array('about_me' => NULL, 'profile_pic' => NULL, 'political_party' => NULL,         'econ_views' => NULL, 'religious_views' => NULL, 
'abortion_view' =>NULL,'gay_marraige' => NULL, 'other' => NULL);

foreach ($_POST as $key => $value) {
    $info[$key] = mysql_escape_string($value);
}

$about_me = $info['about_me'];
$profile_pic = $info['profile_pic'];
$econ_views = $info['econ_views'];
$religious_views = $info['religious_views'];
$abortion_view = $info['abortion_view'];
$gay_marraige = $info['gay_marraige'];
$other = $info['other'];
$political_party = $info['political_party'];

//Connect to database
require 'db.php';

$query = "UPDATE `users` SET `about_me`=$about_me, `profile_pic`=$profile_pic,   `econ_views`=$econ_views,
       `religious_views`=$religious_views,`abortion_view`=$abortion_view,`gay_marriage`=$gay_marraige, 
    `other`=$other, `political_party`=$political_party WHERE `username`=emoore24";

echo "$query"."<br /><br />";
$result = mysql_query($query) or die(mysql_error());

echo "success"

This is run on a form with many text areas and one select element. I ran everything with simple strings as data and got this:

UPDATE users SET about_me=test about, profile_pic=, econ_views=test econ, religious_views=test rel,abortion_view=test abortion,gay_marriage=test gay marraige, other=test other, political_party=democrat WHERE username=emoore24

You have an error in your SQL syntax; check the manual that corresponds to your MySQL >server version for the right syntax to use near ‘ econ_views=test econ, >religious_views=test rel,abortion_view=test abor’ at line 1

I’m assuming that it’s something small, but I can’t see it. Could anyone help?

  • 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-28T16:22:21+00:00Added an answer on May 28, 2026 at 4:22 pm

    You haven’t put quotes around any of your string literals.

    UPDATE `users` SET 
      `about_me`=about_me, 
      `profile_pic`=, 
      `econ_views`=test econ,  
      `religious_views`=test rel,
      `abortion_view`=test abortion,
      `gay_marriage`=test gay marraige, 
      `other`=test other, 
      `political_party`=democrat 
    WHERE `username`=emoore24
    

    Should be:

    UPDATE `users` SET 
      `about_me`='about_me', 
      `profile_pic`=NULL, 
      `econ_views`='test econ',  
      `religious_views`='test rel',
      `abortion_view`='test abortion',
      `gay_marriage`='test gay marraige', 
      `other`='test other', 
      `political_party`='democrat' 
    WHERE `username`='emoore24'
    

    If you use PDO with prepared statements, it would be a lot simpler and safer, and you won’t have to worry about quoting or escaping literals. For example, here’s how I might write that code:

    $info = array(
      'about_me' => NULL, 
      'profile_pic' => NULL, 
      'political_party' => NULL,
      'econ_views' => NULL, 
      'religious_views' => NULL, 
      'abortion_view' => NULL,
      'gay_marriage' => NULL, 
      'other' => NULL
    );
    
    $query = "UPDATE `users` SET 
          `about_me`=:about_me, 
          `profile_pic`=:profile_pic, 
          `econ_views`=:econ_views,  
          `religious_views`=:religious_views,
          `abortion_view`=:abortion_view,
          `gay_marriage`=:gay_marriage, 
          `other`=:other, 
          `political_party`=:political_party 
        WHERE `username`=:username";
    
    if (($stmt = $pdo->prepare($query)) == FALSE) {
      $err = $pdo->errorInfo(); die($err[2]);
    }
    
    $values = array_intersect_key($_POST, $info);
    $values['username'] = 'emoore24';
    
    if ($stmt->execute( $values ) == FALSE) {
      $err = $stmt->errorInfo(); die($err[2]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to PHP/MySQL and have been having a problem that I
I am relatively new to Perl.I have been trying to insert data to database
I am relatively new to MYSQL and have had an issue that has been
I'm relatively new to PHP/mySQL and I'm trying to develop a portfolio of my
I'm relatively new to mysql so bear with me. I have a table that
I'm relatively new to using PHP and have been working on using it to
Relatively new to rails and trying to model a very simple family tree with
I am relatively new to php and have a feeling that I am going
i'm relatively new to php and mysql and would like to know how to
Relatively new to mySQL so this is probably an easy one: I have a

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.