Jump to content

Archived

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

ilikephp

[SOLVED] mysql_query()

Recommended Posts

hello,

 

i am using a form that contains radio buttons.

when I enter the fields and submit I receive this message:

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'xxx'@'localhost' (using password: NO) in /home/xxx/public_html/form.php on line 45

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/xxx/public_html/form.php on line 45

Access denied for user 'xxx'@'localhost' (using password: NO)

 

 

the line 45 contains:

 

mysql_query("update `members` SET first_name='$fname', last_name='$lname',  age='$age' ") or die(mysql_error());

 

 

what should I do please coz I am sure that password is correct;

or maybe the code in sql is wrong?

 

 

 

the code in sql is:

 

 

 

CREATE TABLE members (

  id int(4) NOT NULL auto_increment,

  first_name varchar(100) NOT NULL default '',

  last_name varchar(100) NOT NULL default '',

  age bigint(10) NOT NULL default '0',

 

  PRIMARY KEY  (id)

) TYPE=MyISAM;

 

 

can u help plzzz!!!! thanks

Share this post


Link to post
Share on other sites

The error means that when the mysql_query() statement executed, there was no valid connection to the mysql server and a connection using all default values was attempted, which of course failed.

 

To get help with why your mysql_connect() statement is not working, you would need to post your code.

 

Also, is there a reason why you posted this in the Microsoft SQL - MMSQL section since it is a mysql question?

Share this post


Link to post
Share on other sites

hello, I posted here because I saw: SQL related to php:

I will post all my scripts because I still have the same errors:

 

connect.php:

 

<?php

$host="localhost"; // Host name

$username="***"; // Mysql username

$password="****"; // Mysql password

$db_name="*****"; // Database name

$tbl_name="members"; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect server ");

mysql_select_db("$db_name")or die("cannot select DB");

 

$datetime=date("y-m-d h:i:s"); //date time

 

$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";

$result=mysql_query($sql);

 

//mysql_close();

?>

 

 

* I think that there is an error in the last 5 lines

 

 

inside the phpMyAdmin:

 

CREATE TABLE members (

  id int(4) NOT NULL auto_increment,

  first_name varchar(100) NOT NULL default '',

  last_name varchar(100) NOT NULL default '',

  age bigint(10) NOT NULL default '0',

 

  PRIMARY KEY  (id)

) TYPE=MyISAM;

 

 

 

form.php:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<?php

 

    include("connect.php");

 

   

    echo " <form action=?action=form method=\"post\"> Please selcet your age :  <br />

<input type=\"radio\" name=\"age\" value=10 checked>10 years  || <input type=\"radio\" name=\"age\" value=11>11 years <br />

 

<input type=\"radio\" name=\"age\" value=12>12 years  || <input type=\"radio\" name=\"age\" value=13>13 years <br />

 

<input type=\"radio\" name=\"age\" value=14>14 years  || <input type=\"radio\" name=\"age\" value=15>15 years <br /> <br />

 

Now please enter your First name : <br />

<input type=\"text\" name=\"fname\" value=\"First Name\"> <br /><br />

 

Now please enter your Last name : <br />

<input type=\"text\" name=\"lname\" value=\"Last Name\"> <br /> <br />

 

<input type=\"submit\" value=\"submit\"> || <input type=\"reset\" value=\"reset fields\"> <br /><br />";

 

 

if($_GET['action'] == 'form')

 

{

 

if($_POST['age'] == "" | $_POST['fname'] == "" | $_POST['lname'] == "" ) { echo " Please fill all forms in "; }

 

else

{

 

$age = $_POST['age'];

$fname = $_POST['fname'];

$lname = $_POST['lname'];

 

 

echo "Hello ".$fname." ".$lname."  Your age is ".$age." Record enterd in the database as well.";

mysql_query("update `members` set first_name='$fname', last_name='$lname',  age='$age' ") or die(mysql_error());

 

}

}

?>

 

</body>

</html>

 

Share this post


Link to post
Share on other sites

can someone try this code plz and report to me why it is not uplading to the database?  ??? ???

Share this post


Link to post
Share on other sites

The include statement - include("connect.php"); is probably failing due to a wrong path or the mysql_close(); statement inside connect.php is not commented out in the actual code and is closing the database connection.

 

Also, the code in connect.php that is setting up a query and executing it appears to be left over from some other script and would be inserting rows with empty values into your database.

 

Check your web server log for errors or turn on full php error reporting to find out if the include() statement is working or not.

 

Share this post


Link to post
Share on other sites

please, how can I check my web server log for errors or turn on full php error reporting ?

thanks

Share this post


Link to post
Share on other sites

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