Jump to content

i need a second set of eyes please?


Hillary

Recommended Posts

Parse error: syntax error, unexpected T_VARIABLE in C:\Inetpub\wwwroot\StudentWeb\WIS-220-B1N01-SPRING2009\student1546\races2run\selectRecords.php on line 28

 

<?php include('stylesR2R.css') ?>
<html>
<body>
<?php include ("dbinit.php"); ?>
<font size="12" face="arial">Search Results.</font><br>
<font face="arial">
        <a href="runnersDirectory.php">Runners Directory.</a><br>
        <a href="index.php">Find a Runner.</a><br>
<br>
    
<?php
// Bring me the data!!!
$firstName = mysql_real_escape_string($_GET['firstName']);
$lastName = mysql_real_escape_string($_GET['lastName']);
$age = mysql_real_escape_string($_GET['age']);
$sex = mysql_real_escape_string($_GET['sex']);
$raceName = mysql_real_escape_string($_GET['raceName']);
$distance = mysql_real_escape_string($_GET['distance']);
$city = mysql_real_escape_string($_GET['city']);
$state = mysql_real_escape_string($_GET['state']);
$date = mysql_real_escape_string($_GET['date']);
$time = mysql_real_escape_string($_GET['time']);
$place = mysql_real_escape_string($_GET['place']);
$divPlace = mysql_real_escape_string($_GET['divPlace']);
$pace = mysql_real_escape_string($_GET['pace']);

$query = "SELECT * FROM records
    WHERE firstName LIKE "$firstName%" //THIS IS LINE 28!!!
    OR lastName LIKE "$lastName%"
    OR age LIKE "$age%"
    OR sex LIKE "$sex%"
    OR raceName LIKE "$raceName%"
    OR distance LIKE "$distance%"
    OR city LIKE "$city%"
    OR state LIKE "$state%"
    OR date LIKE "$date%"
    OR time LIKE "$time%"
    OR place LIKE "$place%"
    OR divPlace LIKE "$divPlace%"
    OR pace LIKE "$pace%"";

$result = mysql_query($query, $db) or die(mysql_error().": $query");
$runners = mysql_fetch_assoc($result);
?>
<?php if ($runners) { ?>
<?php include('recordsTable.php'); ?>
<?php }else{
            echo "The runner you have searched for is not listed in this directory.";
            }?> 
<br><br><?php include('footerR2R.html') ?>
  
  </body>
</html>

 

can any one help me figure out what is wrong?

 

also, it only does this when i add the '%' sign to each VAR. from my knowledge the '%' sign is needed to be able to search partials in a database but retrieve a complete string of information? is that wrong? or should i post this is the MySQL forums? PLEASE PLEASE PLEASE HELP!! :) thank you much.

Link to comment
Share on other sites

Answering this question because I like the name Hillary.

 


$query = "SELECT * FROM records
    WHERE firstName LIKE "$firstName%" \ //THIS IS LINE 28!!!
    OR lastName LIKE "$lastName%" \
    OR age LIKE "$age%" \
    OR sex LIKE "$sex%" \
    OR raceName LIKE "$raceName%" \
    OR distance LIKE "$distance%" \
    OR city LIKE "$city%" \
    OR state LIKE "$state%" \
    OR date LIKE "$date%" \
    OR time LIKE "$time%" \
    OR place LIKE "$place%" \
    OR divPlace LIKE "$divPlace%" \
    OR pace LIKE "$pace%"";

 

That should solve your problem

Link to comment
Share on other sites

thanks guys that was a great help, however... my new error is this:

 

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 '\ OR lastName LIKE '%' \ OR age LIKE '%' \ OR sex LIKE '%' \ ' at line 2: SELECT * FROM records WHERE firstName LIKE 'Larry%' \ OR lastName LIKE '%' \ OR age LIKE '%' \ OR sex LIKE '%' \ OR raceName LIKE '%' \ OR distance LIKE '%' \ OR city LIKE '%' \ OR state LIKE '%' \ OR date LIKE '%' \ OR time LIKE '%' \ OR place LIKE '%' \ OR divPlace LIKE '%' \ OR pace LIKE '%'

 

if at any time you'd like to send me to the MySQL boards i will not be mad.

 

<?php include('stylesR2R.css') ?>
<html>
<body>
<?php include ("dbinit.php"); ?>
<font size="12" face="arial">Search Results.</font><br>
<font face="arial">
        <a href="runnersDirectory.php">Runners Directory.</a><br>
        <a href="index.php">Find a Runner.</a><br>
<br>
    
