Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2006, 07:55 PM
Authorized User
 
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default error with SELECT

What is wrong with this code?
Code:
      <?php
          $con = mysql_connect("mysql157.secureserver.net","132591","lotrt2t");

        mysql_select_db("132591",$con);

        $sql = "CREATE TABLE users(
                    user varchar(12),
                    password varchar(12)
                )";
        mysql_query($sql, $con);

        $sql = "SELECT * FROM users WHERE user = '$_POST[username]'";
        $result = mysql_query($sql, $con);
                    echo "query:  \"$sql\"<br>";
                    echo ( $result ) ? "<br>found one!<br>" : "<br> didn't find one! <br>" ;

        echo "confirm:  \"" . $_POST['confirm'] . "\"";
        echo "password: \"" . $_POST['password'] . "\"";


        if( $_POST['confirm'] == $_POST['password']){
            if(!$result){
                $sql = "INSERT INTO users (user, password) VALUES('$_POST[username]','$_POST[password]')";
                echo "query:  \"$sql\"";

                mysql_query($sql, $con);
            }
            else{
                echo "Username already exists. Sorry!";
            }
        }
        else{
            echo "You are not logged on.";
        }
      ?>
__________________
\"Judge a man by his questions, not by his answers.\"
-Voltaire
 
Old November 22nd, 2006, 08:20 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

What error are you getting?

--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com
 
Old November 22nd, 2006, 11:02 AM
Authorized User
 
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This program is supposed to see if the user already exists, and if it doesn't, insert it into a database. But it always says the usery exists, even if it doesn't.

"Judge a man by his questions, not by his answers."
-Voltaire
 
Old November 22nd, 2006, 11:52 PM
Authorized User
 
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind I have the issue solved. Thanks everybody!

"Judge a man by his questions, not by his answers."
-Voltaire





Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 145: ORDER BY ITEMS... SELECT DISTINCT... tbaquero SQL Server 2000 7 May 8th, 2008 02:30 AM
odd error with apply-templates select="..." name Fitty XSLT 1 January 18th, 2008 03:45 AM
get error when SELECT search starts with "@" abbylee26 Classic ASP Databases 1 March 15th, 2004 03:37 PM
SELECT STATEMENT error sinner Classic ASP Databases 5 February 28th, 2004 04:05 PM
select string and error syntax fdmfdm Access VBA 3 November 26th, 2003 09:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.