Jump to content

PHP / MySql Simple Problem


Ducky1

Recommended Posts

Hey Guys. Thanks for looking. I cant figure what on earth is wrong with the code below  :facewall: . It takes a user ID and password, if it's right, it sets a variable to true. This i have confirmed works fine. I also know that the "by" part of my sql table is there. Thanks.

 

<?php
$pass = $_POST['passwd'];
$user = $_POST['login'];
$auth = "FALSE";
$conn = mysql_connect("...", "...", "...");
if (!$conn ) 
{ 
echo "ERROR: Could not connect to the database."; 
}
$did_we_find_a_db_to_use = mysql_select_db("rovstr_peter");
if (!$did_we_find_a_db_to_use) 
{ 
echo "ERROR: Invalid database name."; 
}

echo "<b> Working... Please Wait... </b>";

$data = mysql_query("SELECT * FROM users WHERE name = '$user'");
while($info = mysql_fetch_array($data))
{
if($info['pass'] == $pass)
{
$auth = "TRUE";
}
}

if($auth == "TRUE")
{
Echo ("Prescription table for: $user");
$data = mysql_query("SELECT * FROM medicine WHERE by = '$user'");
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array($data))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['name'] . "</td> ";
Print "<th>Dosage:</th> <td>".$info['dosage'] . " </td>";
Print "<th>Description:</th> <td>".$info['descr'] . "</td> ";
Print "<th>When:</th> <td>".$info['time'] . "</td>";
Print "<th>Set by:</th> <td>".$info['by'] . "</td></tr>";
}
Print "</table>";
}

else
{
echo "Username/password incorrect";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/169072-php-mysql-simple-problem/
Share on other sites

I dont get an error, i get a blank reply, even though i know the data is in the table.. i suspect the sql query?

execute this query in your phpmyadmin and see if mysql throws any error

SELECT * FROM medicine WHERE by = '$user'  //make sure to replace $user with the name

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.