parse error in php file?

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 2478 Views - Last Post: 26 October 2011 - 02:23 PM

#1 yaykittyeee   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 59
  • Joined: 16-September 10

parse error in php file?

Posted 23 October 2011 - 03:53 PM

Hello, i'm new to php. I keep getting the error:

Parse error: syntax error, unexpected 'users' (T_STRING) in C:\websites\checklogin.php on line 10

users is the name of the table i'm trying to access. i would really appreciate any advice on what i'm doing wrong.
here's my code:

<?php
$un=$_POST['username'];
$pw=$_POST['password'];
//connect to the db
$user ='root';
$pswd ='october3';
$db ='BillMe';
$conn = mysql_connect('localhost',$user,$pswd);
mysql_select_db($db);
$sqlquery =“SELECT * FROM users WHERE username=$un AND password=$pw”;
$result = mysql_query($sqlquery) or die(“Unable to verify user because : ” . mysql_error());
if(mysql_num_rows($result) > 0){
echo 1;  // for correct login response
}
else{
echo 0; // for incorrect login response
}
?>



Is This A Good Question/Topic? 0
  • +

Replies To: parse error in php file?

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3795
  • View blog
  • Posts: 13,738
  • Joined: 08-August 08

Re: parse error in php file?

Posted 23 October 2011 - 04:15 PM

Since you're new to PHP start by learning to use prepared statements instead of soon to be deprecated mysql_ functions.

Oh, and there's a difference between curly quotes and straight quotes. You want to use straight quotes but are probably getting curly quotes because you're using Word. Use a real text editor like Textwrangler (Mac) or Notepad++ (PC).
Was This Post Helpful? 2
  • +
  • -

#3 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: parse error in php file?

Posted 23 October 2011 - 04:25 PM

Quote

$sqlquery =“SELECT * FROM users WHERE username=$un AND password=$pw”;


What are you using to write your code? Those double quotes looks like you're using a word processor that generates "smart quotes", and that's not recommended.
Was This Post Helpful? 3
  • +
  • -

#4 yaykittyeee   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 59
  • Joined: 16-September 10

Re: parse error in php file?

Posted 23 October 2011 - 05:12 PM

you were right about the quotes. i'm using notepad++ from now on. that error is gone but now i have another one

Fatal error: Call to undefined function mysql_connect() in C:\websites\checklogin.php on line 8

i've been checking around for a solution and found something that said I should take the ; away from ;extension=php_mysql.dll in my php.ini file. i did that and now my apache server won't even start. i'll keep searching but any help would be very appreciated. thank you very much.
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3795
  • View blog
  • Posts: 13,738
  • Joined: 08-August 08

Re: parse error in php file?

Posted 23 October 2011 - 05:20 PM

You shouldn't be using mysql_connect. Read the link on PDO prepared statements from post #2.
Was This Post Helpful? 1
  • +
  • -

#6 yaykittyeee   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 59
  • Joined: 16-September 10

Re: parse error in php file?

Posted 23 October 2011 - 05:44 PM

ok, i've replaced all of the mysql_functions with the pdo stuff. from what i've read so far, i've edited my code and i'm still getting an error:

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\websites\checklogin.php:16 Stack trace: #0 C:\websites\checklogin.php(16): PDO->__construct('mysql:host=loca...', 'root', 'october3') #1 {main} thrown in C:\websites\checklogin.php on line 16

here's my new code:

<?php
//$un=$_POST['username'];
//$pw=$_POST['password'];
//connect to the db
//$user ='root';
//$pswd ='october3';
//$db ='BillMe';

$host = 'localhost';
$port = 1080;
$database = 'BillMe';
$username = 'root';
$password = 'october3';

$dsn = "mysql:host=$host;port=$port;dbname=$database";
$db = new PDO($dsn, $username, $password);

//$conn = mysql_connect('localhost',$user,$pswd);
//mysql_select_db($db,$conn);
$statement = $db->prepare("SELECT * FROM users WHERE username = ? AND password = ?");
$statement->execute(array($_POST['susanf01'], $_POST['0001']));
//$sqlquery ="SELECT * FROM users WHERE username=$un AND password=$pw";
//$result = mysql_query($sqlquery) or die("Unable to verify user because : " . mysql_error());
//if(mysql_num_rows($result) > 0){
if($result = $statement->fetchObject()){
echo 1;  // for correct login response
}
else{
echo 0; // for incorrect login response
}
?>


Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3795
  • View blog
  • Posts: 13,738
  • Joined: 08-August 08

