Jump to content

What is wrong???????


searls03

Recommended Posts

Here is code I have, I can't seem to figure this error out,  I bet it is obvious, but I clearly am not seeing it.....  Here is error:

Problem with the query:

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 '' at line 3

 

(not really that good of an error, but maybe help getting started?)

 

 

<?php
session_start(); // Must start session first thing
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/
// Here we run a login check
if (!isset($_SESSION['id'])) { 
   echo 'Please <a href="login.php">log in</a> to access your account';
   exit(); 
}
//Connect to the database through our include 
include_once "connect_to_mysql.php";
// Place Session variable 'id' into local variable
$userid = $_SESSION['id'];
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$name = $row["name"];
$phone = $row["phone"];
$username = $row["username"];
$address = $row["address"];
$city = $row["city"];
$state = $row["state"];
$zip = $row["zip"];
$cell = $row["cell"];
$email = $row["email"];
$accounttype = $row["accounttype"];
$rank = $row["rank"];
$badges = $row["badges"];
}
// Set error message as blank upon arrival to page
$errorMsg = "";
// First we check to see if the form has been submitted 
if (isset($_POST['name'])){
$name = ereg_replace("[^A-Z a-z0-9]", "", $_POST['name']); // filter everything but numbers and letters
$phone = ereg_replace("[^A-Z a-z0-9]", "", $_POST['phone']); // filter everything but spaces, numbers, and letters
$username = ereg_replace("[^A-Z a-z0-9]", "", $_POST['username']); // filter everything but spaces, numbers, and letters
$address = ereg_replace("[^A-Z a-z0-9]", "", $_POST['address']); // filter everything but spaces, numbers, and letters
$city = ereg_replace("[^A-Za-z0-9]", "", $_POST['city']); // filter everything but lowercase letters
$state = ereg_replace("[^A-Za-z0-9]", "", $_POST['state']); // filter everything but lowercase letters
$zip = ereg_replace("[^A-Za-z0-9]", "", $_POST['zip']); // filter everything but lowercase letters
$cell = ereg_replace("[^A-Za-z0-9]", "", $_POST['cell']); // filter everything but lowercase letters
$accounttype = ereg_replace("[^A-Z a-z0-9]", "", $_POST['accounttype']); // filter everything but lowercase letters
$email = stripslashes($_POST['email']);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
// Check to see if the user filled all fields with
// the "Required"(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$name) || (!$username) || (!$password)){

	$errorMsg = "You did not submit the following required information!<br /><br />";
	if(!$name){
		$errorMsg .= "--- Name";
	} else if(!$username){ 
	    $errorMsg .= "--- Username"; 
   } else if(!$Password){ 
       $errorMsg .= "--- Password";    
   }
} else {
// Database duplicate Fields Check
$sql_username_check = mysql_query("SELECT userid FROM members WHERE username='$username' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check); 
if ($username_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
} else {
	// Add MD5 Hash to the password variable
       $hashedPass = md5($password); 
	// Add user info into the database table, claim your fields then values 
	$sql = mysql_query("INSERT INTO members (name, phone, username, address, city, state, zip, cell, email, accounttype, password ) 

	VALUES('$name','$phone','$username','$address','$city','$state','$zip','$cell','$email','$accounttype','$hashedPass'") or die ("Problem with the query: $sql<br>" . mysql_error());
printf("Records updated: %d\n", mysql_affected_rows());
	echo mysql_error();

	 echo '<meta HTTP-EQUIV="REFRESH" content="3; url=http://final.net46.net/success.php">';

	exit(); // Exit so the form and page does not display, just this success message
} // Close else after database duplicate field value checks
  } // Close else after missing vars check
//Close if $_POST
}

?>

Link to comment
Share on other sites

This query is not correct. You ended the query string too soon. I would put the query in it's own variable, which makes debugging much easier:

<?php
$sql = "INSERT INTO members (name, phone, username, address, city, state, zip, cell, email, accounttype, password ) 
	VALUES('$name','$phone','$username','$address','$city','$state','$zip','$cell','$email','$accounttype','$hashedPass')";
$rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error());
?>

 

Ken

 

Link to comment
Share on other sites

So I have a display box that looks like attatchment.....except a name goes under troop 78.........so everytime I forget to type in a required field either there will be nothing under that or it will be the name that I typed in if i typed a name in but nothing else......

 

[attachment deleted by admin]

Link to comment
Share on other sites

Separate the query string from the query execution and store it in a variable. While developing, echo the query string along with any error when one occurs.

 

$query = "SELECT field FROM table";
if( !$result = mysql_query($query) ) {
     echo "<br>Query string: $query<br>Produced error: " . mysql_error() . '<br>';
}

Link to comment
Share on other sites

Separate the query string from the query execution and store it in a variable. While developing, echo the query string along with any error when one occurs.

 

$query = "SELECT field FROM table";
if( !$result = mysql_query($query) ) {
     echo "<br>Query string: $query<br>Produced error: " . mysql_error() . '<br>';
}

 

which problem was this for, the first issue has been solved.....

Link to comment
Share on other sites

I will post whole code so you can see it:

<?php
session_start(); // Must start session first thing
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/
// Here we run a login check
if (!isset($_SESSION['id'])) { 
   echo 'Please <a href="login.php">log in</a> to access your account';
   exit(); 
}
//Connect to the database through our include 
include_once "connect_to_mysql.php";
// Place Session variable 'id' into local variable
$userid = $_SESSION['id'];
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$name = $row["name"];
$phone = $row["phone"];
$username = $row["username"];
$address = $row["address"];
$city = $row["city"];
$state = $row["state"];
$zip = $row["zip"];
$cell = $row["cell"];
$email = $row["email"];
$accounttype = $row["accounttype"];
$rank = $row["rank"];
$badges = $row["badges"];
}
// Set error message as blank upon arrival to page
$errorMsg = "";
// First we check to see if the form has been submitted 
if (isset($_POST['name'])){
$name = ereg_replace("[^A-Z a-z0-9]", "", $_POST['name']); // filter everything but numbers and letters
$phone = ereg_replace("[^A-Z a-z0-9]", "", $_POST['phone']); // filter everything but spaces, numbers, and letters
$username = ereg_replace("[^A-Z a-z0-9]", "", $_POST['username']); // filter everything but spaces, numbers, and letters
$address = ereg_replace("[^A-Z a-z0-9]", "", $_POST['address']); // filter everything but spaces, numbers, and letters
$city = ereg_replace("[^A-Za-z0-9]", "", $_POST['city']); // filter everything but lowercase letters
$state = ereg_replace("[^A-Za-z0-9]", "", $_POST['state']); // filter everything but lowercase letters
$zip = ereg_replace("[^A-Za-z0-9]", "", $_POST['zip']); // filter everything but lowercase letters
$cell = ereg_replace("[^A-Za-z0-9]", "", $_POST['cell']); // filter everything but lowercase letters
$accounttype = ereg_replace("[^A-Z a-z0-9]", "", $_POST['accounttype']); // filter everything but lowercase letters
$email = stripslashes($_POST['email']);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
// Check to see if the user filled all fields with
// the "Required"(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$name) || (!$username) || (!$password)){

	$errorMsg = "You did not submit the following required information!<br /><br />";
	if(!$name){
		$errorMsg .= "--- Name";
	} else if(!$username){ 
	    $errorMsg .= "--- Username"; 
   } else if(!$Password){ 
       $errorMsg .= "--- Password";    
   }
} else {
// Database duplicate Fields Check
$sql_username_check = mysql_query("SELECT userid FROM members WHERE username='$username' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check); 
if ($username_check > 0){ 
	$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
} else {
	// Add MD5 Hash to the password variable
       $hashedPass = md5($password); 
	// Add user info into the database table, claim your fields then values 
$sql = "INSERT INTO members (name, phone, username, address, city, state, zip, cell, email, accounttype, password ) 
	VALUES('$name','$phone','$username','$address','$city','$state','$zip','$cell','$email','$accounttype','$hashedPass')";
$rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error());
	echo mysql_error();

	 echo '<meta HTTP-EQUIV="REFRESH" content="0; url=http://final.net46.net/success.php">';

	exit(); // Exit so the form and page does not display, just this success message
} // Close else after database duplicate field value checks
  } // Close else after missing vars check
