Jump to content

updating form


chris_s_22

Recommended Posts

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

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

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

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.