error in my sql and update failed when just trying to log in

3 messages Options
Embed this post
Permalink
serg () error in my sql and update failed when just trying to log in
Reply Threaded More More options
Print post
Permalink
im getting the following error:  I did a print_r($_POST);
Array ( [username] => redwingsfan32 [password] => fivehole19 [login] => Login ) login sql: select * FROM users WHERE username=`redwingsfan32` AND password=`f953ae3fc30423167a9fd15b8f349459`

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /srv/www/htdocs/TEllis/project 3b/checklogin.php on line 37 Update failed, Click here to try againYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Unknown column 'redwingsfan32' in 'where clause'' at line 1

I am taking one error at a time.  I am able to register the user in to in the database with two table.  user and table2( user_info)

I'm about to give up for the day to step away.

here is my code...

login
<CODE>
<html>
<body>
<h1>Login Page</h1>
<form action="checklogin.php" method="post">
<table border="1" bgcolor='#999999'>
  <tr>
    <td>Username:</td>
    <td><input type="text" name="username" id="username"/></td>
  </tr>
   <tr>
     <td>Password:</td>
    <td><input type="password" name="password" id="password"/></td>
  </tr>
   <tr>
     <td> </td>
     <td><input type="submit" name="login" id="login" value="Login"/></td>
 </tr>
 </table>
 </form>
Not a user. Register Here

</body>
</html>
 </CODE>

checklogin.php
<CODE>

<?php
include "database.php";
$error_msg='';
$success_msg='';
print_r($_POST);

//Get's username from the post  
$myusername = $_POST['username'];
 
// Encrypt the string wih MD5 encryption
$mypassword = md5($_POST['password']);


// Query the database for matching username and password
 $login_sql = ("select * FROM users WHERE username=`$myusername` AND password=`$mypassword`".mysql_error());
 
 // echoing out the SQL statement and run it in the phpMyAdmin view
echo "login sql: " . $login_sql . "<br>\n".mysql_error();
 
 
// Query the database for matching username and password
$res = mysql_query($login_sql);
 
// If there is more then one row returned this must mean the username and password was correct
        $success_msg = "You have successfully logged into your Profile";

        $profile = ("SELECT * FROM user_info WHERE username = `username` AND password = `password`".mysql_error());
        $res = mysql_query($profile);
       
        if(mysql_num_rows($res) >0) {
  $array= mysql_fetch_assoc($res);//$loginsql in the mysql_fetch_assoc() call  
                  echo '<table border="2">';
                  echo "<tr><td>ID:  ";
                  echo "<td>" .$array['id']."</td>\n\t";
                  echo "</tr>";
                   echo "<tr><td>First Name:  ";
                  echo "<td>".$array['first_name']. "</td>\n\t";
                  echo "</td></tr>";
                   echo "<tr><td>Last Name:  ";
                  echo "<td>".$array['last_name']. "</td>\n\t";
                  echo "</td></tr>";
                   echo "<tr><td>Email:  ";
                  echo "<td>".$array['email']. "</td>\n\t";
                  echo "</td></tr>";
                   echo "<tr><td>City:  ";
                  echo "<td>".$array['city']. "</td>\n\t";
                  echo "</td></tr>";
                   echo "<tr><td>State:  ";
                  echo "<td>".$array['state']. "</td>\n\t";
                  echo "</td></tr>\n";
                  echo "</table>\n";
                 // echo 'update';
                 
                   
                } else {
                  // If not, send user back to the login page
                  echo('Update failed, Click here to try again'.mysql_error());
                }





?>
</CODE>

i'm about ready to give up on this just for the night.  maybe stepping away and clearing my head will help.  Plus spent way to long on this.
Christoph Dorn () Re: error in my sql and update failed when just trying to log in
Reply Threaded More More options
Print post
Permalink
Your question does not seem to be related to FirePHP. In future, please seek an alternative support group.

I think your problem is caused by your SQL string:

 $login_sql = ("select * FROM users WHERE username=`$myusername` AND password=`$mypassword`".mysql_error());

which should be more something like:

$login_sql = "select * FROM users WHERE username=`$myusername` AND password=`$mypassword`";

Christoph
Michael Day () Re: error in my sql and update failed when just trying to log in
Reply Threaded More More options
Print post
Permalink
In reply to this post by serg
The exact error you are getting is:

'Unknown column 'redwingsfan32' in 'where clause'' at line 1

The reason is that you are using back quotes instead of single quotes. Single quotes imply a string, while back quotes imply a table or column name. Thus, when you say "WHERE username=`redwingsfan32`", you are literally saying "where the column called username is equal to the column called redwingsfan32" and you get an error for having no column called 'redwingsfan32'. Also, and this isn't causing the error you are getting, but the whole thing does not need to be in parentheses. Change that line to the following:

$login_sql = "select * FROM users WHERE username='$myusername' AND password='$mypassword'".mysql_error(); 


I hope that helped, but like Christoph said, this question was not related to FirePHP, so in the future you should look for a more generalized PHP or MySQL group to seek help from.