//Close if $_POST
}

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template2.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<style type="text/css">
#apDiv1 {
position:absolute;
left:33px;
top:320px;
width:252px;
height:48px;
z-index:1;
}
#apDiv2 {
position:absolute;
left:33px;
top:361px;
width:254px;
height:46px;
z-index:2;
}
#apDiv3 {
position:absolute;
left:33px;
top:525px;
width:256px;
height:43px;
z-index:3;
}
#apDiv4 {
position:absolute;
left:33px;
top:402px;
width:250px;
height:48px;
z-index:4;
}
#apDiv5 {
position:absolute;
left:106px;
top:616px;
width:263px;
height:255px;
z-index:5;
}
#apDiv6 {
position:absolute;
left:323px;
top:200px;
width:898px;
height:530px;
z-index:1;
}
#apDiv7 {
position:absolute;
left:33px;
top:443px;
width:266px;
height:42px;
z-index:6;
}
#apDiv8 {
position:absolute;
left:111px;
top:500px;
width:125px;
height:37px;
z-index:7;
}
#apDiv8 strong {
font-size: 24px;
}
#apDiv9 {
position:absolute;
left:33px;
top:408px;
width:267px;
height:49px;
z-index:8;
}
#apDiv10 {
position:absolute;
left:33px;
top:449px;
width:242px;
height:23px;
z-index:9;
}
#apDiv8 a {
color: #000;
}
#apDiv11 {
position:absolute;
left:101px;
top:490px;
width:168px;
height:42px;
z-index:10;
font-size: 24px;
font-weight: bold;
}
#apDiv11 a {
color: #000;
}
#apDiv12 {
position:absolute;
left:33px;
top:210px;
width:205px;
height:135px;
z-index:11;
}
#apDiv12 {
text-align: center;
}
#apDiv13 {
position:absolute;
left:33px;
top:320px;
width:258px;
height:47px;
z-index:12;
}
#apDiv {
position:absolute;
left:33px;
top:484px;
width:225px;
height:35px;
z-index:11;
}
#apDiv14 {
position:absolute;
left:33px;
top:566px;
width:298px;
height:51px;
z-index:12;
}
#apDiv15 {	position:absolute;
left:101px;
top:611px;
width:168px;
height:42px;
z-index:10;
font-size: 24px;
font-weight: bold;
}
#apDiv5 a {
font-size: 24px;
color: #000;
font-weight: bold;
}
</style>
<script type="text/javascript">
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
<!-- InstanceBeginEditable name="head" -->
<script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
<!-- InstanceParam name="id" type="text" value="apDiv6" -->
</head>
<body onload="MM_preloadImages('button/myprofile2.png','button/pictures2.png','button/projects1.png','button/news2.png','button/eventmanager2.png','button/membermanager2.png','button/newsmanager2.png')">
<div id="apDiv2"><a href="register.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image3','','button/register2.png',1)"><img src="button/register1.png" name="Image3" width="235" height="50" border="0" id="Image3" /></a></div>
<div id="apDiv4"><a href="projects.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','button/projects2.png',1)"><img src="button/projects1.png" name="Image4" width="235" height="50" border="0" id="Image4" /></a></div>

