blank entry problems

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

Post Reply
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

blank entry problems

Post by NuclearDoctor »

When ever I load this page, it always puts a blank line entry in he members directory, does anyone see why?

Code: Select all

<?

include "connect.phtml";
$db="delranfire_org";
{ 

  $query1="insert into member(name,password,email)values('$name','$password','$email')"; 
  mysql_db_query($db,$query1,$connection) or die("Error in query:$query. " .mysql_error()); 

}//end if 

?>
<html>
<head>
<title>
<?
include "admin_panel_title.php";?>
</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#FF3333" vlink="#CC0000" alink="#CC0000">
<form action="addmember.phtml" method="post">
<center>
<img src="/newadmin/Administration_Panel_Banner.png"><br>
<h3>Add a Person to a Duty Crew</h3>
  <table border="1" cellspacing="0" cellpadding="0" align="center">
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">First & Last Name:&nbsp</font></b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="name" SIZE="30"></INPUT>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="1">Password:&nbsp</font></b></font></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="password" SIZE="30"></INPUT>	
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>EMail Address**:&nbsp</b></font></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="email" SIZE="30"></INPUT>
      </td>
    </tr>
    <tr>
      <td colspan="3">
        <div align="center">
          <input type="submit" name="Submit" value="Add Member">
          <input type="reset" name="reset" value="Clear Information">
        </div>
      </td>
    </tr>
  </table>
  </form>
<a href="/newadmin/">Back to Administration Panel</a><br>
<br>
<font size="2">**This field will not create an email address.  The email address must be added though the CPanel
</body></html>
  <?
  mysql_close();
  ?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Are you talking about the HTML no showing something, the PHP not showing something or the query not inserting something?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The query is always called, thus always inserting.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Duh, I didn't even see that there is no if statement (hint to the OP).
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post by NuclearDoctor »

yea every time i refresh the page, a blank entry would show up... did i forget the if then statement again?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Yes. This is what you have now:

Code: Select all

<?

include "connect.phtml";
$db="delranfire_org";
{

  $query1="insert into member(name,password,email)values('$name','$password','$email')";
  mysql_db_query($db,$query1,$connection) or die("Error in query:$query. " .mysql_error());

}//end if

?>
This is what it should be:

Code: Select all

<?php
include "connect.phtml";
$db="delranfire_org";
if (<enter your conditional here>)
{
    $query1="insert into member (`name`, `password`, `email`) values ('$name', '$password', '$email')";
    // Stop using mysql_db_query(), it is deprecated. Use mysql_select_db($dbname) and mysql_query(), like below
    mysql_query($query1) or die("Error in query:$query. " .mysql_error());
}
?>
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post by NuclearDoctor »

I just replaced my code with:

Code: Select all

