Jump to content

**fixed** This is making me nuts... error near " on line 1???


jmilane

Recommended Posts

I have been at this for 3 hours... am I missing something obvious???

[code]<html>
<head>
<title>
ULEM Registration Database Search Form
</title>
<body>

<?PHP

$username="ghf";
$password="gfghgfh";
$database="ghgfh";
$databox="www.ghfhgfh.org";

mysql_connect($databox,$username,$password);

@mysql_select_db($database) or die("Unable to select database");

if (isset($_POST['regid'])) {
$regid = $_POST['regid'];
$query = "select employmentprog, businessprog, certprog, youthprog, parentprog, policyprog, firstname, middlename, lastname, birthdate, street, city, state, postalcode, homephone, otherphone, referral, contact, race, otherrace, gender, regdate from registration where id = $regid";
}

if (isset($_POST['lastname'])) {
$ln = $_POST['lastname'];
$query = "select employmentprog, businessprog, certprog, youthprog, parentprog, policyprog, firstname, middlename, lastname, birthdate, street, city, state, postalcode, homephone, otherphone, referral, contact, race, otherrace, gender, regdate from registration where lastname = $ln";
}

$result=mysql_query($query) or die(mysql_error()); 

$num=mysql_num_rows($result);

if ($num == 0) {echo "No matching records."; return;}

mysql_close();

echo "<b><center>The results of your search:</center></b><br><br>";

$i=0;
while ($i < $num) {

$firstname=mysql_result($result,$i,"firstname");
$middlename=mysql_result($result,$i,"middlename");
$lastname=mysql_result($result,$i,"lastname");
$homephone=mysql_result($result,$i,"homephone");
$otherphone=mysql_result($result,$i,"otherphone");
$street=mysql_result($result,$i,"street");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$postalcode=mysql_result($result,$i,"postalcode");
$referral=mysql_result($result,$i,"referral");
$race=mysql_result($result,$i,"race");
$otherrace=mysql_result($result,$i,"otherrace");
$contact=mysql_result($result,$i,"contact");
$gender=mysql_result($result,$i,"gender");
$regdate=mysql_result($result,$i,"regdate");

echo "<b>$firstname $lastname</b><br>Phone: $homephone<br>Other Phone: $otherphone<br>Street: $street<br>City: $city<br>Zip: $postalcode<br>Best time to contact $contact<br>Race: $race<br>Other race (if applicable): $otherrace<br>Gender: $gender<br>Registration date: $regdate<br><hr>";

$i++;
}

?>
</html>[/code]
Link to comment
Share on other sites

Could you post the full error message(s) here please as it'll help us understand whats going on. I think the error you are getting isnt to do with PHP but to do with MySQL queries. As the "[i]error near .... on line 1[/i]" is common with errors in SQL queries as the error is comming from the database rather than PHP itself.
Link to comment
Share on other sites

[code]Change this line:
<?php $result=mysql_query($query) or die(mysql_error());  ?>
to
<?php $result=mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());  ?>[/code]
This will tell you if the query has a problem (which is usually the case when you get an error like that)

BTW, it looks like you're getting all the fields from your data base. If this is the case I would write your query as:
[code]<?php
$whr = '';
if (isset($_POST['regid'])) $whr = " where id = '" . mysql_real_escape_string($_POST['regid']) . "'";
if (isset($_POST['lastname'])) $whr = " where ln = '" . mysql_real_escape_string($_POST['lastname']) . "'";
$query = "select * from registration" . $whr;
?>[/code]

Ken
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.