A little problem with a script

Thread Solved

Join Date: Mar 2008
Posts: 38
Reputation: LeBurt is an unknown quantity at this point 
Solved Threads: 1
LeBurt LeBurt is offline Offline
Light Poster

Re: A little problem with a script

 
0
  #21
Mar 11th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 258
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: A little problem with a script

 
0
  #22
Mar 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 258
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: A little problem with a script

 
0
  #23
Mar 11th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 23
Reputation: tedobg is an unknown quantity at this point 
Solved Threads: 0
tedobg tedobg is offline Offline
Newbie Poster

Re: A little problem with a script

 
0
  #24
Mar 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 258
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: A little problem with a script

 
0
  #25
Mar 11th, 2008
oki
good luck
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 23
Reputation: tedobg is an unknown quantity at this point 
Solved Threads: 0
tedobg tedobg is offline Offline
Newbie Poster

Re: A little problem with a script

 
0
  #26
Mar 11th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 258
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: A little problem with a script

 
0
  #27
Mar 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 38
Reputation: LeBurt is an unknown quantity at this point 
Solved Threads: 1
LeBurt LeBurt is offline Offline
Light Poster

Re: A little problem with a script

 
0
  #28
Mar 11th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 23
Reputation: tedobg is an unknown quantity at this point 
Solved Threads: 0
tedobg tedobg is offline Offline
Newbie Poster

Re: A little problem with a script

 
0
  #29
Mar 11th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 258
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: A little problem with a script

 
0
  #30
Mar 11th, 2008
ok il pop on tomorow to see you.
Np
night night
Last edited by Designer_101; Mar 11th, 2008 at 6:17 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC