| | |
A little problem with a script
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 38
Reputation:
Solved Threads: 1
I remember having connection problems when I started which I resolved by appending the mysql socket address to the host.
mysql_connect (host:socket, username, password)
I can't remember however if I got connection errors or not, but hey, it's worth the try. On my system:
$con = mysql_connect ('localhost:/var/mysql/mysql.sock', 'root', 'password');
Note that the location of the socket might be different on your system (I'm on OS X) but just locate the mysql.sock file and use the resulting path.
mysql_connect (host:socket, username, password)
I can't remember however if I got connection errors or not, but hey, it's worth the try. On my system:
$con = mysql_connect ('localhost:/var/mysql/mysql.sock', 'root', 'password');
Note that the location of the socket might be different on your system (I'm on OS X) but just locate the mysql.sock file and use the resulting path.
Hi
This works perfectly on my wampserver:
if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"]))
{
$name=$_POST["name"];
$pass=$_POST["pass"];
$email=$_POST["email"];
$con=mysql_connect('localhost','user1','11424028');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("rand", $con);
$sql = "INSERT INTO `members` (username,password,email) VALUES ('" . $name . "','" . $pass . "','" . $email . "')";
$query = mysql_query($sql,$con) or die('Error: ' . mysql_error());
}
?>
<html>
<body>
<form method="post">
Username: <input type="text" name="name" /></br>
Password: <input type="password" name="pass" /></br>
Email: <input type="text" name="email" width=40 /></br>
<input type="submit" />
</form>
</body>
</html>
The form action was redirecting the page before the mysql statement was sent,
So i simply just took it out
If this doesnt work, i would suggest going over your database and making sure the fields and table names are exactly right
anyway, hope the above works m8.
Reece
This works perfectly on my wampserver:
if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"]))
{
$name=$_POST["name"];
$pass=$_POST["pass"];
$email=$_POST["email"];
$con=mysql_connect('localhost','user1','11424028');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("rand", $con);
$sql = "INSERT INTO `members` (username,password,email) VALUES ('" . $name . "','" . $pass . "','" . $email . "')";
$query = mysql_query($sql,$con) or die('Error: ' . mysql_error());
}
?>
<html>
<body>
<form method="post">
Username: <input type="text" name="name" /></br>
Password: <input type="password" name="pass" /></br>
Email: <input type="text" name="email" width=40 /></br>
<input type="submit" />
</form>
</body>
</html>
The form action was redirecting the page before the mysql statement was sent,
So i simply just took it out

If this doesnt work, i would suggest going over your database and making sure the fields and table names are exactly right
anyway, hope the above works m8.
Reece
sorry ignore the red above its with my database details .... heres the version with yours .....
if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"]))
{
$name=$_POST["name"];
$pass=$_POST["pass"];
$email=$_POST["email"];
$con=mysql_connect('localhost','root','password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("users", $con);
$sql = "INSERT INTO `members` (username,password,email) VALUES ('" . $name . "','" . $pass . "','" . $email . "')";
$query = mysql_query($sql,$con) or die('Error: ' . mysql_error());
}
?>
<html>
<body>
<form method="post">
Username: <input type="text" name="name" /></br>
Password: <input type="password" name="pass" /></br>
Email: <input type="text" name="email" width=40 /></br>
<input type="submit" />
</form>
hope it helps
reece
if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"]))
{
$name=$_POST["name"];
$pass=$_POST["pass"];
$email=$_POST["email"];
$con=mysql_connect('localhost','root','password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("users", $con);
$sql = "INSERT INTO `members` (username,password,email) VALUES ('" . $name . "','" . $pass . "','" . $email . "')";
$query = mysql_query($sql,$con) or die('Error: ' . mysql_error());
}
?>
<html>
<body>
<form method="post">
Username: <input type="text" name="name" /></br>
Password: <input type="password" name="pass" /></br>
Email: <input type="text" name="email" width=40 /></br>
<input type="submit" />
</form>
hope it helps
reece
Last edited by Designer_101; Mar 11th, 2008 at 5:39 pm.
•
•
Join Date: Jan 2008
Posts: 23
Reputation:
Solved Threads: 0
The result when I put the connection line 1st in my script is a blank page. Not even the form is displayed. I though It might be my mistake mispelling something but unless I am turning blind everything looks well.LeBurt and Desiner_101 I will try your suggestions in a minute and see if something works..
By the way thanks for all the help guys
By the way thanks for all the help guys
•
•
Join Date: Jan 2008
Posts: 23
Reputation:
Solved Threads: 0
Designer_101 I tried what you said to see if it works.Well I dont know why but it doesn't. But when I read LeBurt's post I am striked by an idea. Is MySQL database supposed to be installed in the same directory as Apache Server or PHP. And if it is could that be causing the problem?And LeBurt If MySQL is in X:/Program Files/MySQL and my Apache is well X:/Program Files/Apache how do I select MySQL directory via localhost?
hi
I think now the problem isnt your code, perhaps like you said a direcory issue.
Theres a peice of free software called
Wampserver 2.0
i highly recomend it, it is
-apache
-php
-mySQL
-phpMyADMIN
all in one and is so much easier to use.
download it from here
http://www.wampserver.com/en/download.php
just
download
install
and start designing
hope this helps
I think now the problem isnt your code, perhaps like you said a direcory issue.
Theres a peice of free software called
Wampserver 2.0
i highly recomend it, it is
-apache
-php
-mySQL
-phpMyADMIN
all in one and is so much easier to use.
download it from here
http://www.wampserver.com/en/download.php
just
download
install
and start designing
hope this helps
•
•
Join Date: Mar 2008
Posts: 38
Reputation:
Solved Threads: 1
Actually, mysql is connect to PHP, not to Apache and no, they don't have to be in the same directory. The php.ini file on your system must have a line like this:
extension=mysql.so (or mysql.dll on windows)
(make you remove the semicolon to uncomment the line)
Otherwise, using the socket address should do it if there are still connection problems like on OS X...
extension=mysql.so (or mysql.dll on windows)
(make you remove the semicolon to uncomment the line)
Otherwise, using the socket address should do it if there are still connection problems like on OS X...
Last edited by LeBurt; Mar 11th, 2008 at 6:05 pm.
•
•
Join Date: Jan 2008
Posts: 23
Reputation:
Solved Threads: 0
So its a package instal and it instals everything without any hard to do properties and adjustments. Because once I tried to instal my admin and it was a nightmare. Anyway I will try it tomorrow.I am really tired today. Thanks a lot guys. After I try this tomorrow I will post to say if the problem remains.
Thanks again.
Thanks again.
![]() |
Similar Threads
- Learning PHP but problem with script (PHP)
- [Bash] problem with script in sed command (Shell Scripting)
- Minor problem with some script... (C)
- Large Array Problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP sort control
- Next Thread: Ajax Problem
Views: 2696 | Replies: 35
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date directory display download dynamic echo email error file files folder form format forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





