Jump to content

connections


Constantine8

Recommended Posts

Not sure what I'm doing wrong... I'm practicing with a book program already put together.. I can get this to work on my local host but can't get it to work on my godaddy server... am I missing something in this code?

godaddy::: this one doesn't work

<?php

function db_connect()
{
$result = mysql_pconnect('site', 'book_rama', 'password');
if (!$result)
return false;
if (!mysql_select_db('book_rama'))
return false;

return $result;
}

?>


local host:::::: this works

<?php

function db_connect()
{
$result = mysql_connect('localhost');
if (!$result)
return false;
if (!mysql_select_db('book_rama'))
return false;

return $result;
}

?>



thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/29861-connections/
Share on other sites

i have tried using this and just tried again... forgive me but since i have various forms I'm not sure where to put it... i have an output form, and I have a user_auth form where my echoed error comes from::

function register($username, $email, $password)
// register new person with db
// return true or error message
{
// connect to db
 $conn = db_connect();
 if (!$conn)
   [b]return 'Could not connect to database server - please try later.';[/b]
 // check if username is unique
 $result = mysql_query("select * from user where username='$username'");
 if (!$result)
    return 'Could not execute query';
 if (mysql_num_rows($result)>0)
    return 'That username is taken - go back and choose another one.';

 // if ok, put in db
 $result = mysql_query("insert into user values
                        ('$username', password('$password'), '$email')");
 if (!$result)
   //echo mysql_error($result);
   return 'Could not register you  in database - please try again later.';
 return true;
}

Link to comment
https://forums.phpfreaks.com/topic/29861-connections/#findComment-137238
Share on other sites

not sure if this is what you meant but it doesn't seem to produce any output:

$result = mysql_query("select * from user where username='$username'")or die(mysql_error());

it also seems that the error would be before this since the bold text above is where my error occurs.  should the 'mysql_error' somehow be checking the $conn db_connect()??  or in my 'funtion db_connect' which is in a separate 'db_fns.php' form'?  

also i have this all working on a godaddy server but using different forms with different code.. so I don't think it should be my connection credentials.  I also checked that multiple times--over multiple hours.

thanks for your help.. it would be great to get this error reporting working so I can debug this problem.  
Link to comment
https://forums.phpfreaks.com/topic/29861-connections/#findComment-137252
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.