Page 1 of 2

syntax error for mysql

Posted: Mon Sep 26, 2005 10:37 am
by cnl83
Ok, I have a form (authentication.php). In this form im trying to check the database to see if certain fields are empty and if they are then send them to example.php . I dont know if my code is correct, but I am getting errors so this might help. Keeep in mind that I am using a class file. I did not write this entire application, but im trying to get it to work for me. I appreciate your help in advanced!

My browser generated error is: Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home3/cnl83/actionfx-www/classes/access_user/authentication.php:4) in /home3/cnl83/actionfx-www/classes/access_user/access_user_class.php on line 25
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 'rnquery' at line 1
My code is:

Code: Select all

<?php 
include($_SERVER['DOCUMENT_ROOT']."/classes/access_user/access_user_class.php"); 

$page_protect = new Access_user;
// $page_protect->login_page = "login.php"; // change this only if your login is on another page
$page_protect->access_page(); // only set this this method to protect your page

if (isset($_GET['action']) && $_GET['action'] == "log_out") {
	$page_protect->log_out(); // the method to log off
}

//NEW CODE
//Error Checker
$error = 0;

$rnquery = @mysql_query("SELECT * FROM tbl_USERS WHERE real_name = '".$realname."'");
$result = mysql_query("rnquery") or die(mysql_error());

$row = @mysql_fetch_row_array($mysql);

//Foreach row check to make sure the fields are filled in
foreach ($row as $key => $value) {

If ($value = "") {
$error = $error + 1;
}

}

If ($error > 0) {
 header("location: example.php");
}
//END OF NEW CODE
?>

Posted: Mon Sep 26, 2005 10:51 am
by shiznatix

Code: Select all

$result = mysql_query("rnquery") or die(mysql_error());
rnquery is not sql in any way, so when you do that it will give you a invalid sql error. you already queried $rnquery in the previous line so you don't have to do it twice.

the headers problem, session_start(); has to be the FIRST line of the code, not in the middle.

Posted: Mon Sep 26, 2005 10:55 am
by cnl83
Then what should be in place of rnquery?

Also I dont have a session start() in this document.

Posted: Mon Sep 26, 2005 11:00 am
by feyd
output started in /home3/cnl83/actionfx-www/classes/access_user/authentication.php on line 4. Line 25 of that file has the session_start() call.

remove this entire line

Code: Select all

$result = mysql_query("rnquery") or die(mysql_error());
change

Code: Select all

$row = @mysql_fetch_row_array($mysql);
to$row = mysql_fetch_row($rnquery);

Posted: Mon Sep 26, 2005 11:15 am
by cnl83
Ok it must have passed the previous point, now im getting.

Parse error: parse error, unexpected T_FOREACH in /home3/cnl83/actionfx-www/classes/access_user/example.php on line 20

Posted: Mon Sep 26, 2005 11:22 am
by shiznatix
well $row is not a array, it is a string. try

Code: Select all

while ($row = mysql_fetch_row_array($mysql)
instead of your foreach statement. also you don't need all of those @ symbols everywhere. if those things are going to give you errors then you might want to know about it instead of suppressing the errors (thats what the @ does, suppresses errors)

Posted: Mon Sep 26, 2005 11:26 am
by cnl83
No same parse error only with WHILE in it.

shouldnt $mysql be $rnquery ?

Posted: Mon Sep 26, 2005 12:17 pm
by shiznatix
ahhh yes sorry didnt bother looking at the variable in there. your right it should be the other one

Posted: Mon Sep 26, 2005 12:20 pm
by cnl83
Im still getting the parse error

Parse error: parse error, unexpected T_WHILE in /home3/cnl83/actionfx-www/classes/access_user/example.php on line 20

Any other ideas?

Posted: Mon Sep 26, 2005 12:21 pm
by shiznatix
show me your code now

Posted: Mon Sep 26, 2005 12:23 pm
by cnl83

Code: Select all

<?php 
include($_SERVER['DOCUMENT_ROOT']."/classes/access_user/access_user_class.php"); 

$page_protect = new Access_user;
// $page_protect->login_page = "login.php"; // change this only if your login is on another page
$page_protect->access_page(); // only set this this method to protect your page

if (isset($_GET['action']) && $_GET['action'] == "log_out") {
	$page_protect->log_out(); // the method to log off
}
//NEW <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>
//Error Checker
$error = 0;

$rnquery = mysql_query("SELECT * FROM tbl_USERS WHERE real_name = '".$realname."'");

$row = mysql_fetch_row($rnquery)

//Foreach row check to make sure the fields are filled in
while ($row = mysql_fetch_row_array($rnquery)  {

If ($value = "") {
$error = $error + 1;
}

}

If ($error > 0) {
 header("location: authenticated.php");
}
//END OF NEW <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>
?>

Posted: Mon Sep 26, 2005 12:31 pm
by shiznatix
you obviously did not write this script.

Code: Select all

<?php
include($_SERVER['DOCUMENT_ROOT']."/classes/access_user/access_user_class.php");

$page_protect = new Access_user;
// $page_protect->login_page = "login.php"; // change this only if your login is on another page
$page_protect->access_page(); // only set this this method to protect your page

if (isset($_GET['action']) && $_GET['action'] == "log_out") {
   $page_protect->log_out(); // the method to log off
}
//NEW smurf
//Error Checker
$error = 0;

$rnquery = mysql_query("SELECT * FROM tbl_USERS WHERE real_name = '".$realname."'");

//Foreach row check to make sure the fields are filled in
while ($row = mysql_fetch_assoc($rnquery))  {

  If ($value = "") {//change $value to $row['field_name_you_are_checking_here']
    $error = $error + 1;
  }

}

If ($error > 0) {
 header("location: authenticated.php");
}
//END OF NEW smurf
?>

Posted: Mon Sep 26, 2005 12:38 pm
by cnl83
No, I did not write this. Im still a noob.

Do you mean change the code like this?

Code: Select all

//Foreach row check to make sure the fields are filled in 
while ($row = mysql_fetch_assoc($rnquery))  { 

  If ($row['real_name'] = "") {//change $value to $row['field_name_you_are_checking_here'] 
    $error = $error + 1; 
  }

Posted: Mon Sep 26, 2005 12:49 pm
by shiznatix
yes exactally.

Posted: Mon Sep 26, 2005 12:52 pm
by cnl83
I do apologize for bugging the heck out of you, but im still getting a parse error.

Parse error: parse error, unexpected $ in /home3/cnl83/actionfx-www/classes/access_user/example.php on line 61

If you would like you can login and see what im getting

http://www.actionfx.net/classes/access_user/login.php

testlogin
test