phpnewbie1979 Posted January 28, 2010 Share Posted January 28, 2010 Hi everyone I am new to php and I'm having trouble inserting a new row into my database with the script below. I receive no errors message but when I look into the database the script did not insert the record. I changed the actual field names for security puproses but the field names only contain letters. Any help would be greatly appreciated <?php $fieldone = $_POST['fieldone']; $fieldtwo = $_POST['fieldtwo']; $fieldthree = $_POST['fieldthree']; $fieldfour = $_POST['fieldfour']; $fieldfive = $_POST['fieldfive']; $fieldsix = $_POST['fieldsix']; $fieldseven = $_POST['feildseven']; $fieldeight = $_POST['fieldeight']; $fieldnine = $_POST['fieldnine']; // Filter Function ------------------------------------------------------------------- function filterFunction ($var) { $var = nl2br(htmlspecialchars($var)); $var = eregi_replace("'", "'", $var); $var = eregi_replace("`", "'", $var); return $var; } $fieldone = filterFunction($fieldone); $fieldtwo = filterFunction($fieldtwo); $fieldthree = filterFunction($fieldthree); $fieldfour = filterFunction($fieldfour); $fieldfive = filterFunction($fieldfive); $fieldsix = filterFunction($fieldsix); $fieldseven = filterFunction($fieldseven); $fieldeight = filterFunction($fieldeight); $fieldnine = filterFunction($fieldnine); // End Filter Function -------------------------------------------------------------- include_once "../dbconnect.php"; // Add the info into the database table mysql_query("INSERT INTO table (fieldone, fieldtwo, fieldthree, fieldfour, fieldfive, fieldsix, fieldseven, fieldeight, fieldnine) VALUES('$fieldone', '$fieldtwo', '$fieldthree', '$fieldfour', '$fieldfive', '$fieldsix', '$fieldseven', '$fieldeight', '$fieldnine')"); echo 'successfully entered! <br /><br />Where would you like to go? You can<br /><a href=""</a><br /><a href="">View live data</a><br /><a href="">Return to homepage</a>'; exit(); ?> Link to comment https://forums.phpfreaks.com/topic/190120-script-wont-update-database/ Share on other sites More sharing options...
ChemicalBliss Posted January 28, 2010 Share Posted January 28, 2010 ok, first, save the whole query into a variable and Then use the variable in mysql_query(). Then you can echo the Query with executing the statement (to make sure its what you expect). Also you can add an "Or Die()" Clause to the end of your query function: $query = "INSERT INTO table (fieldone, fieldtwo, fieldthree, fieldfour, fieldfive, fieldsix, fieldseven, fieldeight, fieldnine) VALUES('$fieldone', '$fieldtwo', '$fieldthree', '$fieldfour', '$fieldfive', '$fieldsix', '$fieldseven', '$fieldeight', '$fieldnine')"; echo($query); mysql_query($query) or die(mysql_error()); try that . -CB- Link to comment https://forums.phpfreaks.com/topic/190120-script-wont-update-database/#findComment-1003123 Share on other sites More sharing options...
phpnewbie1979 Posted January 28, 2010 Author Share Posted January 28, 2010 Thank you very much. Saving the query in a variable helped me see what the problem was. One of my fields was named "desc" which is used for sorting in php. I changed the field name and everything worked fine. Thank you. Link to comment https://forums.phpfreaks.com/topic/190120-script-wont-update-database/#findComment-1003168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.