Jump to content

cannot execute query


wikedawsum

Recommended Posts

Now that my <a href="http://www.phpfreaks.com/forums/index.php/topic,120298.0.html">other problem</a> was solved, I keep getting the "could not execute query" error when trying to register. I think the problem lies somewhere in my database connection, and user authentication files. The codes are listed below.

db_fns.php (password has been removed)
[code]<?php

function db_connect()
{
  $result = new mysqli('mysql.aacapartsandsupplies.com', 'admin', '******');
  if (!$result)
    throw new Exception('Could not connect to database server');
  else
    return $result;
}

?>[/code]

user_auth_fns.php
[code]<?php

function register($fname, $lname, $cname, $email, $username, $passwd, $no_tokens)
{
  $conn = db_connect();
 
  $result = $conn->query("select * from user where username='$username'");
  if (!$result)
    throw new Exception('Could not execute query');
  if ($result->num_rows>0)
    throw new Exception('That username is taken. Go back and choose another one.');

  $result = $conn->query("insert into user values('$fname, $lname, $cname, $email, $username, sha1($passwd), $no_tokens')");
  if (!$result)
    throw new Exception('Could not register you in the database. Please try again later.');

  return true;
}

?>[/code]

Anyone have any ideas? Thanks so much in advance.
Link to comment
https://forums.phpfreaks.com/topic/32216-cannot-execute-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.