<?php
// Bring me the data!!!
$firstName = mysql_real_escape_string($_GET['firstName']);
$lastName = mysql_real_escape_string($_GET['lastName']);
$age = mysql_real_escape_string($_GET['age']);
$sex = mysql_real_escape_string($_GET['sex']);
$raceName = mysql_real_escape_string($_GET['raceName']);
$distance = mysql_real_escape_string($_GET['distance']);
$city = mysql_real_escape_string($_GET['city']);
$state = mysql_real_escape_string($_GET['state']);
$date = mysql_real_escape_string($_GET['date']);
$time = mysql_real_escape_string($_GET['time']);
$place = mysql_real_escape_string($_GET['place']);
$divPlace = mysql_real_escape_string($_GET['divPlace']);
$pace = mysql_real_escape_string($_GET['pace']);

$query = "SELECT * FROM records
    WHERE firstName LIKE '$firstName%' \
    OR lastName LIKE '$lastName%' \
    OR age LIKE '$age%' \
    OR sex LIKE '$sex%' \
    OR raceName LIKE '$raceName%' \
    OR distance LIKE '$distance%' \
    OR city LIKE '$city%' \
    OR state LIKE '$state%' \
    OR date LIKE '$date%' \
    OR time LIKE '$time%' \
    OR place LIKE '$place%' \
    OR divPlace LIKE '$divPlace%' \
    OR pace LIKE '$pace%'";

$result = mysql_query($query, $db) or die(mysql_error().": $query");
$runners = mysql_fetch_assoc($result);
?>
<?php if ($runners) { ?>
<?php include('recordsTable.php'); ?>
<?php }else{
            echo "The runner you have searched for is not listed in this directory.";
            }?> 
<br><br><?php include('footerR2R.html') ?>
  
  </body>
</html>

 

does that mean that i have to fill in all fields when searching for something in the data base and if it does how can i make it so that you dont have to require all fields?... sorry. i'm very new to this. :) thanks again

Link to comment
Share on other sites

Try:

$query = "SELECT * FROM `records`
    WHERE firstName LIKE '$firstName%' 
    OR lastName LIKE '$lastName%'
    OR age LIKE '$age%'
    OR sex LIKE '$sex%'
    OR raceName LIKE '$raceName%'
    OR distance LIKE '$distance%'
    OR city LIKE '$city%'
    OR state LIKE '$state%'
    OR `date` LIKE '$date%'
    OR `time` LIKE '$time%'
    OR place LIKE '$place%'
    OR divPlace LIKE '$divPlace%'
    OR pace LIKE '$pace%'";

Link to comment
Share on other sites

Try this:

 

<?php include('stylesR2R.css') ?>
<html>
<body>
<?php include ("dbinit.php"); ?>
<font size="12" face="arial">Search Results.</font><br>
<font face="arial">
        <a href="runnersDirectory.php">Runners Directory.</a><br>
        <a href="index.php">Find a Runner.</a><br>
<br>

<?php
// Bring me the data!!!
$fields = array('firstName', 'lastName', 'age', 'sex', 'raceName', 'distance', 'city', 'state', 'date', 'time', 'place', 'divPlace', 'pace');
$fieldSql = array();
foreach ($fields as $field) {
    if (!empty($_GET[$field])) {
        $fieldSql[] = '`'.$field.'` LIKE \''.mysql_real_escape_string($_GET[$field]).'%\';
    }
}
if ($fieldSql) {
    $query = 'SELECT * FROM `records` WHERE '.implode(' OR ', $fieldSql);
}
else {
    $query = 'SELECT * FROM `records`';
}

$result = mysql_query($query, $db) or die(mysql_error().": $query");
$runners = mysql_fetch_assoc($result);
?>
<?php if ($runners) { ?>
<?php include('recordsTable.php'); ?>
<?php }else{
            echo "The runner you have searched for is not listed in this directory.";
            }?>
<br><br><?php include('footerR2R.html') ?>

  </body>
</html>

Link to comment
Share on other sites

also it looks like your variables are empty.  Make sure you are using the proper $_GET['varnamehere'].  Make sure you are sending them via the GET method in the first place (are they coming from a form via POST method, for instance? Should be $_POST['varnamehere'])

 

i'm not sure what you mean crayon voilent.

 

<?php include('stylesR2R.css') ?>
<html>
<body>
<?php include ("dbinit.php"); ?>
<font size="12" face="arial">Input Results.</font><br>
<font face="arial">
<a href="runnersDirectory.php">Runners Directory.</a><br>
<a href="index.php">Find a Runner.</a><br><br><br><br>
<?php
// put the data in the table... you do this when youre told!!		
$sql="INSERT INTO records (firstName, lastName, age, sex, raceName, distance, city, state, date, time, place, divPlace, pace)
VALUES 
('$_POST[firstName]', '$_POST[lastName]', '$_POST[age]', '$_POST[sex]', '$_POST[raceName]', '$_POST[distance]', '$_POST[city]', '$_POST[state]', '$_POST[date]', '$_POST[time]', '$_POST[place]', '$_POST[divPlace]', '$_POST[pace]')";