<?php
include "connect.phtml";
$db="delranfire_org";
if(isset($_POST['select'])){
{
    $query1="insert into member (name,password,email) values ('$name','$password', '$email')";
    mysql_query($query1) or die("Error in query:$query. " .mysql_error());
}
?>
and now im getting an error:
Parse error: syntax error, unexpected $end in /home2/delranfd/delranfire-www/newadmin/addmember.phtml on line 63

But the funny part is I dont even have 63 lines of code...?

Code: Select all

<?php
include "connect.phtml";
$db="delranfire_org";
if(isset($_POST['select'])){
{
    $query1="insert into member (name,password,email) values ('$name','$password', '$email')";
    mysql_query($query1) or die("Error in query:$query. " .mysql_error());
}
?>
<html>
<head>
<title>
<?
include "admin_panel_title.php";?>
</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#FF3333" vlink="#CC0000" alink="#CC0000">
<form action="addmember.phtml" method="post">
<center>
<img src="/newadmin/Administration_Panel_Banner.png"><br>
<h3>Add a Person to a Duty Crew</h3>
  <table border="1" cellspacing="0" cellpadding="0" align="center">
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">First & Last Name:&nbsp</font></b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="name" SIZE="30"></INPUT>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="1">Password:&nbsp</font></b></font></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="password" SIZE="30"></INPUT>	
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>EMail Address**:&nbsp</b></font></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="email" SIZE="30"></INPUT>
      </td>
    </tr>
    <tr>
      <td colspan="3">
        <div align="center">
          <input type="submit" name="Submit" value="Add Member">
          <input type="reset" name="reset" value="Clear Information">
        </div>
      </td>
    </tr>
  </table>
  </form>
<a href="/newadmin/">Back to Administration Panel</a><br>
<br>
<font size="2">**This field will not create an email address.  The email address must be added though the CPanel
</body></html>
  <?
  mysql_close();
  ?>


EDIT: I got it, I had two {{ at the top

This is what it was:

Code: Select all

<?php
include "connect.phtml";
$db="delranfire_org";
if(isset($_POST['select'])){
{
    $query1="insert into member (name,password,email) values ('$name','$password', '$email')";
    mysql_query($query1) or die("Error in query:$query. " .mysql_error());
}
?>
And it should be:

Code: Select all

<?php
include "connect.phtml";
$db="delranfire_org";
if(isset($_POST['select']))
{
    $query1="insert into member (name,password,email) values ('$name','$password', '$email')";
    mysql_query($query1) or die("Error in query:$query. " .mysql_error());
}
?>
Thanks for your help guys.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Glad you got it working.
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post by NuclearDoctor »

Ok, correction... its not working now, when I added that if code on the 5th line down, it looks like its working, but it won't write anything to the database until I remove that line of code. When I remove the if code, it will take all of the entries that I tried to submit before and it will allow them to go through after, so its like a firewall and nothing can get through it until its removed, everything is building up outside of it... but when I remove that code, it all works fine except it keeps putting blank entries in when ever i refresh the page... hmmm...

Code: Select all

<?php
include "connect.phtml";
$db="delranfire_org";
if(isset($_POST['select']))
{
    $query1="insert into members('name','password','email')values('$name','$password','$email')";
    mysql_query($query1) or die("Error in query:$query. " .mysql_error());
}
?>

<html>
<head>
<title>
<?
include "admin_panel_title.php";?>
</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#FF3333" vlink="#CC0000" alink="#CC0000">
<form action="addmember.phtml" method="post">
<center>
<img src="/newadmin/Administration_Panel_Banner.png"><br>
<h3>Add a Member</h3>
  <table border="1" cellspacing="0" cellpadding="0" align="center">
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1">First & Last Name:&nbsp</font></b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="name" SIZE="30"></INPUT>
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="1">Password:&nbsp</font></b></font></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="password" SIZE="30"></INPUT>	
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>EMail Address**:&nbsp</b></font></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="email" SIZE="30"></INPUT>
      </td>
    </tr>
    <tr>
      <td colspan="3">
        <div align="center">
          <input type="submit" name="Submit" value="Add Member">
          <input type="reset" name="reset" value="Clear Information">
        </div>
      </td>
    </tr>
  </table>
  </form>
<a href="/newadmin/">Back to Administration Panel</a><br>
<br>
<font size="2">**This field will not create an email address.  The email address must be added though the CPanel
</body></html>
  <?
  mysql_close();
  ?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Unless you want that query run on every page load, you should trigger it with something. Lets look at this through comments, shall we?

Code: Select all

<?php
// Check to see if there is a form field called select that is set (this should use empty())
// If there is a form field named 'select' set, then we run the following query
if (!empty($_POST['select']))
{
    // There is, so now we need to insert the variables
    // One quick question? WHERE ARE THESE VALUES ($name, $password and $email) SET?
    // Also, you want to use backticks (`) around field names, not single quotes (')
    $query1 = "INSERT INTO `members` (`name`, `password`, `email`) VALUES ('$name', '$password', '$email')";

    // INSERT queries that are successful return boolean true
    // So we check if the function returns false, which would mean failure
    if (mysql_query($query1) === false)
    {
        die("Error in query: $query1 " . mysql_error());
    }
}

// At this point, the query could have been run or not
// It would depend on the trigger in the if statement above
?>
Post Reply