Page 1 of 1
blank entry problems
Posted: Tue May 01, 2007 10:39 am
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: </font></b></div>
</td>
<td width="51%" valign="middle">
 <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: </font></b></font></div>
</td>
<td width="51%" valign="middle">
 <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**: </b></font></div>
</td>
<td width="51%" valign="middle">
 <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();
?>
Posted: Tue May 01, 2007 10:41 am
by RobertGonzalez
Are you talking about the HTML no showing something, the PHP not showing something or the query not inserting something?
Posted: Tue May 01, 2007 10:44 am
by feyd
The query is always called, thus always inserting.
Posted: Tue May 01, 2007 10:47 am
by RobertGonzalez
Duh, I didn't even see that there is no if statement (hint to the OP).
Posted: Tue May 01, 2007 11:57 am
by NuclearDoctor
yea every time i refresh the page, a blank entry would show up... did i forget the if then statement again?
Posted: Tue May 01, 2007 12:04 pm
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());
}
?>
Posted: Tue May 01, 2007 12:16 pm
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: </font></b></div>
</td>
<td width="51%" valign="middle">
 <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: </font></b></font></div>
</td>
<td width="51%" valign="middle">
 <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**: </b></font></div>
</td>
<td width="51%" valign="middle">
 <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.
Posted: Tue May 01, 2007 12:26 pm
by RobertGonzalez
Glad you got it working.
Posted: Tue May 01, 2007 4:07 pm
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: </font></b></div>
</td>
<td width="51%" valign="middle">
 <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: </font></b></font></div>
</td>
<td width="51%" valign="middle">
 <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**: </b></font></div>
</td>
<td width="51%" valign="middle">
 <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();
?>
Posted: Tue May 01, 2007 4:39 pm
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
?>