Jump to content

HTML/PHP/mySql form UPDATE blanks out database entry...


@Large

Recommended Posts

hola from peru --

 

i'm currently volunteering down here in south america, working on a database of non-profit NGOS in the town of trujillo, la libertad, peru.

 

i am building an online database using a HTML/PHP/ front end and a MySql back end. i have limited expererience with PHP but i am having fun learning... :)

 

i am scratching my head with a problem involved with allowing the users to edit a previously existing entry in the database. every so often when the user retrieves an entry and submits it all the fields are set to blank ("") on submit! que malo!

 

of course, the main difficulty is that the results are only semi-reproducible, and i have yet to figure out under what conditions exactly this is happening. of course, the main reason i am scratching my head is because it's not that complicated of an operation: load form, edit, update. what could possibly go awry?

 

yet something does. about 1 in 5 to 1 in 10 times the fields are blanked out... such that when i go and look in the database at the edited entry... it's there, but all the fields have been wiped out, thus trashing a lot of work in entering the form.

 

i am using:

 

php api : 20020918

php extension: 20020429

 

here is the offending code (called after an html form submit):

 

 

<?
include("dbinfo.gen.inc.php");
mysql_connect(localhost,$username,$password);

$get_id = $_GET['id'];


$query = "UPDATE orgs_general SET categorio = '$categorio', nombre = '$nombre', rep = '$rep', rlcargo = '$rlcargo', dir = '$dir', ciudad = '$ciudad', contacto = '$contacto', ccargo = '$ccargo', tel1 = '$tel1', tel2 = '$tel2', tel3 = '$tel3', fax = '$fax', email1 = '$email1', email2 = '$email2', email3 = '$email3', pagweb = '$pagweb', geograficos = '$geograficos', accion = '$accion', proyectos = '$proyectos', notas = '$notas' WHERE id='$get_id'";


$db = @mysql_select_db($database);
$sql = mysql_query($query);
mysql_close();


echo "<META HTTP-EQUIV=\"refresh\" content=\"0;URL=ver.php\">"

?>

 

 

 

 

 

 

Link to comment
Share on other sites

You have all these variables in your query that I don't see defined before you use them. I bet you they are all null causing it to insert a blank value.

 

To retrieve a variable from a form using POST, you would do this assuming you have an input named "categorio".

$categorio = $_POST['categorio'];

 

Have you tried to echo your query?

<?php 

$query = "UPDATE orgs_general SET categorio = '$categorio', nombre = '$nombre', rep = '$rep', rlcargo = '$rlcargo', dir = '$dir', ciudad = '$ciudad', contacto = '$contacto', ccargo = '$ccargo', tel1 = '$tel1', tel2 = '$tel2', tel3 = '$tel3', fax = '$fax', email1 = '$email1', email2 = '$email2', email3 = '$email3', pagweb = '$pagweb', geograficos = '$geograficos', accion = '$accion', proyectos = '$proyectos', notas = '$notas' WHERE id='$get_id'";

echo $query;

?>

 

 

 

Link to comment
Share on other sites

 

 

 

You have all these variables in your query that I don't see defined before you use them. I bet you they are all null causing it to insert a blank value.

 

To retrieve a variable from a form using POST, you would do this assuming you have an input named "categorio".

$categorio = $_POST['categorio'];

 

 

thanks for your help. this makes sense, except that the update query works MOST of the time. which to me says that most of the time it does know the values of those fields, and some times it doesn't. is there something that could be happening to wipe those fields out?

 

in either case, i will go ahead and use $_POST and see if that effects it.

 

Have you tried to echo your query?

 

i have, and most of the time it's filled in correctly. except for when it's not and it nulls all the fields in the entry. :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.