Jump to content

PHP Code Issues


Recommended Posts

Im trying to make a site where when I go to add a member, it adds them to a database, but when I made this, it won't write to the database for some reason and I know that connect.phtml works because its used for other scripts that I have written and they all connect to the database.  When I remove "if(isset($_POST['select']))", it does write to the database but every time when I go to refresh the page, it also puts a blank entry into the database so I can't have that happen.  Does anyone see what might be going wrong?

<?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 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();
  ?>

Link to comment
Share on other sites

Thats weird, now when I remove that line of code, it worked before where every time when I refreshed it would submit blank entries, but now its giving me an error when I remove the line of code.

 

Error in 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 ''name','password','email')values('','','')' at line 1

Link to comment
Share on other sites

<?php
include "connect.phtml";
$db="delranfire_org";

print_r( $_POST );


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());
}
?>

 

Where does $name $password and $email come from?

 

Also add: print_r( $_POST );

 

monk.e.boy

 

Link to comment
Share on other sites

Where does $name $password and $email come from?

register_globals must be off.

Change

 $query1="insert into member('name','password','email')values('$name','$password','$email')";

to

 $query1="insert into member('name','password','email')values('".$_POST['name']."','".$_POST['password']."','".$_POST['email']."')";

Link to comment
Share on other sites

I replaced the code but nothing changed.

My code updated:

<?php
include "connect.phtml";
$db="delranfire_org";

print_r( $_POST );


if(isset($_POST['select']))
{
$query1="insert into member('name','password','email')values('".$_POST['name']."','".$_POST['password']."','".$_POST['email']."l')";
    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();
  ?>

Link to comment
Share on other sites

<?php
include "connect.phtml";
$db="delranfire_org";

print_r( $_POST );


if(isset($_POST['select']))
{
$query1="insert into member('name','password','email')values('".$_POST['name']."','".$_POST['password']."','".$_POST['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();
  ?>

Link to comment
Share on other sites

should be:

<?php
include "connect.phtml";
$db="delranfire_org";

print_r( $_POST );


if(isset($_POST['select']))
{
$query1="insert into member('name','password','email')values('".$_POST['name']."','".$_POST['password']."','".$_POST['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();
  ?>

Link to comment
Share on other sites

I just made a new database, the old one has alot of entries already and its getting boring scrolling through all of the entries to see if it posted or not, the new one is called members

Updated code is below

<?php
include "connect.phtml";
$db="delranfire_org";

print_r( $_POST );


if(isset($_POST['select']))
{
$query1="insert into members('name','password','email')values('".$_POST['name']."','".$_POST['password']."','".$_POST['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();
  ?>

Could my database be wrong?

Field - ID

Type - int(10)

Attributes - UNSIGNED

Null - No

Default -

Extra - auto_increment

Action -

---

Field - Name

Type - Varchar(55)

Attributes -

Null - Yes

Default - NULL

Extra -

Action -

---

Field - Password

Type - Varchar(55)

Attributes -

Null - Yes

Default - NULL

Extra -

Action -

---

Field - email

Type - Varchar(55)

Attributes -

Null - Yes

Default - NULL

Extra -

Action -

Link to comment
Share on other sites

Yea, I know I saw yours already, but it still doesn't post.

<?php
include "connect.phtml";
$db="delranfire_org";

print_r( $_POST );


if(isset($_POST['select']))
{
$query1="insert into member (name,`password`,email) values ('".$_POST['name']."','".$_POST['password']."','".$_POST['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();
  ?>

Link to comment
Share on other sites

Try downloading the free program SQLog, this will let you connect to your database and test out your SQL commands.

 

When you have them running OK, you can past the SQL into your PHP program.

 

You need to do this else you will have these problems every time you try to change any of your SQL.

 

<?php
$query1="insert into member (Name,Password,Email) values ('".$_POST['name']."','".$_POST['password']."','".$_POST['email']."')";

echo $query1;

?>

 

I don't know if MySQL column names are case sensitive? I've never seen anyone use capitals in them before...

 

monk.e.boy

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.