frshjb373 Posted April 27, 2012 Share Posted April 27, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/261725-database-error-using-jquery-auto-complete-text-box/ Share on other sites More sharing options...
xyph Posted April 27, 2012 Share Posted April 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261725-database-error-using-jquery-auto-complete-text-box/#findComment-1341203 Share on other sites More sharing options...
frshjb373 Posted April 27, 2012 Author Share Posted April 27, 2012 Thank you for the reply. I am a bit of beginner...what would the code look like then, to avoid this error? Quote Link to comment https://forums.phpfreaks.com/topic/261725-database-error-using-jquery-auto-complete-text-box/#findComment-1341206 Share on other sites More sharing options...
xyph Posted April 27, 2012 Share Posted April 27, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/261725-database-error-using-jquery-auto-complete-text-box/#findComment-1341208 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.