Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

php/mysql problems


ghost's Avatar
0 0

Hello everyone, I'm having trouble with a php/mysql script, so I was hoping you all can help me out. I'm getting a mysql error that states,

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2) in /home/content/a/l/f/user/html/phprentals/includes/config.php on line 13 Unable to connect to database

Heres the config file: //code <? //Main variables $sitename = "PHPRentals"; $domain = "www.yourdomain.com"; //www.yourdomain.com $owneremail = "webmaster@yourdomain.com"; //name@domain.com $emailsubject = "PHPRentals Registration"; //Subject for landlord registration email

//Database connection info $hostname = "host_address"; $username = "database_name"; $password = "password"; $dbName = "database_name"; MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); @mysql_select_db( "$dbName") or die( "Unable to select database");

//landlord add image variables $abpath = "".$_SERVER['DOCUMENT_ROOT']."/phprentals/images/"; //Absolute path to where images are uploaded. No trailing slash $sizelim = "yes"; //Do you want size limit, yes or no $max_size = "25000000"; //What do you want size limited to be if there is one

?>

//code

and this is the source for the page thats not connecting:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">

</HEAD> <BODY NOF="(MB=(DefaultMasterBorder, 0, 0, 0, 0), L=(HomeLayout, 600, 671))" BGCOLOR="#FFFFFF" TEXT="00000" TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>

<? include ("".$_SERVER['DOCUMENT_ROOT']."/phprentals/includes/header.php"); ?> <CENTER>

&lt;TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 NOF=LY&gt;
    &lt;TR VALIGN=TOP ALIGN=LEFT&gt;
        &lt;TD WIDTH=600&gt;
            &lt;FORM ACTION=&quot;/phprentals/html/baseresults.php&quot; METHOD=POST&gt;
                &lt;TABLE ID=&quot;Table2&quot; BORDER=0 CELLSPACING=0 CELLPADDING=4 WIDTH=&quot;100%&quot;&gt;
                    &lt;TR&gt;
                        &lt;TD COLSPAN=2&gt;
                            &lt;P&gt; &lt;/P&gt;
                        &lt;/TD&gt;
                    &lt;/TR&gt;
                    &lt;TR&gt;
                        &lt;TD COLSPAN=2 VALIGN=TOP&gt;

<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=592 NOF=TI> <TR> <TD> <P ALIGN=LEFT><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif"><B><U>PHPRentals Demo</u></b><p>This is the demo for our property management/phprentals listing software. Use the links or the form below to search the listings database.</FONT></P> <P ALIGN=LEFT><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">Landlords have a password protected area where they can Add/Edit/Delete their listings. Follow the links above to visit the landlords area. You can login with <B>user:</B> guest <B>pass:</B> guest . The ability to edit the current listings has been disabled. The location dropdown box below is database driven, so when a new city is added, it will appear in the box.</FONT></P> <P ALIGN=LEFT><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">There is also a website owner admin area to let you administer the landlords, view/edit all listings </FONT></B></P> </TD> </TR> </TABLE> </TD> </TR> <TR BGCOLOR="#FFFFCC"><TD colspan=2><P ALIGN=CENTER><B><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">View all listings in an area</TD></TR> <TR> <TD COLSPAN=2 VALIGN=TOP><P><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif"> <? include ("".$_SERVER['DOCUMENT_ROOT']."/phprentals/includes/config.php"); $selectquery = "SELECT DISTINCT city FROM listings"; //echo "$selectquery"; $result = mysql_query($selectquery) or die ("Query failed");

while ($row = mysql_fetch_array($result)) { $city=urlencode($row["city"]); echo "<a href=\"/phprentals/html/link.php?city=$city\">".$row["city"]."</a><BR>"; } ?></FONT></P><BR> </TD> </TR> <TR> <TD COLSPAN=2 VALIGN=TOP ALIGN=CENTER BGCOLOR="#FFFFCC"> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=592 NOF=TI> <TR> <TD> <P ALIGN=CENTER><B><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">Search Form</FONT></B></P> </TD> </TR> </TABLE> </TD> </TR> <TR> <TD WIDTH=172> <P> </P> </TD> <TD WIDTH=412> <P> </P> </TD> </TR> <TR> <TD VALIGN=MIDDLE WIDTH=172> <P><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">Location</FONT></P> </TD> <TD VALIGN=MIDDLE WIDTH=412> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=412 NOF=TI> <TR> <TD> <P> <SELECT NAME="city"> <?php $selectquery = "SELECT DISTINCT city FROM listings"; //echo "$selectquery"; $result = mysql_query($selectquery) or die ("Query failed");

