Jump to content

[SOLVED] whats wrong with this code?


adamdyer

Recommended Posts

I keep getting a syntax error :

 

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 ''BOOKING DATABASE' where CUSTOMER_ID = '' and PASSWORD = ''`' at line 1

 

 

#create the query - sets $sql to contain the required query
$sql = "SELECT * from 'BOOKING DATABASE' where CUSTOMER_ID = '$CUSTOMER_USERNAME' and PASSWORD = '$PASSWORD'`";

Link to comment
https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/
Share on other sites

You need tilde signs ( ` ) around field names, not quotes ( ' )

 

$sql = "SELECT * from `BOOKING DATABASE` where `CUSTOMER_ID` = '$CUSTOMER_USERNAME' and PASSWORD = '$PASSWORD'";

 

check your database connections. if you're using two different databases

then you will need to specify the database ie:

 

SELECT * FROM `data_base`.`table_name`  WHERE ...

 

Or check for spelling mistakes?

has it got anything to do with the fact I havent specified my username and filepath

 

<font size="4">Customer Page<hr>
<a href="http://puma.marjon.ac.uk/~your_user_name/path&filename" target="_self">Click here</a> to return to the home page<p></p>

 

or does that not matter to the connection?

 

AHA! I kinda fixed that bit, now im getting this message:

 

Incorrect Username or Password entered.

 

AND also this message

 

Unknown column 'CUSTOMER_USERNAME' in 'where clause'

I'll post the whole coding just incase ive mucked up somewhere else.

 

<HTML>
<HEAD>
<TITLE>Check Customer ID</TITLE>
</HEAD>
<body BGCOLOR=lemonchiffon>

<font size="4">Customer Page<hr>
<a href="http://puma.marjon.ac.uk/~your_user_name/path&filename" target="_self">Click here</a> to return to the home page<p></p>

<?php 

$Customer_Username= $_POST['ID_Search'];

$Password = $_POST['Password_Search'];

# connect to MySQL
$conn = @mysql_connect("localhost","ajdref","ref2")
or die ("sorry - could not connect to MySQL"); 

# select the specified database
$rs = @mysql_select_db("ajdref", $conn)
or die ("sorry - could not connect to the ajdref");

#create the query - sets $sql to contain the required query
$sql = "SELECT * from `Booking Database` where `CUSTOMER_USERNAME` = '$CUSTOMER_USERNAME' and PASSWORD = '$PASSWORD'";

$rs = mysql_query($sql,$conn) or die(mysql_error());

?>

<hr>
<p>Make a booking... </p>
<p>Search for a booking...</p>
</font>
</BODY>
</HTML>

try this:

$sql = "SELECT * from `Booking Database` where `customer_username` = '$Customer_Username' and password = '$Password'";

 

A lesson to learn Mysql and PHP are case sencitive.. so

 

PASSWORD and Password are two different variables :)

the above should work as long as your mysql tables are LOWERCASE

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.