aery Posted July 18, 2012 Share Posted July 18, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265876-notice-undefined-variable-query-in-cxampphtdocssubmitphp-on-line-24-query/ Share on other sites More sharing options...
neller Posted July 18, 2012 Share Posted July 18, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265876-notice-undefined-variable-query-in-cxampphtdocssubmitphp-on-line-24-query/#findComment-1362381 Share on other sites More sharing options...
Maq Posted July 18, 2012 Share Posted July 18, 2012 aery, please use or tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/265876-notice-undefined-variable-query-in-cxampphtdocssubmitphp-on-line-24-query/#findComment-1362482 Share on other sites More sharing options...
aery Posted July 19, 2012 Author Share Posted July 19, 2012 thank a lot that helps.. Quote Link to comment https://forums.phpfreaks.com/topic/265876-notice-undefined-variable-query-in-cxampphtdocssubmitphp-on-line-24-query/#findComment-1362646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.