Jump to content

script won't update database


phpnewbie1979

Recommended Posts

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("'", "&#39;", $var);
    $var = eregi_replace("`", "&#39;", $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

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 :P.

 

-CB-

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.