Jump to content

Database error using jquery auto complete text box


frshjb373

Recommended Posts

I have been working on my local machine and haven't had any errors.  I just deployed my site live and I'm getting a database error in my auto-complete text box.  Any help would be much appreciated! I'm thinking there may be an error in my the way I'm naming the mysql connect names, but the fact that database data is being populated is confusing me. Wondering if something is wrong with the code? Thanks for the help in advance!

 

These are the errors:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/content/99/7862599/html/gadgetabulous/Database/filename.php on line 3

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/99/7862599/html/gadgetabulous/Database/filename.php on line 3

 

(here is a link if you want to see the error: http://gadgetabulous.com/cellphoneform.php(just type "iphone" in the search box and the error will appear))

 

Here is my db file:

<?php
    $q=$_GET['q'];
    $my_data=mysql_real_escape_string($q);
    $mysqli=mysqli_connect('host','root','password','dbname') or die("Database Error");
    $sql="SELECT name FROM cell_brands WHERE name LIKE '%$my_data%' ORDER BY name";
    $result = mysqli_query($mysqli,$sql) or die(mysqli_error());


    if($result)
    {
        while($row=mysqli_fetch_array($result))
        {
            echo $row['name']."\n";

        }
    }

mysql_close($mysqli);
?>

 

Thank you in advance for the help!

Link to comment
Share on other sites

You need to turn error reporting on in your local server.

 

You're trying to use mysql_real_escape_string before using mysql_connect. You can't do this, as stated in the manual

http://php.net/manual/en/function.mysql-real-escape-string.php

 

string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier = NULL ] )

 

Parameters

 

  $unescaped_string

    The string that is to be escaped.

 

  $link_identifier

    The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect()

    is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no

    arguments. If no connection is found or established, an E_WARNING level error is generated.

Link to comment
Share on other sites

It would look the same, only your call to mysql_real_escape_string()[/m] would come after your call to [ic]mysql_connect()

 

If you want it done for you, hire a developer. We're here to help, not fix your errors for you.

 

Also, a database driven auto-complete text box is pretty damn advanced for a beginner. I suggest starting with something easier, like basic form processing.

 

edit - I didn't notice this before, but if you're using mysqli functions, you have to stick with them. You have to use mysqli_real_escape_string

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.