if (!mysql_query($sql, $db))
{
die('FAIL!: ' . mysql_error());
}

echo "Success! 1 New record has been added.";

mysql_close($db);
?></font>
<br><br><br><br><br>
<?php include('footerR2R.html') ?>
</body>
</html>

 

this is the file i made to input the information... each field is empty until someone fills it in and posts it at which time its sent to its appropriate variable in a table i created in phpMyadmin with MySQL.

 

CREATE TABLE records (
id int PRIMARY KEY,
firstName VARCHAR(25)NOT NULL,
lastName VARCHAR(25)NOT NULL,
age VARCHAR(3)NOT NULL,
sex VARCHAR(1)NOT NULL,
raceName VARCHAR(50)NOT NULL,
distance VARCHAR(8)NOT NULL,
city VARCHAR(15)NOT NULL,
state VARCHAR(11)NOT NULL,
date VARCHAR(8)NOT NULL,
time VARCHAR(8)NOT NULL,
place VARCHAR(6)NOT NULL,
divPlace VARCHAR(6)NOT NULL,
pace VARCHAR(10)NOT NULL
)

INSERT INTO records 
VALUES (
'0', 'Wayne', 'Kursh', '00', 'M', 'Demo', '000000', 'Montchanin', 'Delaware', '00/00/00', '00:00:00', '10,000', '1', '00.00'
)

 

retrieving the information is where i am having trouble. before i inserted all the \'s and %'s it kind of worked it would only retrieve the first name that matched the search but i am wondering how i can make this so that it will retrieve everyone in my database with a name matching the search criteria. if i search for Larry... only one Larry was displayed but there are 3 Larry's in total. i am very confused? thank you for putting up with me... i'm sorry for any confusion.

Link to comment
Share on other sites

Can you show us your updated search code?

 

yes sir.

 

<?php include('stylesR2R.css') ?>
<html>
<body>
<?php include ("dbinit.php"); ?>
<font size="12" face="arial">Search Results.</font><br>
<font face="arial">
        <a href="runnersDirectory.php">Runners Directory.</a><br>
        <a href="index.php">Find a Runner.</a><br>
<br>
    
<?php
// Bring me the data!!!
$firstName = mysql_real_escape_string($_GET['firstName']);
$lastName = mysql_real_escape_string($_GET['lastName']);
$age = mysql_real_escape_string($_GET['age']);
$sex = mysql_real_escape_string($_GET['sex']);
$raceName = mysql_real_escape_string($_GET['raceName']);
$distance = mysql_real_escape_string($_GET['distance']);
$city = mysql_real_escape_string($_GET['city']);
$state = mysql_real_escape_string($_GET['state']);
$date = mysql_real_escape_string($_GET['date']);
$time = mysql_real_escape_string($_GET['time']);
$place = mysql_real_escape_string($_GET['place']);
$divPlace = mysql_real_escape_string($_GET['divPlace']);
$pace = mysql_real_escape_string($_GET['pace']);

$query = "SELECT * FROM records
    WHERE firstName LIKE \'$firstName%'\
    OR lastName LIKE \'$lastName%'\
    OR age LIKE \'$age%'\
    OR sex LIKE \'$sex%'\
    OR raceName LIKE \'$raceName%'\
    OR distance LIKE \'$distance%'\
    OR city LIKE \'$city%'\
    OR state LIKE \'$state%'\
    OR date LIKE \'$date%'\
    OR time LIKE \'$time%'\
    OR place LIKE \'$place%'\
    OR divPlace LIKE \'$divPlace%'\
    OR pace LIKE \'$pace%'";

$result = mysql_query($query, $db) or die(mysql_error().": $query");
$runners = mysql_fetch_assoc($result);
?>
<?php if ($runners) { ?>
<?php include('recordsTable.php'); ?>
<?php }else{
            echo "The runner you have searched for is not listed in this directory.";
            }?> 
<br><br><?php include('footerR2R.html') ?>
  
  </body>
</html>

Link to comment
Share on other sites

Not sure why you are trying to escape those quotes

 

Try:

$query = "SELECT * FROM `records`
    WHERE firstName LIKE '$firstName%' 
    OR lastName LIKE '$lastName%'
    OR age LIKE '$age%'
    OR sex LIKE '$sex%'
    OR raceName LIKE '$raceName%'
    OR distance LIKE '$distance%'
    OR city LIKE '$city%'
    OR state LIKE '$state%'
    OR `date` LIKE '$date%'
    OR `time` LIKE '$time%'
    OR place LIKE '$place%'
    OR divPlace LIKE '$divPlace%'
    OR pace LIKE '$pace%'";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.