Jump to content

Notice: Undefined variable: query in C:\xampp\htdocs\submit.php on line 24 Query


Recommended Posts

HI guy i'm having a problem with my registration form

can anyone help m out please

 

my php code for submit.php

 

 

<?php
session_start();

include 'db.inc.php';

$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or 
    die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));

// filter incoming values
$email = (isset($_POST['email'])) ? trim($_POST['email']) : '';
$username = (isset($_POST['username'])) ? trim($_POST['username']) : '';
$password = (isset($_POST['password'])) ? $_POST['password'] : '';

if (isset($_POST['submit']) && $_POST['submit'] == 'Register')

        $query = 'INSERT INTO nelyn_user 
                (user_id, username, password, email)
           VALUES 
               (NULL, "' . mysql_real_escape_string($email, $db) . '", ' . 
                     '"' . mysql_real_escape_string($username, $db)  . '", ' .
		'PASSWORD("' . mysql_real_escape_string($password, $db) . '"))';

$result = mysql_query($query, $db) or die(mysql_error());
$user_id = mysql_insert_id($db);


        $_SESSION['logged'] = 1;
        $_SESSION['email'] = $email;

        header('Refresh: 5; URL=login.php');		


?>

and my html code is as

<html>
<body>
<form method="post" action="submit.php" />
<b>Email</b><br />
<input type="text" name="email" id="email" /><br />

<b>UserName</b><br />
<input type="text" name="username" id="username" /><br />
<b>Password</b><br />
<input type="password" name="password" id="password" /><br /><br />
<input type="submit" value=" Register " name="submit" id="submit"/>
</form>
</body>
</html>

 

 

 

 

i'm getting a

Notice: Undefined variable: query in C:\xampp\htdocs\submit.php on line 24

Query was empty

 

(this is the line 24 ; $result = mysql_query($query, $db) or die(mysql_error())

 

when i submit the form

 

i'm using java/js for validation

thank

Making the following 2 changes will fix it..

 

1 - change the text on your submit button, currently you have spaces  " Register " , but in your PHP you are not checking for spaces you just have

 

if (isset($_POST['submit']) && $_POST['submit'] == 'Register')

So change your submit button to...

 

<input type="submit" value="Register" name="submit" id="submit"/>

 

then I always find wrapping my if statements in brackets is far better as it none of it will get run unless it passes your checks u are doing, so for example use this..

 

if (isset($_POST['submit']) && $_POST['submit'] == 'Register') {

        $query = 'INSERT INTO nelyn_user
                (user_id, username, password, email)
           VALUES
               (NULL, "' . mysql_real_escape_string($email, $db) . '", ' .
                     '"' . mysql_real_escape_string($username, $db)  . '", ' .
         'PASSWORD("' . mysql_real_escape_string($password, $db) . '"))';

   $result = mysql_query($query, $db) or die(mysql_error());
   $user_id = mysql_insert_id($db);


        $_SESSION['logged'] = 1;
        $_SESSION['email'] = $email;

        header('Refresh: 5; URL=login.php');      
}

 

Hope that helps and all make ssense

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.