syntax error for mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

cnl83
Forum Commoner
Posts: 44
Joined: Mon Sep 26, 2005 10:34 am

syntax error for mysql

Post 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
?>
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
cnl83
Forum Commoner
Posts: 44
Joined: Mon Sep 26, 2005 10:34 am

Post by cnl83 »

Then what should be in place of rnquery?

Also I dont have a session start() in this document.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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);
cnl83
Forum Commoner
Posts: 44
Joined: Mon Sep 26, 2005 10:34 am

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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)
cnl83
Forum Commoner
Posts: 44
Joined: Mon Sep 26, 2005 10:34 am

Post by cnl83 »

No same parse error only with WHILE in it.

shouldnt $mysql be $rnquery ?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ahhh yes sorry didnt bother looking at the variable in there. your right it should be the other one
cnl83
Forum Commoner
Posts: 44
Joined: Mon Sep 26, 2005 10:34 am

Post 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?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

show me your code now
cnl83
Forum Commoner
Posts: 44
Joined: Mon Sep 26, 2005 10:34 am

Post 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>
?>
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
?>
cnl83
Forum Commoner
Posts: 44
Joined: Mon Sep 26, 2005 10:34 am

Post 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; 
  }
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

yes exactally.
cnl83
Forum Commoner
Posts: 44
Joined: Mon Sep 26, 2005 10:34 am

Post 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
Post Reply