Page 1 of 1

can't find problem

Posted: Mon Apr 30, 2007 2:14 pm
by NuclearDoctor
I can't get my code to attach to the database, can't someone help me?

Code: Select all

<?

include "connect.phtml";
$db=delranfire_org;
if(isset($_POST['select'])){ 

  $query1="insert into members(flname,pass,email)values('$select','$flname','$pass','$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 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="2">First & Last Name:&nbsp</font></b></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="flname" 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="2">Password:&nbsp</font></b></font></div>
      </td>
      <td width="51%" valign="middle">
        &nbsp<INPUT TYPE="text" NAME="pass" SIZE="30"></INPUT>	
      </td>
    </tr>
    <tr>
      <td width="47%" align="center" valign="middle">
        <div align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><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>
</body></html>
  <?
  mysql_close();
  ?>

Posted: Mon Apr 30, 2007 2:22 pm
by arturm
Do you have connection to the database?
Show us your connect.phtml

and you have an error in your query
number of arguments (flname,pass,email) don't match the values ('$select','$flname','$pass','$email')

and if you have register globals off you should use $_POST['select'] instead of $select

Posted: Mon Apr 30, 2007 2:48 pm
by RobertGonzalez
Specifically, show the code that connects to the database (you can leave out the credentials if you please). Also, are you error checking anywhere in the code? And thislittle guy here:

Code: Select all

<?php $db=delranfire_org;  ?>
will cause you some issues if delranfire_org is not a constant.

Posted: Mon Apr 30, 2007 3:42 pm
by NuclearDoctor
I know the connect.phtml works because I have my other thing, like my duty crews and all of that connecting to the connect.phtml and that works fine, but anyhow, the code is below:

Code: Select all

<?
 $connection=mysql_connect("localhost","***","***")
  or die ("couldnot connect to server");
$db="delranfire_org";
$latest_table="latestphoto"
?>

But I think I might have set the MySQL database up wrong, I did the following:
Field - ID
Type - int(10)
Attributes - UNSIGNED
Null - No
Default - *Blank*
Extra - auto_increment

---

Field - flname
Type - varchar(55)
Attributes - *Blank*
Null - Yes
Default - NULL
Extra - *Blank*

---

Field - pass
Type - varchar(70)
Attributes - *Blank*
Null - Yes
Default - NULL
Extra - *Blank*

---

Field - email
Type - varchar(100)
Attributes - *Blank*
Null - Yes
Default - NULL
Extra - *Blank*

Posted: Mon Apr 30, 2007 3:43 pm
by NuclearDoctor
Everah wrote:Specifically, show the code that connects to the database (you can leave out the credentials if you please). Also, are you error checking anywhere in the code? And thislittle guy here:

Code: Select all

<?php $db=delranfire_org;  ?>
will cause you some issues if delranfire_org is not a constant.
What do you mean not a constant?

Posted: Mon Apr 30, 2007 4:05 pm
by RobertGonzalez
In your first example, that string is not wrapped in quotes. PHP will attempt to locate a constant by that name, and if it cannot find it, it will throw a notice/warning for using an undefined constant/variable.

As for the database issue, you are using a deprecated function. You should be using mysql_select_db() and mysql_query(). I am sure this is not the cause of your problem, but since your original post stated that you could not attach to the database and the last post said that your database connection works because other parts of the app are working, I am assuming that your problem is corrected. Unless I am misunderstanding your problem.

Posted: Mon Apr 30, 2007 4:08 pm
by NuclearDoctor
Nope, my problem isn't fixed, for some reason, it wont connect to the database and export the settings I put in to the database. So all I have to do is wrap the string in quotes?

Edit: Nope, I just put it in quotes, and that didn't work.. I can't figure out this thing lol

Posted: Mon Apr 30, 2007 4:12 pm
by RobertGonzalez

Code: Select all

<?php if(isset($_POST['select'])){ ?>
I didn't see this field in the form anywhere. Maybe the fact that this is not set is causing the conditional to fail, hence the lack of execution of the query.

Posted: Mon Apr 30, 2007 4:42 pm
by NuclearDoctor
So can I just remove that whole line or should I add in $select

Posted: Mon Apr 30, 2007 4:44 pm
by RobertGonzalez
It would seem obvious from the code that the select was needed for something. Where did it go? Why is it not there? Why does the query need to be triggered? Answer these questions and you can answer the question you just asked.

Posted: Mon Apr 30, 2007 4:45 pm
by volka
mysql_db_query is deprecated, use mysql_select_db and mysql_query instead.
$query1="insert into members(flname,pass,email)values('$select','$flname','$pass','$email')";
this might work with register_globals=On, otherwise you have to use $_POST['select']. $_POST['flname'], ...

try

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('mysql.trace_mode', true);
?>
<html>
  <head>
    <title><?php require "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">
<?php
require "connect.phtml";
$db='delranfire_org';
if( !isset($_POST['Submit']) ) {
  echo '<div>Debug: _POST[Submit] not set</div>';
}
else if ( !isset($_POST['select'], $_POST['flname'], $_POST['pass'], $_POST['email']) ) {
  echo '<div>Missing parameter</div>';
}
else {
  $select = mysql_real_escape_string($_POST['select'], $connection) or die(mysql_error());
  $flname = mysql_real_escape_string($_POST['flname'], $connection) or die(mysql_error());
  $pass = mysql_real_escape_string($_POST['pass'], $connection) or die(mysql_error());
  $email = mysql_real_escape_string($_POST['email'], $connection) or die(mysql_error());
  $query1="INSERT INTO
      members
      (flname,pass,email)
    VALUES
      ('$select','$flname','$pass','$email')
    ";
  mysql_select_db($db, $connection) or die(mysql_error());
  mysql_query($query1,$connection) or die("Error in query:$query. " .mysql_error());
}
?>
    <form action="addmember.phtml" method="post">

Posted: Mon Apr 30, 2007 4:59 pm
by RobertGonzalez
As of his last post, there was not $_POST['select'] which is what I think may have been causing his problem as he was using that posted field for his query trigger.

Posted: Mon Apr 30, 2007 5:01 pm
by volka
Yes, I've silently integrated that solution ;)

Code: Select all

if( !isset($_POST['Submit']) ) {

Posted: Mon Apr 30, 2007 5:02 pm
by RobertGonzalez
Doh Image

I need to read better.