0

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 ^_^

0

4 Answers 4

1

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();
1
  • Lol, ok I'm an idiot. I had it all one way, it didn't work, so I replaced it with mysqli_* and it still didn't work, so I reverted it back to the original (or so I thought). Thanks, this works now :)
    – Kaceykaso
    Commented Jul 17, 2013 at 23:05
0

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.
1
  • Damn, this is good to know! I just got back into mysql recently, after using Oracle SQL for a long time; I had no idea they were changing all the extensions! Thanks!
    – Kaceykaso
    Commented Jul 17, 2013 at 23:09
0

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

0

What if you do mysql_query instead of mysqli_query?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.