Jump to content

Recommended Posts

I get this error

 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

From this query

 

<?php
include("k_falls_dbinfo.inc.php");
mysql_connect(mysql,$username,$password);
@mysql_select_db($database) or die(mysql_error());
$query_content= "SELECT * FROM content_table WHERE item = $mynumber";
$result=mysql_query($query_content) or die(mysql_error());

echo $query_content['heading'];
echo "<BR>";
echo $query_content['image'];
echo "<BR>";
echo $query_content['description'];
echo"<BR>";
echo $query_content['description'];
?>

 

Can someone tell me whats wrong?

Link to comment
https://forums.phpfreaks.com/topic/89090-solved-mysql-error/
Share on other sites

First of all, you need the $ or static text.  If the server's on the localhost you could just change it to that with quotes around it.  After that try changing the code to this:

 

<?php
include("k_falls_dbinfo.inc.php");
mysql_connect('localhost',$username,$password); // this would have to be $mysql if it's not on the localhost
@mysql_select_db($database) or die(mysql_error());
$query_content= "SELECT * FROM `content_table` WHERE `item` = '$mynumber'";
$result=mysql_query($query_content) or die(mysql_error());
$arr = mysql_fetch_assoc($result);
extract($arr);
echo $heading;
echo "<br />";
echo $image;
echo "<br />";
echo $description;
?>

Link to comment
https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456313
Share on other sites

OK tried all of the above and I still get the error

 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

 

I also dropped the table and rebuilt it and inserted a record to test it still get the same error.

 

I ran queries on the other tables and dbs and they all work fine.

 

Thanks for taking the time to look

 

Any other suggestions??

Link to comment
https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456338
Share on other sites

I get this error

 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

From this query

 

<?php
include("k_falls_dbinfo.inc.php");
mysql_connect(mysql,$username,$password);
@mysql_select_db($database) or die(mysql_error());
$query_content= "SELECT * FROM content_table WHERE item = $mynumber";
$result=mysql_query($query_content) or die(mysql_error());

echo $query_content['heading'];
echo "<BR>";
echo $query_content['image'];
echo "<BR>";
echo $query_content['description'];
echo"<BR>";
echo $query_content['description'];
?>

 

Can someone tell me whats wrong?

 

Firstly, you're missing $ from the start of mysql.

 

However, the most prominent error I can see is here:

 

$query_content= "SELECT * FROM content_table WHERE item = $mynumber";
$result=mysql_query($query_content) or die(mysql_error());

echo $query_content['heading'];
echo "<BR>";
echo $query_content['image'];
echo "<BR>";
echo $query_content['description'];
echo"<BR>";
echo $query_content['description'];

 

 

$query_content doesn't hold any information called from the database. It just holds the mySQL query you wish to execute as a string. $result is what holds the information that has been extracted from the db. However, you can't just extract information from this so you must do:

 

while ($info = mysql_fetch_array($result)) {
echo $query_content['heading'];
echo "<BR>";
echo $query_content['image'];
echo "<BR>";
echo $query_content['description'];
echo"<BR>";
echo $query_content['description'];
}

 

What this does is loop through the raw information extracted from the database and then puts it into an array, where the keyname for each element is the column header (like, 'heading', 'image', etc).

 

I hope this helps :)

Link to comment
https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456344
Share on other sites

Codein  Thanks it did help me understand a little better about how the while loop works.

I got it working now I had to drop the db and recreat it then it worked thanks for all your help!!

 

p2grace  Yes they are they are both on the Yahoo servers Thanks for your help I now have a better understanding of mysql_fetch_assoc You guys have a great day

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456356
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.