chris_s_22 Posted January 19, 2009 Share Posted January 19, 2009 ok well ive already created a registration form, what i am trying to do now is if people want to change there details to be able to, have i done the scripts ok? and also if a feild was to be left blank would it change the value in the database to blank or do i have to add code to tell it to ignore it? lastyly is there anything else i need to think about doing this update form? once my update form is filled out it send data to this page update.php <?php // Include init file this connects to database include 'init.php'; if (!isset($_POST['submit'])) { // Show the form include 'index.php'; exit; } else { // Everything is ok, update user_update ($_POST['feild1'], $_POST['feild2'], $_POST['feild3']); } ?> this is my functions.php page <?php function user_update($feild1, $feild2, $feild3) { // store the information in the database $query = "UPDATE into user (feild1, feild2, feild3) values ('$feild1, '$feild2', '$feild3')"; $result=mysql_query($query) or die(mysql_error()); // if suceesfully inserted data into database if($result) { header('Location: http://www.sitename/folder/conformation.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/141425-updating-form/ Share on other sites More sharing options...
heman007 Posted January 19, 2009 Share Posted January 19, 2009 Yes it would, so you may need some sort of condition to ignore empty field Link to comment https://forums.phpfreaks.com/topic/141425-updating-form/#findComment-740309 Share on other sites More sharing options...
chris_s_22 Posted January 19, 2009 Author Share Posted January 19, 2009 ok thx any help in what id have to put and where to achieve this is grately received Link to comment https://forums.phpfreaks.com/topic/141425-updating-form/#findComment-740483 Share on other sites More sharing options...
tqla Posted January 19, 2009 Share Posted January 19, 2009 Try this: <?php // Include init file this connects to database include 'init.php'; if (!isset($_POST['submit'])) { // Show the form include 'index.php'; exit; } if (isset($_POST['submit'])) { //check for empty fields if ($_POST['feild1'] == "" || $_POST['feild2'] == "" || $_POST['feild3'] == "") { // Show the form include 'index.php'; exit; } else { // Everything is ok, update user_update ($_POST['feild1'], $_POST['feild2'], $_POST['feild3']); } ?> Link to comment https://forums.phpfreaks.com/topic/141425-updating-form/#findComment-740608 Share on other sites More sharing options...
chris_s_22 Posted January 20, 2009 Author Share Posted January 20, 2009 thx tqla but wont your code stop the form from updating the feild that was fillied in? i want the form to simply ignore and not update empty feilds and if a feild is entered to change what is already in the database Link to comment https://forums.phpfreaks.com/topic/141425-updating-form/#findComment-741013 Share on other sites More sharing options...
haku Posted January 20, 2009 Share Posted January 20, 2009 The answers to your questions can be figured out in about 30 seconds by just trying out your script, and seeing what happens. Link to comment https://forums.phpfreaks.com/topic/141425-updating-form/#findComment-741016 Share on other sites More sharing options...
heman007 Posted January 20, 2009 Share Posted January 20, 2009 PLEAS TRY THIS, PLEASE CHECK FOR ERRORS, AS I JUST RUSHED TO PUT TOGETHER <?php // Include init file this connects to database include 'init.php'; if (!isset($_POST['submit'])) { // Show the form include 'index.php'; exit; } else { //CHECK IF FIELD IS PRESENT //NOTICE THAT, HAVE PUT A COMMER NEXT TO field1 and 1 //THIS IS BECAUSE IF THIS FIELD IS EMPTY //YOU MAY HAVE ERROR IN THE DATABASE CUS OF "," if(isset($_POST['feild1']){$array_field1 = array('0' => 'feild1,', '1' => $_POST['feild1'].','); } if(isset($_POST['feild2']){$array_field2 = array('0' => 'feild2,', '1' => $_POST['feild2'].','); } if(isset($_POST['feild3']){$array_field3 = array('0' => 'feild3', '1' => $_POST['feild3']); } // Everything is ok, update user_update ($array_field1, $array_field2, $array_field3); //PASS THE ARRAYS } ?> <?php function user_update($array_field1, $array_field2, $array_field3)// { // store the information in the database //THE ARRAYS ARE PASSED HERE $query = "UPDATE into user ($array_field1[0] $array_field2[0] $array_field3) values ($array_field1[1] $array_field2[0] $array_field3[0])"; $result=mysql_query($query) or die(mysql_error()); // if suceesfully inserted data into database if($result) { header('Location: http://www.sitename/folder/conformation.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/141425-updating-form/#findComment-741162 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.