while ($row = mysql_fetch_array($result)) { echo "<OPTION VALUE=\"".$row["city"]."\" SELECTED>".$row["city"]."</OPTION>"; } ?> </SELECT> </TD> </TR> </TABLE> </TD> </TR> <TR> <TD VALIGN=MIDDLE WIDTH=172> <P><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">Home or Apartment</FONT></P> </TD> <TD VALIGN=MIDDLE WIDTH=412> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=412 NOF=TI> <TR> <TD> <P> <SELECT NAME="rtype"> <OPTION VALUE="Home" SELECTED>Home</OPTION> <OPTION VALUE="Apartment">Apartment</OPTION> <OPTION VALUE="Apartment">Duplex</OPTION> </SELECT> </TD> </TR> </TABLE> </TD> </TR> <TR> <TD VALIGN=MIDDLE WIDTH=172 HEIGHT=16> <P><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">Bedrooms</FONT></P> </TD> <TD VALIGN=MIDDLE WIDTH=412> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=412 NOF=TI> <TR> <TD> <P> <SELECT NAME="brooms"> <OPTION VALUE="1" SELECTED>1</OPTION> <OPTION VALUE="2">2</OPTION> <OPTION VALUE="3">3</OPTION> <OPTION VALUE="4">4</OPTION> </SELECT> </TD> </TR> </TABLE> </TD> </TR> <TR> <TD VALIGN=MIDDLE WIDTH=172> <P><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">Bathrooms</FONT></P> </TD> <TD VALIGN=MIDDLE WIDTH=412> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=412 NOF=TI> <TR> <TD> <P> <SELECT NAME="bath"> <OPTION VALUE="1" SELECTED>1</OPTION> <OPTION VALUE="2">2</OPTION> <OPTION VALUE="3">3</OPTION> <OPTION VALUE="4">4</OPTION> </SELECT> </TD> </TR> </TABLE> </TD> </TR> <!–<TR> <TD VALIGN=MIDDLE WIDTH=172> <P><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">Pets</FONT></P> </TD> <TD VALIGN=MIDDLE WIDTH=412> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=412 NOF=TI> <TR> <TD> <P> <SELECT NAME="pets"> <OPTION VALUE="%" SELECTED>Not Important</OPTION> <OPTION VALUE="Yes">Yes</OPTION> <OPTION VALUE="No">No</OPTION> </SELECT> </TD> </TR> </TABLE> </TD> </TR> <TR> <TD VALIGN=MIDDLE WIDTH=172> <P><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">Garage</FONT></P> </TD> <TD VALIGN=MIDDLE WIDTH=412> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=412 NOF=TI> <TR> <TD> <P> <SELECT NAME="gar"> <OPTION VALUE="%" SELECTED>Not Important</OPTION> <OPTION VALUE="Yes">Yes</OPTION> <OPTION VALUE="No">No</OPTION> </SELECT> </TD> </TR> </TABLE> </TD> </TR> <TR> <TD VALIGN=MIDDLE WIDTH=172> <P><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">Yard</FONT></P> </TD> <TD VALIGN=MIDDLE WIDTH=412> <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=412 NOF=TI> <TR> <TD> <P> <SELECT NAME="yd"> <OPTION VALUE="%" SELECTED>Not Important</OPTION> <OPTION VALUE="Yes">Yes</OPTION> <OPTION VALUE="No">No</OPTION> </SELECT> </TD> </TR> </TABLE> </TD> </TR>–> <TR> <TD COLSPAN=2 VALIGN=TOP> <P><BR><INPUT TYPE=SUBMIT VALUE="Search"></TD> </TR> </TABLE> </FORM> </TD> </TR> </TABLE><BR><BR> <? include ("".$_SERVER['DOCUMENT_ROOT']."/phprentals/includes/footer.php"); ?> </BODY> </HTML>

Thanks everyone.


ghost's Avatar
0 0

Did you try to start the MySQL server?


ghost's Avatar
0 0

hacker2k wrote: Did you try to start the MySQL server?

I assume you're asking if I set up the mysql database? If so, then yes. I'll double check to see if it's running. Thanks :)


ghost's Avatar
0 0

I changed something in the config file and now i'm getting an error that says, "Unable to select database. I'm going to google this, but if anyone has dealt with this problem before I would appreciate any input, thanks.


ghost's Avatar
0 0

Fixed, Problem was in the config file.