Jump to content

[SOLVED] query help


tom232

Recommended Posts

THE CODE
$result = $conn->query(" select * from user where username='$username' ");
and
$result = $conn->query("insert into user values ('$username', sha1('$password'), '$email')");

ERROR (same error)
Fatal error: Call to a member function query() on a non-object in /home/u7/collegenote/html/logtest/user_auth_fns.php on line 14

what am im missing? this has been driving me crazy
Link to comment
https://forums.phpfreaks.com/topic/32645-solved-query-help/
Share on other sites

Heres the code

[code]<?php

require_once('db_fns.php');

function register($username, $email, $password)
// register new person with db
// return true or error message
{
  // connect to db
  $conn = mysql_connect(localhost, collegenote, OC1kl07r);
 
  // check if username is unique
  $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.');


  // if ok, put in db
  $result = $conn->query("insert into user values
                        ('$username', sha1('$password'), '$email')");
  if (!$result)
    throw new Exception('Could not register you in database - please try again later.');

  return true;
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/32645-solved-query-help/#findComment-151895
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.