nucleardoctor Posted May 2, 2007 Share Posted May 2, 2007 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: </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(); ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted May 2, 2007 Share Posted May 2, 2007 try: if($_POST['select'] != "") Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 Nope, didn't work, any other ideas? Quote Link to comment Share on other sites More sharing options...
papaface Posted May 2, 2007 Share Posted May 2, 2007 You should really put this on the submit rather than the select: if(isset($_POST['submit'])) Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 Nope, still didn't work on submit =/ Quote Link to comment Share on other sites More sharing options...
papaface Posted May 2, 2007 Share Posted May 2, 2007 Change the filename to addmember.php and change where the form is being submitted to, to addmember.php to. Then see if it works Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 The .php didn't work. Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted May 2, 2007 Share Posted May 2, 2007 <?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 Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 Its my values that are to be submitted... or wait, do I even need them sence im not recieving any data? It says "Array ( [name] => test [password] => etest => test [submit] => Add Member )" at the top but its still not writting to the database Quote Link to comment Share on other sites More sharing options...
papaface Posted May 2, 2007 Share Posted May 2, 2007 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']."')"; Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 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: </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(); ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted May 2, 2007 Share Posted May 2, 2007 '".$_POST['email']."l' should be: '".$_POST['email']."' Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 Now I get Parse error: syntax error, unexpected T_STRING in /home2/delranfd/delranfire-www/newadmin/addmember.phtml on line 11 Quote Link to comment Share on other sites More sharing options...
papaface Posted May 2, 2007 Share Posted May 2, 2007 Show the code. Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 <?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: </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(); ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted May 2, 2007 Share Posted May 2, 2007 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: </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(); ?> Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 Parse error: syntax error, unexpected T_STRING in /home2/delranfd/delranfire-www/newadmin/addmember.phtml on line 11 Quote Link to comment Share on other sites More sharing options...
papaface Posted May 2, 2007 Share Posted May 2, 2007 This is simple PHP, put a ; at the end of: $query1="insert into member('name','password','email')values('".$_POST['name']."','".$_POST['password']."','".$_POST['email']."')" Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 Still not writing :-\ Quote Link to comment Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 $query1="insert into member (name,`password`,email) values ('".$_POST['name']."','".$_POST['password']."','".$_POST['email']."')"; Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 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: </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(); ?> 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 - Quote Link to comment Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Look at my query. Note the spaces. Quote Link to comment Share on other sites More sharing options...
nucleardoctor Posted May 2, 2007 Author Share Posted May 2, 2007 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: </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(); ?> Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted May 3, 2007 Share Posted May 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.