I'm having issues as well; I have a database jokes with a couple rows already and am trying to insert another row (the ID is auto incrementing). This is what I have, as you can see I'm trying to insert a value from a form.
Here's the form

<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Type your joke here:<BR>
<TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP>
</TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
</FORM>

and the php

$joketext = $_POST['joketext'
if ("SUBMIT" == $_POST['submitjoke']) {
  $sql = "INSERT INTO Jokes VALUES ($joketext, CURDATE())";
  if (mysql_query($sql)) {
    echo("<P>Your joke has been added.</P>");
  } else {
    echo("<P>Error adding submitted joke: " .
         mysql_error() . "</P>");
  }
}

It comes back with the error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2), what does that mean?

If that is all of your code, looks like you are missing the db connect and select

$conn = mysql_connect("localhost","username","password");
        mysql_select_db("database",$conn);

//and don't forget to close

mysql_close($conn);

No, I thought that was just the code that was giving me issues; above it is:

$dbcnx = @mysql_connect("sql307.freei.me", "freei_3694379", "pass");
if (!$dbcnx) {
  echo( "<P>Unable to connect to the database server at this time.</P>" );
  exit();
}

// Select the BookStore database
mysql_select_db("freei_3694379_BookStore", $dbcnx);
if (! @mysql_select_db("freei_3694379_BookStore") ) {
  echo( "<P>Unable to locate the BookStore database at this time.</P>" );
  exit();
}

// Request the text of all the jokes
    $result = mysql_query(
              "SELECT JokeText FROM Jokes");
    if (!$result) {
      echo("<P>Error performing query: " .
           mysql_error() . "</P>");
      exit();
    }

      // Display the text of each joke in a paragraph
    while ( $row = mysql_fetch_array($result) ) {
      echo("<P>" . $row["JokeText"] . "</P>");
    }

I'm using the bookstore database because I think the free account I'm experimenting on only allows one database. And the select statement, etc is working just fine, so that confuses me even more.

This article has been dead for over six months. Start a new discussion instead.