Can any one tell me what I am missing?


#1

Can any one tell me what I am missing?

I enter the data it echos the data but it doesn’t update the data

I have checked the table is not mispelt and I don’t get any errors?

Below is the script

<?php // Retreiving Form Elements from Form $thisproject_name = addslashes($_REQUEST['thisproject_nameField']); $thisstreet = addslashes($_REQUEST['thisstreetField']); $thiscityOrTown = addslashes($_REQUEST['thiscityOrTownField']); $thiscounty = addslashes($_REQUEST['thiscountyField']); $thiscountry = addslashes($_REQUEST['thiscountryField']); $thispCode = addslashes($_REQUEST['thispCodeField']); $thisdescription = addslashes($_REQUEST['thisdescriptionField']); $thisvalue = addslashes($_REQUEST['thisvalueField']); $thisprojectDate = addslashes($_REQUEST['thisprojectDateField']); $thisclient = addslashes($_REQUEST['thisclientField']); $thisstructEng = addslashes($_REQUEST['thisstructEngField']); $thismContractor = addslashes($_REQUEST['thismContractorField']); $thisprojectType = addslashes($_REQUEST['thisprojectTypeField']); $thisdiv_ID = addslashes($_REQUEST['thisdiv_IDField']); $thiskeywords = addslashes($_REQUEST['thiskeywordsField']); $sqlQuery = "INSERT INTO project_details (project_name , street , CityOrTown , county , country , pCode , description , value , client , structEng , mContractor , projectType , div_ID, keywords ) VALUES ('$thisproject_id' , '$thisproject_name' , '$thisstreet' , '$thiscityOrTown' , '$thiscounty' , '$thiscountry' , '$thispCode' , '$thisdescription' , '$thisvalue' , '$thisclient' , '$thisstructEng' , '$thismContractor' , '$thisprojectType' , '$thisdiv_ID' ,'$thiskeywords' )"; $result = MYSQL_QUERY($sqlQuery); ?>

#2

First thing you’re missing is [php] tags:

[php]

<?php // Retreiving Form Elements from Form $thisproject_name = addslashes($_REQUEST['thisproject_nameField']); $thisstreet = addslashes($_REQUEST['thisstreetField']); $thiscityOrTown = addslashes($_REQUEST['thiscityOrTownField']); $thiscounty = addslashes($_REQUEST['thiscountyField']); $thiscountry = addslashes($_REQUEST['thiscountryField']); $thispCode = addslashes($_REQUEST['thispCodeField']); $thisdescription = addslashes($_REQUEST['thisdescriptionField']); $thisvalue = addslashes($_REQUEST['thisvalueField']); $thisprojectDate = addslashes($_REQUEST['thisprojectDateField']); $thisclient = addslashes($_REQUEST['thisclientField']); $thisstructEng = addslashes($_REQUEST['thisstructEngField']); $thismContractor = addslashes($_REQUEST['thismContractorField']); $thisprojectType = addslashes($_REQUEST['thisprojectTypeField']); $thisdiv_ID = addslashes($_REQUEST['thisdiv_IDField']); $thiskeywords = addslashes($_REQUEST['thiskeywordsField']); $sqlQuery = "INSERT INTO project_details (project_name , street , CityOrTown , county , country , pCode , description , value , client , structEng , mContractor , projectType , div_ID, keywords ) VALUES ('$thisproject_id' , '$thisproject_name' , '$thisstreet' , '$thiscityOrTown' , '$thiscounty' , '$thiscountry' , '$thispCode' , '$thisdescription' , '$thisvalue' , '$thisclient' , '$thisstructEng' , '$thismContractor' , '$thisprojectType' , '$thisdiv_ID' ,'$thiskeywords' )"; $result = MYSQL_QUERY($sqlQuery); ?>

[/php]

Second thing you’re doing wrong consistently is ‘use the right tool for the right job’. Learn about what addslashes() should be used for, and why mysql_real_escape_string() is a better choice for this application. Learn about why $_REQUEST should never be used for user input, and which tools ($_GET, $_POST, $_COOKIE) are better suited for such means. Learn about Control Structures and Arrays and how to use them to prevent having to type up repetitive statements. Also, most (if not all) PHP functions are lowercase.

All in all, refactoring your script comes down to this:

[php]

<?php // Fixing form variables and table field names in arrays $formVars = array( "thisproject_nameField", "thisstreetField", "thiscityOrTownField", "thiscountyField", "thiscountryField", "thispCodeField", "thisdescriptionField", "thisvalueField", "thisprojectDateField", "thisclientField", "thisstructEngField", "thismContractorField", "thisprojectTypeField", "thisdiv_IDField", "thiskeywordsField" ); $tableNames = array( "project_name", "street", "CityOrTown", "county", "country", "pCode", "description", "value", "client", "structEng", "mContractor", "projectType", "div_ID", "keywords", ); // Retreiving Form Elements from Form and escaping them for ($i = 0; $i < count($formVars); $i++) { ${$formVars[$i]} = mysql_real_escape_string($_POST[$formVars[$i]]); } // Inserting values into the MySQL table $sqlQuery = "INSERT INTO project_details ("; for ($i = 0; $i < count($tableNames); $i++) { if ($i > 0) { $sqlQuery .= ", "; } $sqlQuery .= $tableNames[$i]; } $sqlQuery .= ") VALUES ("; for ($i = 0; $i < count($tableNames); $i++) { if ($i > 0) { $sqlQuery .= ", "; } $sqlQuery .= "'".$formVars[$i]."'"; } $sqlQuery .= ")"; $result = mysql_query($sqlQuery); ?>

[/php]

And after doing some 2nd grade counting ;) I can tell that there’s one field too many in the form variables, namely ‘thisprojectDateField’. Other than that, this should give you a MySQL error. Try mysql_error() or error_reporting(E_ALL) to display errors. I’m sure either of these would have picked up the problem.