Jump to content

Trouble connecting to SQL database from PHP


Ang

Recommended Posts

I'm very new to php and SQL (version 5.0.27).  Can someone please advise on my connection problem.  Message received is 'Unable to connect to SQL server".

 

Thank you

 

 

<html>

<body>

<HEAD>

<link rel="stylesheet" type="text/css" href="style_sheet.css" />

</HEAD>

 

<form action="EmployerDetails.php" method="post">

Thank you <?php echo $_POST["name"]; ?> and welcome..<br />

You're details have been added to our database.<br/>

 

<?php

include("$ mysql -u 112489 -h mysql.ict.school.edu.au -p 112489db ");

 

$query = "INSERT INTO users ";

    $query .= "(user_id, name, address ";

    $query .= " values(0000,'$name','$address')";

    mysql_pconnect("$ mysql -u 112489 -h mysql.ict.school.edu.au -p 112489db")

                  or die("Unable to connect to SQL server");

    mysql_select_db("tator_awtrey") or die("Unable to select database");

    mysql_query($query) or die("Insert Failed!");

 

// Show the entries in the database

function showEntries() {

  if (!($connection = @ mysql_connect("mysql -u 112489 -h mysql.ict.school.edu.au -p 112489db/users.inc", USER, PASSWORD)))

      die("Could not connect");

  if (!(mysql_select_db(DATABASE, $connection)))

      showerror();

  $query = "select name, address from users order by user_id";

  if (!($result = @ mysql_query($query, $connection)))

      showerror();

  while ($row = mysql_fetch_row($result)) {

      echo "<p>\n" . $row[0] . "\n";

      echo "<p>\n -- <a href=\"mailto:" . $row[1] . "\">"

  . $row[2] . "</a>\n";

  }

  if (!(mysql_close($connection)))

      showerror();

}

 

// Add a new entry to the database

function addEntry($name, $address) {

  if (!($connection = @ mysql_connect("localhost", USER, PASSWORD)))

    die("Could not connect");

  if (!(mysql_select_db(DATABASE, $connection)))

    showerror();

  $insert = "insert into users " .

    "values (null, \", \"$name\", \"$address\")";

  if (!($result = @ mysql_query ($insert, $connection)))

    showerror();

  if (!(mysql_close($connection)))

    showerror();

}

*/

?>

Umm, this is completely incorrect:

mysql_pconnect("$ mysql -u 112489 -h mysql.ict.school.edu.au -p 112489db")

mysql_pconnect requires three parameters hostname, username and password in that order. Not a command line.

 

This is what the above line should be:

mysql_pconnect("mysql.ict.school.edu.au", "112489", "112489db")

Archived

This topic is now archived and is closed to further replies.

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