adamdyer Posted August 23, 2007 Share Posted August 23, 2007 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 More sharing options...
xyn Posted August 23, 2007 Share Posted August 23, 2007 this will work. $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/#findComment-331733 Share on other sites More sharing options...
XaeroDegreaz Posted August 23, 2007 Share Posted August 23, 2007 You need tilde signs ( ` ) around field names, not quotes ( ' ) $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/#findComment-331734 Share on other sites More sharing options...
adamdyer Posted August 23, 2007 Author Share Posted August 23, 2007 Cheers :-) however now im getting this message : Table 'ajdref.BOOKING DATABASE' doesn't exist but it does exist because ive been using that Booking Database for other connections :-s Link to comment https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/#findComment-331735 Share on other sites More sharing options...
xyn Posted August 23, 2007 Share Posted August 23, 2007 You dont actually have to use them i mean... $sql = SELECT * FROM table WHERE field = '$var' will work the same as $sql = SELECT * FROM `table` WHERE `field` ='$var' Link to comment https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/#findComment-331736 Share on other sites More sharing options...
xyn Posted August 23, 2007 Share Posted August 23, 2007 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? Link to comment https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/#findComment-331737 Share on other sites More sharing options...
adamdyer Posted August 23, 2007 Author Share Posted August 23, 2007 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' Link to comment https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/#findComment-331740 Share on other sites More sharing options...
xyn Posted August 23, 2007 Share Posted August 23, 2007 Show me your sql query Link to comment https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/#findComment-331744 Share on other sites More sharing options...
Fjerpje Posted August 23, 2007 Share Posted August 23, 2007 Hi there, Doesnt matter this error says you have an error in your SQL syntax so. I suggest you do this: $query = "SELECT * FROM table WHERE columname='blabla',columname=..."; mysql_query($query); Link to comment https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/#findComment-331746 Share on other sites More sharing options...
adamdyer Posted August 23, 2007 Author Share Posted August 23, 2007 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> Link to comment https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/#findComment-331748 Share on other sites More sharing options...
xyn Posted August 23, 2007 Share Posted August 23, 2007 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 Link to comment https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/#findComment-331751 Share on other sites More sharing options...
adamdyer Posted August 23, 2007 Author Share Posted August 23, 2007 perfect! it works! thanks alot to everyone who helped me with this - ive still a few more problems, and will probably be back later with them! :-) Link to comment https://forums.phpfreaks.com/topic/66318-solved-whats-wrong-with-this-code/#findComment-331758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.