Computing.Net > Forums > Programming > PHP and MYSQL, query wont work

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP and MYSQL, query wont work

Reply to Message Icon

Name: Salts
Date: April 1, 2004 at 07:51:58 Pacific
OS: winxp
CPU/Ram: 750 256
Comment:

Hi, i am so annoyed at the moment, i have a query that appear to refuses to run and goes straight to the die command.

session_start();
session_register('auth');
session_register('logname');
include("it.inc");
switch (@$do)
{
case "login":
$connection = mysql_connect($host, $user,$password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");

$sql = "SELECT loginName FROM members
WHERE loginName='$logname'";
$result10 = mysql_query($sql)
or die("Couldn't execute query.problem");

$num = mysql_num_rows($result10);
if ($num == 1) // login name was found
{
$sql = "SELECT loginName FROM members
WHERE loginName='$fusername'
AND password=password('$fpassword')";
$result2 = mysql_query($sql)
or die("Couldn't execute query.");
$num2 = mysql_num_rows($result2);
if ($num2 > 0) // password is correct
{
$auth="yes";
$logname=$fusername;
$today = date("Y-m-d h:m:s");
$sql = "INSERT INTO login (loginName,loginTime)
VALUES ('$logname','$today')";
mysql_query($sql) or die("Can't execute query.");
header("Location: Member_page.php");


i know that the database must be beeing seen as these point give no errors, however when the query runs to....

$sql = "SELECT loginName FROM members
WHERE loginName='$logname'";
$result10 = mysql_query($sql)
or die("Couldn't execute query.problem");
i just get the die output. all the variables are correct, all the table names are correct, i just dont know whats going on, can anyone spot anything with this, or tell me a different/better way of doing it.

Many thanks with this.

Ian

Howdy



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: April 1, 2004 at 08:13:20 Pacific
Reply:

It would be helpful to see mysql's error here, and the final sql query:

$result10 = mysql_query($sql)
or die("Couldn't execute query.problem: $sql ".mysql_error());

See what that outputs and get back to us.

-SN


0

Response Number 2
Name: Salts
Date: April 1, 2004 at 08:24:03 Pacific
Reply:

hey thanks for this bud, im really stuck here, heres that output u wanted, if it helps loginName is a valid field it is a varchar (20) and also the primary key. thanks again.
oh and dave21 is in the table in this field, ive just checked manually.
cheers

Couldn't execute query.problem: SELECT loginName FROM members // 19 WHERE loginName='dave21' You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '// 19 WHERE loginName='dave21'' at line 1

Howdy


0

Response Number 3
Name: SN
Date: April 1, 2004 at 08:44:59 Pacific
Reply:

Salts-
Somehow, an extra "// 19" is coming in between members and WHERE, and that's screwing it all up. Is the code exactly as posted? No comments in there?

This one has got me stumped...I can't see where that // 19 is coming from. The only thing I can think of is to put the sql query all on one line so there's no line break between members and where.

Good luck,
-SN


0

Response Number 4
Name: Salts
Date: April 1, 2004 at 09:07:48 Pacific
Reply:

thanks man, ill give this a go. the //19 is coming from the end of lines of code, i have many of them going down with my code as a guide, i never thought it would be interfering.
Ill get rid of them all now, they aint worth it:)
Ill let u know how it turns out.
thanks again.

Howdy


0

Response Number 5
Name: Salts
Date: April 1, 2004 at 09:10:15 Pacific
Reply:

Yo man, it worked, i really owe u for this, i would have never have got this going if it were not for this forum and ur help. im doing a really big project for my university work and i needed this bad.

Thanks again man, many many thanks.

Howdy


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

VB6 List Box Accessing members of a st...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: PHP and MYSQL, query wont work

PHP and MySql www.computing.net/answers/programming/php-and-mysql/6888.html

php code to email mysql query to me www.computing.net/answers/programming/php-code-to-email-mysql-query-to-me/10499.html

mysql and PHP problem www.computing.net/answers/programming/mysql-and-php-problem/10150.html