<div id="apDiv11"><?php if ($accounttype == "Scout") {
echo '<a href="../logout.php">Logout</a>';} ?></div>
<div id="apDiv12"><?php echo "$accounttype"; ?>
  <p><?php echo "$name"; ?></p>
  <p>Troop 78</p>
</div>
<div id="apDiv13"><a href="myprofile.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','button/myprofile2.png',1)"><img src="button/myprofile1.png" name="Image5" width="235" height="50" border="0" id="Image5" /></a></div>
<div id="apDiv5"><?php if ($accounttype == "Admin") {
echo "<a href=\"../logout.php\">Logout</a>";
}
?></div>
</a>
</div>
<div id="apDiv6"><!-- InstanceBeginEditable name="EditRegion3" -->
<div id="TabbedPanels1" class="TabbedPanels">
  <ul class="TabbedPanelsTabGroup">
    <li class="TabbedPanelsTab" tabindex="0">My Info</li>
    <li class="TabbedPanelsTab" tabindex="0">Scout Info</li>
  </ul>
  <div class="TabbedPanelsContentGroup">
    <div class="TabbedPanelsContent"><table width="600" align="center" cellpadding="4">
  <tr>
    <td width="7%">Register new members here</td>
  </tr>
</table>
<table width="600" align="center" cellpadding="5">
  <form action="join_form.php" method="post" enctype="multipart/form-data" >
    <tr>
      <td colspan="2"><font color="#FF0000"><?php echo "$errorMsg"; ?></font></td>
    </tr>
    <tr>
      <td width="163"><div align="right">Name:</div></td>
      <td width="409"><input name="name" type="text" /></td>
    </tr>
     <tr>
      <td width="163"><div align="right">Phone:</div></td>
      <td width="409"><input name="phone" type="text" /></td>
    </tr>
    <tr>
      <td><div align="right">User Name: </div></td>
      <td><input name="username" type="text" /></td>
    </tr>
    <tr>
      <td><div align="right">Address: </div></td>
      <td>
        <input name="address" type="text" />
      </td>
    </tr>
  <tr>
      <td><div align="right">City: </div></td>
      <td>
        <input name="city" type="text" />
      </td>
    </tr>
    <tr>
      <td><div align="right">State: </div></td>
      <td><input name="state" type="text" /></td>
    </tr>
    <tr>
      <td><div align="right">Zip Code: </div></td>
      <td><input name="zip" type="text" /></td>
    </tr>
