Need help with register .php file?
-
<?php include 'config.php'; function is_alphachar($text) { for ($i = 0; $i < strlen($text); $i++) { if (!ereg("[A-Za-z0-9]", $text[$i])) { return 1; } } } $form .= "Register a new username. Be sure to enter a <b>genuine</b> email as it will be used to recover your account.<br>"; $form .= "<form action=\"./register.php\" method=\"POST\">"; $form .= "Username: <br><input type=\"text\" name=\"username\"><br>"; $form .= "Your email: <br><input type=\"text\" name=\"email\"><br>"; $form .= "Password: <br><input type=\"password\" name=\"password\"><br>"; $form .= "<input type=\"submit\" value=\"Create!\">"; $form .= "</form>"; if($_POST[username] == ""){ echo $form; } elseif(strlen($_POST[password]) < 6){ echo $form; echo "<br> Error password must be 6 characters or more"; } else { //Database Information $dbhost = "%%%%%%"; $dbname = "%%%%%%%%%"; $dbuser = "%%%%%%%%%%%"; $dbpass = "%%%%%%%%%%%"; //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql = "SELECT username FROM users WHERE username = '$_POST[username]'"; $sql2 = "SELECT email FROM users WHERE email = '$_POST[email]'"; $result = mysql_query($sql) or die ("Couldn't execute query."); $result2 = mysql_query($sql2) or die ("Couldn't execute query."); $num = mysql_num_rows($result); $num2 = mysql_num_rows($result2); if (is_alphachar($_POST[username]) == 1) { echo $form; echo "Invalid Username. Only numbers/letters and underscores are allowed.<br>"; die; } if ($num == 1) { echo "Error, username already exists!"; } elseif ($num2 == 1) { echo "Error, that email address has already been registered. Please select a different one."; } else { $query = "INSERT INTO users (username, password, email) VALUES ('$_POST[username]', '$_POST[password]', '$_POST[email]')"; $resultB = mysql_query($query, $connection) or die ("Coundn't execute query."); echo "Congratulations $tmpname. Your account has been created and added to database"; echo "<br><a href=\"login.php\">Back to login area</a>"; } } ?> that is the script , it works for a start , i enter my info and then when i clich on create it says Couldn't execute query. why is this and what is wrong . how do i fix it thankyou Jamie
-
Answer:
Hi Jamie, Why don't you echo $sql and $sql2 to see what query you're sending. Anyway it looks like you've left the quote out of your POST arrays: $_POST['username'], $_POST['email'] etc. So try: $sql = "SELECT username FROM users WHERE username = '" . $_POST['username'] . "'";
Jamie at Yahoo! Answers Visit the source
Other answers
Pls post the error msg so others can help you
Related Q & A:
- How to use external PHP file in СakePHP 2?Best solution by Stack Overflow
- I need help on what I need to buy or do.Best solution by Yahoo! Answers
- I need help with some horse questions, can you help me.Best solution by Yahoo! Answers
- I did something really bad and now i need help please help me.Best solution by Yahoo! Answers
- How to connect php file to ms access?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.