Ok, heres an odd situation.

I've been using a code for a few years to basically add edit, and delte content from my site.

I have taken this bit of code and once again am using it to add some content. ARGH! I can't figure this out for the life of me! The data I am trying to write won't insert into my database. I've checked everything three times and it looks good.

I have also checked my old scripts to see if the mysql or php was upgraded into incompatibility and those old scripts seem to work.

Ok here goes the code:

<?
// This file is used for administraton of the Estimate Request pages.
        $dbhost = "localhost";
        //      MySQL server username
        $dbuser = "reliable_om1";
        //      MySQL server password
        $dbpasswd = "removed for security";
        //      MySQL server connect
        $db=mysql_connect("$dbhost","$dbuser","$dbpasswd");
        //      MySQL database name
        $db_name="reliable_relamedata";
        mysql_select_db($db_name,$db);
	   $table="estimate_requests";

       $query = "SELECT * FROM $table WHERE firstName='$firstName' ";
       $result = mysql_query($query);
       $nombre = mysql_numrows($result);
//_________________________ADD__________________________
       if ($action=='add'  and  $nombre == 0 )        {
       $query="INSERT INTO $table ('firstName', 'lastName', 'orginization', 'jobAddress', 'jobCity', 'jobState', 'jobZip', 'mailAddress', 'mailCity', 'mailState', 'mailZip', 'dayPhone', 'evePhone', 'cellPhone', 'faxNo', 'eMail', 'workType', 'estimateDesc', 'referrer') VALUES ('$firstName', '$lastName','$orginization', '$jobAddress', '$jobCity','$jobState', '$jobZip','$mailAddress', '$mailCity','$mailState', '$mailZip', '$ dayPhone', '$evePhone', '$cellPhone', '$faxNo', '$eMail', '$workType', '$estimateDesc', '$referrer')";
       $result=mysql_query($query);
	   
       echo "The entry  $firstName  $lastName was added to the Lead Bank.<br>" ;
	   echo "<a href=\"open_estimates.php\">View Open Estimates.</a> 
	   		 <a href=\"index.php\">Return to Employee Home Page.</a> <br>" ;
       mysql_close();
       exit;
       }
       elseif ($action=='add'  and  $nombre != 0) {
       echo "No Addition, the entry <b>$id</b> exist in the glossary" ;
       mysql_close();
       exit ;
         }
//more code removed for convenience 
?>

The interface used is found at: http://relamedata.reliableamerican.us/UnnamedSite/new_estimate.php upon submission of the form it appears as if the data is added, but no data is added to the database when I check through phpMyAdmin

The file with the above code is found at: http://relamedata.reliableamerican.us/UnnamedSite/estimate_request_engine.php

Find:

$nombre = mysql_numrows($result);

Replace with

$nombre = mysql_num_rows($result);

Hope this helps.

Hmmm LOL it's always something stupid like that. I'll look into it and post back this evening when I have time.

Thanks!

you should always use error checking, because not always will the error pop up, sometimes you need to add the line

or die (mysql_error());
$nombre = mysql_num_rows($result) or die (mysql_error());

this will output any errors from the query, with this, you can properly find any problems going on with your mysql queries, i find it a good idea, that every few lines, when doing queries, to add a or die (mysql_error());

I tried both suggestions. No luck, no error message and still not working.

I tried both suggestions. No luck, no error message and still not working.

have you tried adding it to all lines, somthing is obviously being parsed wrong within the mysql itself and not the php.

Maybe you didn't post all your code.... But I don't see where you have retrieved your variables from $_POST. You will either need to assign them at the top of the script like this:

$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
etc....

or use the $_POST variables in your query:

$query="INSERT INTO $table ('firstName', 'lastName',.......) 
VALUES ('{$_POST['firstName']}', '{$_POST['$lastName']}',...)";

I prefer the first way so the query looks cleaner and has less syntax for me to screw up ;)

Killer So you are saying add "or die (mysql_error());" at the end of every line?

Dance I'll have to try what you are suggesting some time later today.

go with dance first as i believe he has it, in that your not retrieving anything from the previous page, but in it, you may want to end it to the end of all your mysql lines just to make sure that everything is being done that needs to be.

Ok since I really couldn;t figure out what dance was trying to tell me I decided to go with typo's suggestion.

Funny thing is now for some reason, the program looks for columns named after the fileds. Take a look at http://relamedata.reliableamerican.us/UnnamedSite/new_estimate.php Then just enter your name "Any Name" into the first name field. The error it now outputs is "Unknown column 'AnyName' in 'field list' " LOL at least now I know what the problem was. I was having syntax errors before. I fixed all of them and now I am at this point.

I can't understand why this program works fine for a glossary that contains name and definition, but add a few more fields and it's failing :(

Ok since I really couldn;t figure out what dance was trying to tell me I decided to go with typo's suggestion.

Funny thing is now for some reason, the program looks for columns named after the fileds. Take a look at http://relamedata.reliableamerican.us/UnnamedSite/new_estimate.php Then just enter your name "Any Name" into the first name field. The error it now outputs is "Unknown column 'AnyName' in 'field list' " LOL at least now I know what the problem was. I was having syntax errors before. I fixed all of them and now I am at this point.

I can't understand why this program works fine for a glossary that contains name and definition, but add a few more fields and it's failing :(

dances comment was that you are not retrieving any variables from the previous post, IE, there is no $usrname = %_POST[usrname]; with a form that uses the post feature to the current page...so its like this


FORM:A
usrname (enter username)
password (enter password)

SUBMIT (uses post feature with a direction to form B)

FORM:B
$username = $_POST[usrname]; //for retreiving the username
$password = $_POST[password]; //for retreiving the password


then using these variables you can submit to a database.

This article has been dead for over six months. Start a new discussion instead.