<tr>
      <td><div align="right">Cell Phone: </div></td>
      <td><input name="cell" type="text" /></td>
    </tr>
    <tr>
      <td><div align="right">Access Level: </div></td>
      <td><select name="accounttype" id="accounttype">
<option value="Scout" selected="selected">Scout</option>
        <option value="Scout Master">Scout Master</option>
        <option value="Admin">Admin</option>
      </select></td>
    </tr>
        </tr>
<tr>
      <td><div align="right">Email Address: </div></td>
      <td><input name="email" type="text" /></td>
    </tr>

    <tr>
      <td><div align="right"> Password: </div></td>
      <td><input name="password" type="password" /> 
      <font size="-2" color="#006600">(letters or numbers only, no spaces no symbols)</font></td>
    </tr> 
    <tr>
      <td><div align="right"></div></td>
      <td><input type="submit" name="Submit" value="Submit Form" /></td>
    </tr>
  </form>
</table></div>
    <div class="TabbedPanelsContent">
    Please create member profile for Scout Info.
    </div>
  </div>
</div>
<script type="text/javascript">
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
</script>
<!-- InstanceEndEditable --></div>
<div id="apDiv7"><a href="news.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','button/news2.png',1)"><img src="button/news1.png" name="Image6" width="235" height="50" border="0" id="Image6" /></a></div>
<div id="apDiv"> <?php if ($accounttype == "Admin") {
echo "<a href=\"../membermanager.php\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image7','','../button/membermanager2.png',1)\"><img src=\"../button/membermanager1.png\" name=\"Image7\" width=\"235\" height=\"50\" border=\"0\" id=\"Image7\" /></a>";
} 
?></div>
<div id="apDiv3"><?php if ($accounttype == "Admin") {
echo "<a href=\"../addevent.php\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image8','','../button/eventmanager2.png',1)\"><img src=\"../button/eventmanager1.png\"  name=\"Image8\" width=\"235\" height=\"50\" border=\"0\" id=\"Image8\" /></a>";
}
?>
</div>
<div id="apDiv14"><?php if ($accounttype == "Admin") {
echo "<a href=\"../addart.php\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('Image9','','../button/newsmanager2.png',1)\"><img src=\"../button/newsmanager1.png\"  name=\"Image9\" width=\"234\" height=\"50\" border=\"0\" id=\"Image9\" /></a>";
}
?>
</div>
<img name="boyscout" src="button/boyscout.jpg" width="1180" height="700" border="0" id="boyscout" alt="" />
</body>
<!-- InstanceEnd --></html>

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.