jazzman1
Staff Alumni-
Posts
2,713 -
Joined
-
Last visited
-
Days Won
12
Everything posted by jazzman1
-
Run the following sql statement via your GUI db tool, mysql workbench, phpmyadmin or whatever you use and bring me the result back. SHOW FULL COLUMNS FROM db_name.users; I don't know your database name. Most important - you should have to use the same database credentials and charset encoding when inserting the data to mysql. Maybe you're using different one???
-
See the link - http://php.net/manual/en/mysqli.set-charset.php Example: <?php $con = mysqli_connect('localhost', 'my_user', 'my_password', 'test'); mysqli_set_charset($con, "utf8"); What's ascii characters - http://www.asciitable.com/ After that, delete all old records, create a new one and try to retrieve the correct hashed/salted password.
-
Ok, add on line 44 var_dump() to your loginUser function. function loginUser($con, $name, $pass) { $query = sprintf("SELECT password, salt_password FROM users WHERE username ='%s'", mysqli_real_escape_string($name)); $result = mysqli_query($con, $query); if(!$result) { echo "Error Result: ".mysqli_error($con); } $row = mysqli_fetch_assoc($result); var_dump($row); // here add this if($row['password'] == md5($pass.$row['salt_password'])) { echo "passwords match"; // do } else { echo "passwords failed"; } } Is there a column named username in your users table? Use my query! $query = sprintf("SELECT password, salt_password FROM users WHERE username ='%s'", mysqli_real_escape_string($name));
-
it's a beautiful day today in Toronto So, do you know how the programming functions work? Try, this and tell me what result you get: <?php session_start(); //this will start the session for the user error_reporting(E_ALL); ini_set('display_errors', '1'); require( 'database.php' ); if ( isset( $_POST['login']) ) { loginUser($con,$_POST['username'],$_POST['password']); } else { include('includes/overall/header.php'); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <ul> <li>Username:<br> <input type="text" name="username"> </li> <li>Password:<br> <input type="password" name="password"> </li> <li><input type="submit" name="login" value="Login"> </form> <?php include('includes/overall/footer.php'); } function loginUser($con, $name, $pass) { $query = sprintf("SELECT password, salt_password FROM users WHERE username ='%s'", mysqli_real_escape_string($name)); $result = mysqli_query($con, $query); if(!$result) { echo "Error Result: ".mysqli_error($con); } $row = mysqli_fetch_assoc($result); if($row['password'] == md5($pass.$row['salt_password'])) { echo "passwords match"; // do } else { echo "passwords failed"; } } /* if($row['password'] == md5($_POST['password'].$row['salt_password'])) { if ($row) { //echo "Reached Matching Row<br/>"; $_SESSION['loggedin'] = 1; $_SESSION['loggedinuser'] = $row['username']; if($row['level'] == '1'){ //level 1 user (Normal User) //echo "Reached level 1 check<br/>"; $_SESSION['adminuser'] = 0; //not an admin set value to false/0 header ('location: main.php'); } elseif ($row['level'] == '9'){ //level 9 user (Admin User) //echo "Reached level 9 check<br/>"; $_SESSION['adminuser'] = 1; //yes is an admin set value to true/1 header ('location: main.php'); } } mysqli_free_result($result); } // decide what to do if the login is unsuccessful else{ include('includes/overall/header.php'); echo "There was a problem with your login. It Could be the Wrong Username or Password"; include('includes/overall/footer.php'); } // end function /* close connection * * */ mysqli_close($con); ?>
-
Try, while ($row = mysqli_fetch_array($result,MYSQLI_NUM)) { echo "<option value=$row[0]>".$row[0]."</option>"; }
-
Do a view source to your browser: $row[0] = 'head'; echo "<select>"; echo '("<option value="'; echo ($row[0]),'</br>'; echo '</br>">'; echo ($row[0]),'</br>'; echo '</option>")'; echo "</select>"; Result of value is: "head</br></br>"
-
No, there is no another reason! There is no table name (head) in database, named ( Databasename ) Are you using some GUI visual tool for database administration like mysql workbech, phpmyadmin, etc... ? PS: Do var_dump before to send the query: $table = $_POST["selform"]; $sql = 'SELECT * FROM '.$table ; var_dumt($sql); $result = mysqli_query($con,$sql); if(!$result) echo("Error result: " . mysqli_error($con)); exit;
-
make sure your database credentials point to correct database. the error message is self-explanatory.
-
what's your database name?
-
Try, $sql = "SELECT * FROM `$table`";
-
Have you tried mysqli_error() function? Try, $sql = 'SELECT * FROM '.$table ; $result = mysqli_query($con,$sql); if(!$result) echo("Error result: " . mysqli_error($con)); exit; // continue...
-
you need to use only 1 query, then use php to build your query with or not where condition depends on the logic you want to apply.
-
How about a frameset attribute.
- 1 reply
-
- php
- javascript
-
(and 2 more)
Tagged with:
-
Here's my testing: 1. Using .ready method at top of the document - works ! Note, that .add class is added to #presidentinfo before entire html to be loaded. <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>JSON Presidents</title> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#PresidentInfo').addClass("odd"); }); </script> <style type="text/css"> body{ font-family:arial, helvetica, sans-serif; text-align:center; width:100%; margin:200px 0 0 0; } #PresidentInfo{ width:75%; margin:0 auto; } table#data{ width:100%; } table#data th{ background:#333; color:#fff; text-align:center; text-shadow:1px 1px 1px rgba(0,0,0,1); padding:5px; } table#data td{ border:1px solid #333; border-collapse:collapse; padding:10px; margin:0 5px 0 5px; text-align:center; } .odd tr:nth-child(odd) { background-color: #ccc; } </style> </head> <body> <div id="PresidentInfo"></div> <script type="text/javascript"> jQuery.getJSON('data.json', function(data) { var output = "<table id='data'><tr><th>First Name:</th><th>Last Name:</th><th>Month of Inauguration:</th><th>Year of Inauguration:</th></tr>"; for (var i in data.Presidents) { output += "<tr><td>" + data.Presidents[i].firstName + "</td><td>" + data.Presidents[i].lastName + "</td><td>" + data.Presidents[i].YearInauguratedPresident.month + "</td><td>" + data.Presidents[i].YearInauguratedPresident.year + "</td></tr>"; } output += "</tr></table>"; $('#PresidentInfo').html(output); }); </script> </body> </html> 2. Not-working method using self-executing jquery function before html to be loaded and json method called. <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>JSON Presidents</title> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script type="text/javascript"> /* $(document).ready(function() { $('#PresidentInfo').addClass("odd"); }); */ // self executing function here (function() { $('#PresidentInfo').addClass("odd"); })(); </script> <style type="text/css"> body{ font-family:arial, helvetica, sans-serif; text-align:center; width:100%; margin:200px 0 0 0; } #PresidentInfo{ width:75%; margin:0 auto; } table#data{ width:100%; } table#data th{ background:#333; color:#fff; text-align:center; text-shadow:1px 1px 1px rgba(0,0,0,1); padding:5px; } table#data td{ border:1px solid #333; border-collapse:collapse; padding:10px; margin:0 5px 0 5px; text-align:center; } .odd tr:nth-child(odd) { background-color: #ccc; } </style> </head> <body> <div id="PresidentInfo"></div> <script type="text/javascript"> jQuery.getJSON('data.json', function(data) { var output = "<table id='data'><tr><th>First Name:</th><th>Last Name:</th><th>Month of Inauguration:</th><th>Year of Inauguration:</th></tr>"; for (var i in data.Presidents) { output += "<tr><td>" + data.Presidents[i].firstName + "</td><td>" + data.Presidents[i].lastName + "</td><td>" + data.Presidents[i].YearInauguratedPresident.month + "</td><td>" + data.Presidents[i].YearInauguratedPresident.year + "</td></tr>"; } output += "</tr></table>"; $('#PresidentInfo').html(output); }); </script> </body> </html> 3. Call self-executing function after json method and div#presidentinfo - works! <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>JSON Presidents</title> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <style type="text/css"> body{ font-family:arial, helvetica, sans-serif; text-align:center; width:100%; margin:200px 0 0 0; } #PresidentInfo{ width:75%; margin:0 auto; } table#data{ width:100%; } table#data th{ background:#333; color:#fff; text-align:center; text-shadow:1px 1px 1px rgba(0,0,0,1); padding:5px; } table#data td{ border:1px solid #333; border-collapse:collapse; padding:10px; margin:0 5px 0 5px; text-align:center; } .odd tr:nth-child(odd) { background-color: #ccc; } </style> </head> <body> <div id="PresidentInfo"></div> <script type="text/javascript"> jQuery.getJSON('data.json', function(data) { var output = "<table id='data'><tr><th>First Name:</th><th>Last Name:</th><th>Month of Inauguration:</th><th>Year of Inauguration:</th></tr>"; for (var i in data.Presidents) { output += "<tr><td>" + data.Presidents[i].firstName + "</td><td>" + data.Presidents[i].lastName + "</td><td>" + data.Presidents[i].YearInauguratedPresident.month + "</td><td>" + data.Presidents[i].YearInauguratedPresident.year + "</td></tr>"; } output += "</tr></table>"; $('#PresidentInfo').html(output); }); </script> <script type="text/javascript"> // self executing function here (function() { $('#PresidentInfo').addClass("odd"); })(); </script> </body> </html> So, what is your conclusion?
-
Maybe, you don't understand me very well I've never said that JS or Ajax are part of DOM. No, they aren't, but the content that they created/retrieved will be loaded into DOM in very specific order in the HTML document. His script loads lots of javascript errors into firebird, I will try later, but mine works fine. <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>JSON Presidents</title> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <style type="text/css"> body{ font-family:arial, helvetica, sans-serif; text-align:center; width:100%; margin:200px 0 0 0; } #PresidentInfo{ width:75%; margin:0 auto; } table#data{ width:100%; } table#data th{ background:#333; color:#fff; text-align:center; text-shadow:1px 1px 1px rgba(0,0,0,1); padding:5px; } table#data td{ border:1px solid #333; border-collapse:collapse; padding:10px; margin:0 5px 0 5px; text-align:center; } .odd tr:nth-child(odd) { background-color: #ccc; } </style> </head> <body> <div id="PresidentInfo"></div> <script type="text/javascript"> jQuery.getJSON('data.json', function(data) { var output = "<table id='data'><tr><th>First Name:</th><th>Last Name:</th><th>Month of Inauguration:</th><th>Year of Inauguration:</th></tr>"; for (var i in data.Presidents) { output += "<tr><td>" + data.Presidents[i].firstName + "</td><td>" + data.Presidents[i].lastName + "</td><td>" + data.Presidents[i].YearInauguratedPresident.month + "</td><td>" + data.Presidents[i].YearInauguratedPresident.year + "</td></tr>"; } output += "</tr></table>"; $('#PresidentInfo').html(output).addClass("odd"); }); </script> </body> </html>
-
No. Ajax call should be executed by javascript and all requested data will be probably parsed from the web browser before </body></html> are being loaded in to DOM. So, when the content will be returned back from the server and loaded in to DOM is a different story That's why, we should be always using callback functions while dealing with ajax ( especially with large data, databases, another servers and so on ) just to make sure that all data is successfully retrieved and loaded in to DOM before any rest of data to be parsed of the browser.
-
just assign the css selector to .add class, then add the class to #presidentInfo: example: 1. CSS .odd tr:nth-child(odd) { background-color: #ccc; } 2. All jquery script ( no need extra code ) <script> $.getJSON('data.json', function(data) { var output = "<table id='data'><tr><th>First Name:</th><th>Last Name:</th><th>Month of Inauguration:</th><th>Year of Inauguration:</th></tr>"; for (var i in data.Presidents) { output += "<tr><td>" + data.Presidents[i].firstName + "</td><td>" + data.Presidents[i].lastName + "</td><td>" + data.Presidents[i].YearInauguratedPresident.month + "</td><td>" + data.Presidents[i].YearInauguratedPresident.year + "</td></tr>"; } output += "</tr></table>"; $('#PresidentInfo').html(output).addClass("odd"); }); </script> @CroNiX, according the docs, this (.ready) function/method will be executed after the DOM is done.
-
what debugging steps have you taken so far? A chance to see some of your actual code?
-
Remove the empty space between sum and (). Sum is a function in mysql
-
Because, I've created this on-the-fly codding yesterday, tomorrow I saw some errors. However, the purpose was to get the principle. The second parameter of md5() hash is optional providing a boolean value and can be set to false or omitted to return 32-character hexadecimal number rather than to true as I did. $salt = md5(uniqid(rand(), true)); $pass = md5($_POST['password'].$salt,true); // to $salt = md5(uniqid(rand(), true),false); $pass = md5($_POST['password'].$salt,false); also, the column's name in the users table is named salt_password, not salt. if($row['password'] == md5($_POST['password'].$row['salt'])) // to if($row['password'] == md5($_POST['password'].$row['salt_password'])) BTW: Jacques1 is right. You should avoid using md5() hashing in production environment.
-
Is this the query string trying to execute by php to mysql? if so, that the syntax of your query is not correct.