@Large Posted October 22, 2007 Share Posted October 22, 2007 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\">" ?> Quote Link to comment https://forums.phpfreaks.com/topic/74338-htmlphpmysql-form-update-blanks-out-database-entry/ Share on other sites More sharing options...
@Large Posted October 22, 2007 Author Share Posted October 22, 2007 or is there some exception that i can for before writing to the database? hmmm. thanks - @LG Quote Link to comment https://forums.phpfreaks.com/topic/74338-htmlphpmysql-form-update-blanks-out-database-entry/#findComment-375636 Share on other sites More sharing options...
pocobueno1388 Posted October 22, 2007 Share Posted October 22, 2007 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74338-htmlphpmysql-form-update-blanks-out-database-entry/#findComment-375640 Share on other sites More sharing options...
@Large Posted October 22, 2007 Author Share Posted October 22, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74338-htmlphpmysql-form-update-blanks-out-database-entry/#findComment-375649 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.