A little problem with a script

Thread Solved

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

A little problem with a script

 
0
  #1
Mar 9th, 2008
Hi guys.I am new to web development and of course I have been experiensing some problems.Most of them are easy to solve and I usually find my way, but there is some thing that is getting on my nerves for some time now.

I have been trying to make a simple script for registering a user via MySQL.No filtering input, no validating only the part that adds the new user into the MySQL table. But it doesn't work.I have checked my code a couple of times and i can't see the problem.Here it is:
  1. <?php
  2. if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"]))
  3. {
  4. $name=$_POST["name"];
  5. $pass=$_POST["pass"];
  6. $email=$_POST["email"];
  7. $con=mysql_connect('localhost','root','password');
  8. if (!$con)
  9. {
  10. die('Could not connect: ' . mysql_error());
  11. }
  12. mysql_select_db("users", $con);
  13. mysql_query("INSERT INTO members (username,password,email) values ('$name','$pass','$email')") or die('Error');
  14. }
  15. ?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: A little problem with a script

 
0
  #2
Mar 9th, 2008
try this:

  1. <?php
  2. if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"]))
  3. {
  4. $name=$_POST["name"];
  5. $pass=$_POST["pass"];
  6. $email=$_POST["email"];
  7. $con=mysql_connect('localhost','root','password');
  8. if (!$con)
  9. {
  10. die('Could not connect: ' . mysql_error());
  11. }
  12. mysql_select_db("users", $con);
  13. $sql = "INSERT INTO `members` (username,password,email) VALUES ('" . $name . "','" . $pass . "','" . $email . "')";
  14. $query = mysql_query($sql,$con) or die('Error: ' . mysql_error());
  15. }
  16. ?>

if this script doesn't fix the problem, post the mysql error message and i will help you from there.
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
  #3
Mar 9th, 2008
Hey.Thanks for the quick reply there mate.I am sorry you didn't get the same from me but I was unable to reply sooner.Unfortunatelly the problem remains.The worst part is that a SQL error doesn't even appear.All I get after clicking on "submit" is my page reloading blank. . .
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: A little problem with a script

 
0
  #4
Mar 9th, 2008
post the rest of your code so i can see if there is a problem there.
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
  #5
Mar 9th, 2008
  1. <?php
  2. if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"]))
  3. {
  4. $name=$_POST["name"];
  5. $pass=$_POST["pass"];
  6. $email=$_POST["email"];
  7. $con=mysql_connect('localhost','root','password');
  8. if (!$con)
  9. {
  10. die('Could not connect: ' . mysql_error());
  11. }
  12. mysql_select_db("users", $con);
  13. $sql = "INSERT INTO `members` (username,password,email) VALUES ('" . $name . "','" . $pass . "','" . $email . "')";
  14. $query = mysql_query($sql,$con) or die('Error: ' . mysql_error());
  15. }
  16. ?>
  17.  
  18. <html>
  19. <body>
  20. <form action="register.php" method="post">
  21. Username: <input type="text" name="name" /></br>
  22. Password: <input type="password" name="pass" /></br>
  23. Email: <input type="text" name="email" width=40 /></br>
  24. <input type="submit" />
  25. </form>
  26. </body>
  27. </html>
OK.Here it is mate... My code with your corections.I would really appreciate if u find a solution.I have been trying for a few days now.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 561
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: A little problem with a script

 
0
  #6
Mar 9th, 2008
Is it inserting the data into the database.Of course,it will display blank because you have not triggered something to display if it is inserted correctly.try to replace this part:

  1. $query = mysql_query($sql,$con) or die('Error: ' . mysql_error());

with this:

  1. $query = mysql_query($sql);
  2. if (!$query)
  3. {
  4. echo 'Error: ' . mysql_error();
  5. }
  6. else
  7. {
  8. echo 'Inserted correctly.';
  9. }
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
  #7
Mar 10th, 2008
Hey ryan. I am sorry to say that it didn't work.I Inserted the statements you proposed, but still I get a blank.No error, no nothing.Oh Isn't the page supposed to display the form again if the insert is correct,because the page is reloading?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 561
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: A little problem with a script

 
0
  #8
Mar 10th, 2008
change this line:

  1. if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"]))

to this:

  1. if ($_POST['Submit'])

then add a name in your form button
  1. <input type="submit" name="Submit" />

See if that helps.

By the way,is this page the register.php page?
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
  #9
Mar 10th, 2008
Still no work mate. Again blank page.And to you question... yes this is named register.php
By the way I am signing off for now going to school. Again any help is appresiated.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,738
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: A little problem with a script

 
0
  #10
Mar 10th, 2008
Try this..
  1. <?php
  2. if(isset($_POST['submit'])){
  3. if(!empty($_POST["name"]) && !empty($_POST["pass"]) && !empty($_POST["email"]))
  4. {
  5. $name=$_POST["name"];
  6. $pass=$_POST["pass"];
  7. $email=$_POST["email"];
  8. $con=mysql_connect('localhost','root','password');
  9. if (!$con)
  10. {
  11. die('Could not connect: ' . mysql_error());
  12. }
  13. mysql_select_db("users");
  14. $sql = "INSERT INTO members (username,password,email) VALUES ('$name','$pass','$email')";
  15. $query = mysql_query($sql) or die('Error: ' . mysql_error());
  16. echo "Inserted successfully !";
  17. } else {
  18. echo "Fields can't be empty !";
  19. }
  20. }
  21. ?>
  22. <html>
  23. <body>
  24. <form action="register.php" method="post">
  25. Username: <input type="text" name="name" /></br>
  26. Password: <input type="password" name="pass" /></br>
  27. Email: <input type="text" name="email" width=40 /></br>
  28. <input type="submit" name="submit" value="submit" />
  29. </form>
  30. </body>
  31. </html>
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
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