Re: parse error in php file?

Posted 23 October 2011 - 05:57 PM

Run this:
<?php
phpinfo();
?>

and tell us what you see under mysql support.
Was This Post Helpful? 1
  • +
  • -

#8 yaykittyeee   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 59
  • Joined: 16-September 10

Re: parse error in php file?

Posted 23 October 2011 - 06:05 PM

PHP Version 5.4.0beta2

and then a lot of information. should i post any of that?
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6642
  • View blog
  • Posts: 30,931
  • Joined: 10-May 07

Re: parse error in php file?

Posted 23 October 2011 - 06:06 PM

View Postyaykittyeee, on 23 October 2011 - 09:05 PM, said:

PHP Version 5.4.0beta2

and then a lot of information. should i post any of that?


View PostCTphpnwb, on 23 October 2011 - 08:57 PM, said:

and tell us what you see under mysql support.

Was This Post Helpful? 0
  • +
  • -

#10 yaykittyeee   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 59
  • Joined: 16-September 10

Re: parse error in php file?

Posted 23 October 2011 - 06:14 PM

mysqlnd
mysqlnd	enabled
Version 	mysqlnd 5.0.9-dev - 20110325 - $Revision: 318221 $
Compression 	supported
SSL 	supported
Command buffer size 	4096
Read buffer size 	32768
Read timeout 	31536000
Collecting statistics 	Yes
Collecting memory statistics 	Yes
Tracing 	n/a
Loaded plugins 	mysqlnd,example,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password
API Extensions 	no value

mysqlnd statistics	
bytes_sent 	0
bytes_received 	0
packets_sent 	0
packets_received 	0
protocol_overhead_in 	0
protocol_overhead_out 	0
bytes_received_ok_packet 	0
bytes_received_eof_packet 	0
bytes_received_rset_header_packet 	0
bytes_received_rset_field_meta_packet 	0
bytes_received_rset_row_packet 	0
bytes_received_prepare_response_packet 	0
bytes_received_change_user_packet 	0
packets_sent_command 	0
packets_received_ok 	0
packets_received_eof 	0
packets_received_rset_header 	0
packets_received_rset_field_meta 	0
packets_received_rset_row 	0
packets_received_prepare_response 	0
packets_received_change_user 	0
result_set_queries 	0
non_result_set_queries 	0
no_index_used 	0
bad_index_used 	0
slow_queries 	0
buffered_sets 	0
unbuffered_sets 	0
ps_buffered_sets 	0
ps_unbuffered_sets 	0
flushed_normal_sets 	0
flushed_ps_sets 	0
ps_prepared_never_executed 	0
ps_prepared_once_executed 	0
rows_fetched_from_server_normal 	0
rows_fetched_from_server_ps 	0
rows_buffered_from_client_normal 	0
rows_buffered_from_client_ps 	0
rows_fetched_from_client_normal_buffered 	0
rows_fetched_from_client_normal_unbuffered 	0
rows_fetched_from_client_ps_buffered 	0
rows_fetched_from_client_ps_unbuffered 	0
rows_fetched_from_client_ps_cursor 	0
rows_affected_normal 	0
rows_affected_ps 	0
rows_skipped_normal 	0
rows_skipped_ps 	0
copy_on_write_saved 	0
copy_on_write_performed 	0
command_buffer_too_small 	0
connect_success 	0
connect_failure 	0
connection_reused 	0
reconnect 	0
pconnect_success 	0
active_connections 	0
active_persistent_connections 	0
explicit_close 	0
implicit_close 	0
disconnect_close 	0
in_middle_of_command_close 	0
explicit_free_result 	0
implicit_free_result 	0
explicit_stmt_close 	0
implicit_stmt_close 	0
mem_emalloc_count 	0
mem_emalloc_amount 	0
mem_ecalloc_count 	0
mem_ecalloc_amount 	0
mem_erealloc_count 	0
mem_erealloc_amount 	0
mem_efree_count 	0
mem_efree_amount 	0
mem_malloc_count 	0
mem_malloc_amount 	0
mem_calloc_count 	0
mem_calloc_amount 	0
mem_realloc_count 	0
mem_realloc_amount 	0
mem_free_count 	0
mem_free_amount 	0
mem_estrndup_count 	0
mem_strndup_count 	0
mem_estndup_count 	0
mem_strdup_count 	0
proto_text_fetched_null 	0
proto_text_fetched_bit 	0
proto_text_fetched_tinyint 	0
proto_text_fetched_short 	0
proto_text_fetched_int24 	0
proto_text_fetched_int 	0
proto_text_fetched_bigint 	0
proto_text_fetched_decimal 	0
proto_text_fetched_float 	0
proto_text_fetched_double 	0
proto_text_fetched_date 	0
proto_text_fetched_year 	0
proto_text_fetched_time 	0
proto_text_fetched_datetime 	0
proto_text_fetched_timestamp 	0
proto_text_fetched_string 	0
proto_text_fetched_blob 	0
proto_text_fetched_enum 	0
proto_text_fetched_set 	0
proto_text_fetched_geometry 	0
proto_text_fetched_other 	0
proto_binary_fetched_null 	0
proto_binary_fetched_bit 	0
proto_binary_fetched_tinyint 	0
proto_binary_fetched_short 	0
proto_binary_fetched_int24 	0
proto_binary_fetched_int 	0
proto_binary_fetched_bigint 	0
proto_binary_fetched_decimal 	0
proto_binary_fetched_float 	0
proto_binary_fetched_double 	0
proto_binary_fetched_date 	0
proto_binary_fetched_year 	0
proto_binary_fetched_time 	0
proto_binary_fetched_datetime 	0
proto_binary_fetched_timestamp 	0
proto_binary_fetched_string 	0
proto_binary_fetched_blob 	0
proto_binary_fetched_enum 	0
proto_binary_fetched_set 	0
proto_binary_fetched_geometry 	0
proto_binary_fetched_other 	0
init_command_executed_count 	0
init_command_failed_count 	0
com_quit 	0
com_init_db 	0
com_query 	0
com_field_list 	0
com_create_db 	0
com_drop_db 	0
com_refresh 	0
com_shutdown 	0
com_statistics 	0
com_process_info 	0
com_connect 	0
com_process_kill 	0
com_debug 	0
com_ping 	0
com_time 	0
com_delayed_insert 	0
com_change_user 	0
com_binlog_dump 	0
com_table_dump 	0
com_connect_out 	0
com_register_slave 	0
com_stmt_prepare 	0
com_stmt_execute 	0
com_stmt_send_long_data 	0
com_stmt_close 	0
com_stmt_reset 	0
com_stmt_set_option 	0
com_stmt_fetch 	0
com_deamon 	0
bytes_received_real_data_normal 	0
bytes_received_real_data_ps 	0

