943,542 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 3212
  • PHP RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Mar 11th, 2008
0

Re: A little problem with a script

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.
Reputation Points: 10
Solved Threads: 1
Light Poster
LeBurt is offline Offline
38 posts
since Mar 2008
Mar 11th, 2008
0

Re: A little problem with a script

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
Reputation Points: 12
Solved Threads: 16
Posting Whiz
Designer_101 is offline Offline
314 posts
since Jul 2007
Mar 11th, 2008
0

Re: A little problem with a script

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
Last edited by Designer_101; Mar 11th, 2008 at 5:39 pm.
Reputation Points: 12
Solved Threads: 16
Posting Whiz
Designer_101 is offline Offline
314 posts
since Jul 2007
Mar 11th, 2008
0

Re: A little problem with a script

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tedobg is offline Offline
23 posts
since Jan 2008
Mar 11th, 2008
0

Re: A little problem with a script

oki
good luck
Reputation Points: 12
Solved Threads: 16
Posting Whiz
Designer_101 is offline Offline
314 posts
since Jul 2007
Mar 11th, 2008
0

Re: A little problem with a script

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tedobg is offline Offline
23 posts
since Jan 2008
Mar 11th, 2008
0

Re: A little problem with a script

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
Reputation Points: 12
Solved Threads: 16
Posting Whiz
Designer_101 is offline Offline
314 posts
since Jul 2007
Mar 11th, 2008
0

Re: A little problem with a script

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...
Last edited by LeBurt; Mar 11th, 2008 at 6:05 pm.
Reputation Points: 10
Solved Threads: 1
Light Poster
LeBurt is offline Offline
38 posts
since Mar 2008
Mar 11th, 2008
0

Re: A little problem with a script

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tedobg is offline Offline
23 posts
since Jan 2008
Mar 11th, 2008
0

Re: A little problem with a script

ok il pop on tomorow to see you.
Np
night night
Last edited by Designer_101; Mar 11th, 2008 at 6:17 pm.
Reputation Points: 12
Solved Threads: 16
Posting Whiz
Designer_101 is offline Offline
314 posts
since Jul 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP sort control
Next Thread in PHP Forum Timeline: Ajax Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC