gotenxds Posted August 27, 2011 Share Posted August 27, 2011 i have a problom with this code i made for a register, i keep on geting the error "no username or password enterd" no matter what here is the page (most of it is the form so its not that long ) <?php require_once('db_login.php'); $connection = mysql_connect($db_host, $db_username, $db_password, $db_database) or die("error connecting to db". mysql_error()); $error = ""; if(isset($_POST['submit'])){ //grabing info $UserName = mysqli_real_escape_string($connection, trim($_POST['username'])); $password = mysqli_real_escape_string($connection, trim($_POST['password'])); $password2 = mysqli_real_escape_string($connection, trim($_POST['password2'])); $Email = mysqli_real_escape_string($connection, trim($_POST['Email'])); $Gender = mysqli_real_escape_string($connection, trim($_POST['Gender'])); $Msn = mysqli_real_escape_string($connection, trim($_POST['Msn'])); $Skype = mysqli_real_escape_string($connection, trim($_POST['Skype'])); $Year = mysqli_real_escape_string($connection, trim($_POST['Year'])); $Month = mysqli_real_escape_string($connection, trim($_POST['Month'])); $Day = mysqli_real_escape_string($connection, trim($_POST['Day'])); if(!empty($UserName) && !empty($password) && !empty($password2) && ($password == $password2) ){ $query = "SELECT * FROM users WHERE UserName = '$UserName'" ; $data = mysqli_query($connection, $query); if(mysqli_num_rows($data) == 0){ $query_to_users = "INSERT INTO users VALUES (null,'$UserName','$password',now())"; $query_to_usersDetails = "INSERT INTO user_details VALUES (null,'$B_day','$Email','$Gender','$Msn','$Skype')"; $result = mysql_query( $query_to_users ); if (!$result){ die("could not query database <br />". mysql_error()); } $result2 = mysql_query($query_to_usersDetails); if (!$result2){ die("could not query database <br />". mysql_error()); } echo " ok ok ok ok "; mysqli_close($connection); exit(); } else{ $error = "username is allredy taken";} } else {$error = "no username or password enterd";} } mysqli_close($connection); ?> השדות המסומנים ב '<span style="color:red;">*</span>' הינם חובה. <br /><br /> <div id="detailes"> <?php echo $error ;?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <label> שם משתמשם: <span style="color:red;">*</span> <input type="text" name="username" value="<?php $UserName ?>"/> </label> <br /> <label> סיסמה: <span style="color:red;">*</span> <input type="password" name="password" style="margin-right:45px;" /> </label> <br /> <label> ווידוי סיסמה: <span style="color:red;">*</span> <input type="password" name="password2" style="margin-right:13px;" /> </label> <br /> <label> מין: <input type="radio" name="Gender" value="male" style="margin-right:80px;" />זכר </label> <label> <input type="radio" name="Gender" value="female" style="margin-right:10px;" /> נקבה </label> <br /> <label> אימייל: <input type="Email" name="Email" value="<?php $Email ?>" style="margin-right:58px;" /> </label> <br /> תאריך לידה: <br /> <label>יום: <select name="Day" style="margin-right:80px;"> <option value='01'>01</option> <option value='02'>02</option> <option value='03'>03</option> <option value='04'>04</option> <option value='05'>05</option> <option value='06'>06</option> <option value='07'>07</option> <option value='08'>08</option> <option value='09'>09</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> <option value='13'>13</option> <option value='14'>14</option> <option value='15'>15</option> <option value='16'>16</option> <option value='17'>17</option> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> <option value='25'>25</option> <option value='26'>26</option> <option value='27'>27</option> <option value='28'>28</option> <option value='29'>29</option> <option value='30'>30</option> <option value='31'>31</option> </select> </label> <br /> <label>חודש: <select name="Month" value='' style="margin-right:64px;"> <option value='01'>ינואר</option> <option value='02'>פבואר</option> <option value='03'>מרץ</option> <option value='04'>אפריל</option> <option value='05'>מאי</option> <option value='06'>יוני</option> <option value='07'>יולי</option> <option value='08'>אוגוסט</option> <option value='09'>ספטמבר</option> <option value='10'>אוקטובר</option> <option value='11'>נובמבר</option> <option value='12'>דצמבר</option> </select> </label> <br /> <label>שנה: <select name="Year" style="margin-right:72px;"> <option value='2011'>2011</option> <option value='2010'>2010</option> <option value='2009'>2009</option> <option value='2008'>2008</option> <option value='2007'>2007</option> <option value='2006'>2006</option> <option value='2005'>2005</option> <option value='2004'>2004</option> <option value='2003'>2003</option> <option value='2002'>2002</option> <option value='2001'>2001</option> <option value='2000'>2000</option> <option value='1999'>1999</option> <option value='1998'>1998</option> <option value='1997'>1997</option> <option value='1996'>1996</option> <option value='1995'>1995</option> <option value='1994'>1994</option> <option value='1993'>1993</option> <option value='1992'>1992</option> <option value='1991'>1991</option> <option value='1990'>1990</option> <option value='1989'>1989</option> <option value='1988'>1988</option> <option value='1987'>1987</option> <option value='1986'>1986</option> <option value='1985'>1985</option> <option value='1984'>1984</option> <option value='1983'>1983</option> <option value='1982'>1982</option> <option value='1981'>1981</option> <option value='1980'>1980</option> <option value='1979'>1979</option> <option value='1978'>1978</option> <option value='1977'>1977</option> <option value='1976'>1976</option> <option value='1975'>1975</option> <option value='1974'>1974</option> <option value='1973'>1973</option> <option value='1972'>1972</option> <option value='1971'>1971</option> <option value='1970'>1970</option> <option value='1969'>1969</option> <option value='1968'>1968</option> <option value='1967'>1967</option> <option value='1966'>1966</option> <option value='1965'>1965</option> </select> </label> <br /> <label> סקייפ: <input type="text" name="Skype" value="<?php $Skype ?>" style="margin-right:62px;" /> </label> <br /> <label> מסנג'ר: <input type="text" name="Msn" value="<?php $Msn ?>" style="margin-right:53px;" /> </label> <br /> <label> <input type="submit" value="הרשם" name="submit" /> </label> </form> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/245802-could-someone-take-a-look-at-this-code/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 27, 2011 Share Posted August 27, 2011 You are mixing mysql and mysqli functions on one connection. That does not work. You must stick to all mysql or all mysqli functions. If you had error_reporting set to E_ALL and display_errors set to ON, you would be getting php errors that would have helped you find problems with mixing the two different type of database functions. Quote Link to comment https://forums.phpfreaks.com/topic/245802-could-someone-take-a-look-at-this-code/#findComment-1262545 Share on other sites More sharing options...
gotenxds Posted August 27, 2011 Author Share Posted August 27, 2011 ho thx alot, i did not know about that, and thx for the tip as well, but i fixed at as you said and set them all to mysqli, but for some reason i now get a "could not query database" error, i chacked and the db login data is correct. here is the "fixed" page thx alot for all the trouble your going trouge to help useless me XD <?php /* $UserName = $_POST['username']; $password = $_POST['password']; $password2 = $_POST['password2']; $Email = $_POST['Email']; $Gender = $_POST['Gender']; $Msn = $_POST['Msn']; $Skype = $_POST['Skype']; $Year = $_POST['Year']; $Month = $_POST['Month']; $Day = $_POST['Day']; $UserName = ""; $password = ""; $password2 =""; $Email = ""; $Gender = ""; $Msn = ""; $Skype = ""; $Year = ""; $Month = ""; $Day = ""; */ require_once('db_login.php'); $connection = mysqli_connect($db_host, $db_username, $db_password, $db_database) or die("error connecting to db". mysqli_error()); $error = ""; if(isset($_POST['submit'])){ //grabing info $UserName = mysqli_real_escape_string($connection, trim($_POST['username'])); $password = mysqli_real_escape_string($connection, trim($_POST['password'])); $password2 = mysqli_real_escape_string($connection, trim($_POST['password2'])); $Email = mysqli_real_escape_string($connection, trim($_POST['Email'])); $Gender = mysqli_real_escape_string($connection, trim($_POST['Gender'])); $Msn = mysqli_real_escape_string($connection, trim($_POST['Msn'])); $Skype = mysqli_real_escape_string($connection, trim($_POST['Skype'])); $Year = mysqli_real_escape_string($connection, trim($_POST['Year'])); $Month = mysqli_real_escape_string($connection, trim($_POST['Month'])); $Day = mysqli_real_escape_string($connection, trim($_POST['Day'])); if(!empty($UserName) && !empty($password) && !empty($password2) && ($password == $password2) ){ $query = "SELECT * FROM users WHERE UserName = '$UserName'" ; $data = mysqli_query($connection, $query); if(mysqli_num_rows($data) == 0){ $query_to_users = "INSERT INTO users VALUES (null,'$UserName','$password',now())"; $query_to_usersDetails = "INSERT INTO user_details VALUES (null,'$B_day','$Email','$Gender','$Msn','$Skype')"; $result = mysqli_query($connection, $query_to_users ); if (!$result){ die("could not query database <br />". mysqli_error()); } $result2 = mysqli_query($connection, $query_to_usersDetails); if (!$result2){ die("could not query database <br />". mysqli_error()); } echo " ok ok ok ok "; mysqli_close($connection); exit(); } else{ $error = "username is allredy taken";} } else {$error = "no username or password enterd";} } mysqli_close($connection); ?> השדות המסומנים ב '<span style="color:red;">*</span>' הינם חובה. <br /><br /> <div id="detailes"> <?php echo $error ;?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <label> שם משתמשם: <span style="color:red;">*</span> <input type="text" name="username" value="<?php $UserName ?>"/> </label> <br /> <label> סיסמה: <span style="color:red;">*</span> <input type="password" name="password" style="margin-right:45px;" /> </label> <br /> <label> ווידוי סיסמה: <span style="color:red;">*</span> <input type="password" name="password2" style="margin-right:13px;" /> </label> <br /> <label> מין: <input type="radio" name="Gender" value="male" style="margin-right:80px;" />זכר </label> <label> <input type="radio" name="Gender" value="female" style="margin-right:10px;" /> נקבה </label> <br /> <label> אימייל: <input type="Email" name="Email" value="<?php $Email ?>" style="margin-right:58px;" /> </label> <br /> תאריך לידה: <br /> <label>יום: <select name="Day" style="margin-right:80px;"> <option value='01'>01</option> <option value='02'>02</option> <option value='03'>03</option> <option value='04'>04</option> <option value='05'>05</option> <option value='06'>06</option> <option value='07'>07</option> <option value='08'>08</option> <option value='09'>09</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> <option value='13'>13</option> <option value='14'>14</option> <option value='15'>15</option> <option value='16'>16</option> <option value='17'>17</option> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> <option value='25'>25</option> <option value='26'>26</option> <option value='27'>27</option> <option value='28'>28</option> <option value='29'>29</option> <option value='30'>30</option> <option value='31'>31</option> </select> </label> <br /> <label>חודש: <select name="Month" value='' style="margin-right:64px;"> <option value='01'>ינואר</option> <option value='02'>פבואר</option> <option value='03'>מרץ</option> <option value='04'>אפריל</option> <option value='05'>מאי</option> <option value='06'>יוני</option> <option value='07'>יולי</option> <option value='08'>אוגוסט</option> <option value='09'>ספטמבר</option> <option value='10'>אוקטובר</option> <option value='11'>נובמבר</option> <option value='12'>דצמבר</option> </select> </label> <br /> <label>שנה: <select name="Year" style="margin-right:72px;"> <option value='2011'>2011</option> <option value='2010'>2010</option> <option value='2009'>2009</option> <option value='2008'>2008</option> <option value='2007'>2007</option> <option value='2006'>2006</option> <option value='2005'>2005</option> <option value='2004'>2004</option> <option value='2003'>2003</option> <option value='2002'>2002</option> <option value='2001'>2001</option> <option value='2000'>2000</option> <option value='1999'>1999</option> <option value='1998'>1998</option> <option value='1997'>1997</option> <option value='1996'>1996</option> <option value='1995'>1995</option> <option value='1994'>1994</option> <option value='1993'>1993</option> <option value='1992'>1992</option> <option value='1991'>1991</option> <option value='1990'>1990</option> <option value='1989'>1989</option> <option value='1988'>1988</option> <option value='1987'>1987</option> <option value='1986'>1986</option> <option value='1985'>1985</option> <option value='1984'>1984</option> <option value='1983'>1983</option> <option value='1982'>1982</option> <option value='1981'>1981</option> <option value='1980'>1980</option> <option value='1979'>1979</option> <option value='1978'>1978</option> <option value='1977'>1977</option> <option value='1976'>1976</option> <option value='1975'>1975</option> <option value='1974'>1974</option> <option value='1973'>1973</option> <option value='1972'>1972</option> <option value='1971'>1971</option> <option value='1970'>1970</option> <option value='1969'>1969</option> <option value='1968'>1968</option> <option value='1967'>1967</option> <option value='1966'>1966</option> <option value='1965'>1965</option> </select> </label> <br /> <label> סקייפ: <input type="text" name="Skype" value="<?php $Skype ?>" style="margin-right:62px;" /> </label> <br /> <label> מסנג'ר: <input type="text" name="Msn" value="<?php $Msn ?>" style="margin-right:53px;" /> </label> <br /> <label> <input type="submit" value="הרשם" name="submit" /> </label> </form> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/245802-could-someone-take-a-look-at-this-code/#findComment-1262546 Share on other sites More sharing options...
PFMaBiSmAd Posted August 27, 2011 Share Posted August 27, 2011 mysqli_error requires the database connection link as a parameter. Again, if you had error_reporting/display_errors set as suggested, you would have been getting php errors that would have alerted you to the problem with the mysqli_error statement. Without the connection link as a parameter to the mysqli_error statement, it does not return the reason why the query failed. Quote Link to comment https://forums.phpfreaks.com/topic/245802-could-someone-take-a-look-at-this-code/#findComment-1262548 Share on other sites More sharing options...
gotenxds Posted August 27, 2011 Author Share Posted August 27, 2011 ok alllot agin for all your help, im seting it on now, and ya it did give me an error msg that helpd my solve it once and for all, agin thx alot. Quote Link to comment https://forums.phpfreaks.com/topic/245802-could-someone-take-a-look-at-this-code/#findComment-1262551 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.