Data not going into SQL
Posted: Tue Aug 02, 2005 4:40 am
I have got the following funcions:
And I got a form, this is the processing script:
I don't know why, but when the user hits submit, he/she gets returned to the same form page with all fields blank and nothing added to the databse, I just don't understand why. And yes, I have also user the HTTP_POST_VARS so the values can't be empty!
What have I done wrong ?
EDIT:
I have slightly modified my processing script:
Now I get my error message saying that the information couldn't be saved ? How can I find out what's causing the problem ?
Code: Select all
function filled_out($form_vars) {
foreach ($form_vars as $keys => $value) {
if (!isset($key) || ($value == ''))
return false;
}
return true;
}
function insert($city, $area, $street, $unit, $unitl, $incident, $property, $andiamos, $bbgs, $telxos, $obervations, $ip) {
$conn = db_connect();
if (!$conn)
require_once('header.html');
return '<div id="error">No se ha podido establecer una conexión a la base de datos. Por favor, inténtelo más tarde.</div>';
require_once('footer.html');
$result = mysql_query("INSERT INTO `informes` (`id`, `city`, `area`, `street`, `unit`, `unitl`, `incident`, `property`, `andiamos`, `bbgs`, `telxos`, `observations`, `ip`) VALUES ('', '$city', '$area', '$street', '$unit', '$unitl', '$incident', '$property', '$andiamos', '$bbgs', '$telxos', '$observations ', '$ip');");
if (!result)
require_once('header.html');
return '<div id="error">No se ha podido agregar la informaci&oacture;n a la base de datos.</div>';
require_once('footer.html');
return true;
}Code: Select all
require_once('includes/global.php');
$city = $HTTP_POST_VARS['city'];
$street = $HTTP_POST_VARS['street'];
$unit = $HTTP_POST_VARS['unit'];
$unitl = $HTTP_POST_VARS['unitl'];
$incident = $HTTP_POST_VARS['incident'];
$property = $HTTP_POST_VARS['property'];
$andiamos = $HTTP_POST_VARS['andiamos'];
$bbgs = $HTTP_POST_VARS['bbgs'];
$telxos = $HTTP_POST_VARS['telxos'];
$observations = $HTTP_POST_VARS['observations'];
$ip = $REMOTE_ADDR;
$area = '1'; /* Change this value! */
if (!filled_out($HTTP_POST_VARS)) {
require_once('header.html');
echo '<div class="error">No ha rellenado el formulario completamente, asegúrese de que este rellenado y después pulse agregar.</div>';
require_once('footer.html');
exit;
}
$insert_result = insert($city, $area, $street, $unit, $unitl, $incident, $property, $andiamos, $bbgs, $telxos, $obervations, $ip);
if ($insert_result = true) {
require_once('header.html');
echo '<div id="error">¡La información que ha enviado ha sido añadida a la base de datos con éxito!</div>';
echo '$insert_result';
require_once('footer.html');
}
else {
require_once('header.html');
echo '<div id="error">No se ha podido guardar la información a la base de datos. Por favor, inténtelo de nuevo.</div>';
echo '$insert_result';
require_once('footer.html');
exit;
}What have I done wrong ?
EDIT:
I have slightly modified my processing script:
Code: Select all
$insert_result = insert($city, $area, $street, $unit, $unitl, $incident, $property, $andiamos, $bbgs, $telxos, $obervations, $ip);
if ($insert_result === true) {
require_once('header.html');
echo '<div class="error">¡La información que ha enviado ha sido añadida a la base de datos con éxito!</div>';
require_once('footer.html');
}
else {
require_once('header.html');
echo '<div class="error">No se ha podido guardar la información a la base de datos. Por favor, inténtelo de nuevo.</div>';
require_once('footer.html');
exit;
}