Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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 August 6th, 2004, 07:48 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chp 11: Database entry problem

Hi all

On the register.php page - when I enter a new username and password I receive this message:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

The code follows below. Please note that i have changed some things slightly from the book (i.e. leaving some un-required fileds) to make it more like the final application I want to implement.

Any help appciated. TIA

<?php
session_start();
include "logged_config.php";
?>
<html>
<head>
    <title>This is a test!</title>
</head>
<body>

<?php
//if the button is pressed
 if ($_POST['submit'] == "Register")
 {
    //check to see that the fields aren't empty
    if ($_POST['username'] != "" && $_POST['password'] != "")
    {
        //create function to see if user already exists
        $check_user = $_POST['username'];

$query = "SELECT username FROM user_info WHERE username ='$check_user';";
    $result = mysql_query($query) or die(mysql_error());

        if (mysql_num_rows($result) !=0)
        {
  //present form to user and warn if username is in use
  ?>

<b>The Username, <?php echo $_POST['username']?>, is already in use, please choose another!</b>
    <form action="register.php" method="post">
    Username: <input type="text" name="username"><br>
    Password: <input type="password" name="password" value="<?php echo $_POST['password']?>"><br>
    <input type="submit" name="submit" value="Register"> &nbsp; <input type="reset" value="Clear">
    </form>
<?php

//place data into database
    }
    else
    {
    $query = "INSERT INTO user_info(username, password) VALUES ('" . $_POST['username'] . "', (password(' ". $_POST['password'] . "'));";
        $result = mysql_query($query) or die(mysql_error());
        $_SESSION['user_logged'] = $_POST['username'];
        $_SESSION['user_password'] = $_POST['password'];
?>
    Thank you, <?php echo $_POST['username'];?> for registering!<br>
        <a href="logged_in.php">Click Here</a> to continue.
<?php

//if fields are empty warn user and display form again
        }
    }
    else
    {
?>

<b>The Username and Password fields are required!</b>
        <form action="register.php" method="post">
        Username: <input type="text" name="username" value"<?php echo $_POST['username']?>"><br>
    Password: <input type="password" name="password" value="<?php echo $_POST['password']?>"><br>
    <input type="submit" name="submit" value="Register"> &nbsp; <input type="reset" value="Clear">
    </form>

<?php
    }
}
else
{
?>

Welcome to the registration page!<br>
The Username and Password fields are required!
<form action="register.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Register"> &nbsp; <input type="reset" value="Clear">
</form>
<?php
}
?>

</body>
</html>

 
Old August 9th, 2004, 03:38 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I implemented the changes Firedrill suggested but I still receive the same error message.

 
Old August 10th, 2004, 11:11 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fixed it. Just in case anyone looks at this in future and has a similar problem here is the code:

    $query = "INSERT INTO user_info (username, password) VALUES ('" . $_POST['username'] . "', (password(' ". $_POST['password'] . "')));";
        $result = mysql_query($query) or die(mysql_error());
        $_SESSION['user_logged'] = $_POST['username'];
        $_SESSION['user_password'] = $_POST['password'];
?>

Needed an extra ) after $_POST['password'] on the insert line. Seems to have done the trick!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 11 - Problem Opening Database dbcook8 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 15 February 2nd, 2009 08:41 AM
Chp.11 CodeCompileUnit.ReferencedAssemblies studen77 BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 2 February 20th, 2007 06:24 PM
Database Entry Problems gmoney060 Classic ASP Databases 4 November 9th, 2004 08:19 AM
Chp 11 - Creating htaccess JamesA BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 6 June 15th, 2004 08:01 AM
Database Double Entry isg2000 Access ASP 1 June 13th, 2003 04:30 AM





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