Kaceykaso
Kaceykaso

Reputation: 240

PHP+MySQL UPDATE query (multiple columns) not working

Ok, it's probably something simple that I'm overlooking, but I've combed through this so many times..!

Just a simple update via a PHP form, pulls in variables, builds query:

// Connect
$connect = mysql_connect('host','login','passwd');
if (!$connect) { $errors .= "Not connected : ".mysql_error(); }
$database = mysql_select_db('db', $connect);
if (!$database) { $errors .= "Could not get to that database: ".mysql_error(); }

// Update database table
$info = "UPDATE `gsa_officers` SET `term` = '2012-2013', `office` = 'President', `type` = 'Poop', `dept` = 'Visual Arts', `name` = 'Matthew W. Jarvis', `email` = '[email protected]', `blurb` = 'Serves as Chair of both the GSA Executive Committee and Council, oversees the direction of the organization and ensures the execution of its responsibilities and commitments.', `picture` = 'http://gsa.ucsd.edu/sites/gsa.ucsd.edu/files/mat%20w%20jarvis.jpg' WHERE `id` = 1";
$query = mysqli_query($info);
if (!$query) { $errors .= "Bad query: ".mysql_error(); }
mysql_close($connect);

I get no errors, it only prints out: "Bad query: "

What am I missing/doing wrong? Any extra eyeballs are appreciated ^_^

Upvotes: 0

Views: 389

Answers (4)

Bill Karwin
Bill Karwin

Reputation: 562348

You're using mysql_connect() to connect to your database server and select the db. Then you use mysqli_query() to run the query, then mysql_error() to report the error. You can't mix these API's.

You should use mysqli_* functions throughout, because the mysql_* functions are deprecated and will be removed from a future version of PHP.

Example:

// Connect
$mysqli = new mysqli('host','login','passwd','db');
if ($mysqli->connect_error) { $errors .= "Not connected : ".$mysqli->connect_error; }

// Update database table
$info = "UPDATE `gsa_officers` SET `term` = '2012-2013', `office` = 'President',
  `type` = 'Poop', `dept` = 'Visual Arts', `name` = 'Matthew W. Jarvis', 
  `email` = '[email protected]', 
  `blurb` = 'Serves as Chair of both the GSA Executive Committee and Council, oversees the direction of the organization and ensures the execution of its responsibilities and commitments.',
  `picture` = 'http://gsa.ucsd.edu/sites/gsa.ucsd.edu/files/mat%20w%20jarvis.jpg' 
  WHERE `id` = 1";
if (!$mysqli->query($info)) {
    $errors .= "Bad query: ".$mysqli->error;
}
$mysqli->close();

Upvotes: 1

Lys777
Lys777

Reputation: 456

What if you do mysql_query instead of mysqli_query?

Upvotes: 0

dimaninc
dimaninc

Reputation: 850

you connect using simple mysql (not mysqli) but use mysqli_query to send query

Upvotes: 0

Khawer Zeshan
Khawer Zeshan

Reputation: 9646

Change this line

$query = mysqli_query($info);

To

$query = mysql_query($info);

NOTE

mysql extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.

Upvotes: 0

Related Questions