example statistics	
stat1 	0
stat2 	0 


Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3795
  • View blog
  • Posts: 13,738
  • Joined: 08-August 08

Re: parse error in php file?

Posted 23 October 2011 - 06:44 PM

I was looking for something like below. So far I'm wondering if you've found a problem with the beta version of PHP 5.4

Attached image(s)

  • Attached Image

Was This Post Helpful? 1
  • +
  • -

#12 yaykittyeee   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 59
  • Joined: 16-September 10

Re: parse error in php file?

Posted 23 October 2011 - 07:58 PM

those are the only tables that mention mysql

Posted Image
Was This Post Helpful? 0
  • +
  • -

#13 yaykittyeee   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 59
  • Joined: 16-September 10

Re: parse error in php file?

Posted 23 October 2011 - 08:27 PM

i added a try/catch thingy:

try{
$db = new PDO($dsn);
$statement = $db->prepare("SELECT * FROM users WHERE username = ? AND password = ?");
$statement->execute(array($_POST['susanf01'], $_POST['0001']));
if($result = $statement->fetchObject()){
echo 1;  // for correct login response
}
else{
echo 0; // for incorrect login response
}
}
catch(PDOException $e){
echo $e->getMessage();
}



and now i'm just getting this error:

could not find driver
Was This Post Helpful? 0
  • +
  • -

#14 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3795
  • View blog
  • Posts: 13,738
  • Joined: 08-August 08

Re: parse error in php file?

Posted 23 October 2011 - 08:31 PM

In your php.ini file do you have any value for this?
mysql.default_socket =
Was This Post Helpful? 0
  • +
  • -

#15 yaykittyeee   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 59
  • Joined: 16-September 10

Re: parse error in php file?

Posted 23 October 2011 - 08:39 PM

nope

could it have something to do with this line in php.ini

;extension=php_pdo_mysql.dll
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2