Jump to content

[SOLVED] updating database


chris_s_22

Recommended Posts

ok i have already created a form that sucessfully inserts data into my database

im now creating a seperate form to update the data.

i dont see any problems with my editform.php and it all seems fine.

The edit.php seems to be working fine and throws back the error message as it should. 

when i do change data in form i get the message

hello1updated

when i check my database nothing has changed can anyone point out what im doing wrong

 

here is my form it has 13 feilds as you can see itgets previous stored data then display it in the value

<?php 
include_once 'Connect.php';

if (!is_authed()) 
{
     die ('You are not permitted to view this page, <a href="index.php">click here</a> to go back.');
}
$thequery = ("SELECT * FROM users WHERE username = '$username' ");
$query = mysql_query($thequery) or die ('session data dont match.');
while ($row = mysql_fetch_assoc($query)) 
{
$q1 = $row["feild1"];
$q2 = $row["feild2"];
$q3 = $row["feild3"];	       
$q4 = $row["feild4"];
$q5 = $row["feild5"]; 
$q6 = $row["feild6"];
$q7 = $row["feild7"];
$q8 = $row["feild8"];
$q9 = $row["feild9"];
$q10 = $row["feild10"];
$q11 = $row["feild11"];
$q12 = $row["feild12"];
$q13 = $row["feild13"];
}
?>
<html><head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class=logo><?php include "logo.php";?></div>
<div class=navigationbarbox><?php include "navigationbar.php";?></div>
<div class=editform>
<?php if (isset($feild1_error)) {?>There was an error: <?php echo $feild1_error; ?> please try again.<?php } ?>
<?php if (isset($feild2_error)) {?>There was an error: <?php echo $feild2_error; ?> please try again.<?php } ?>
<?php if (isset($feild3_error)) {?>There was an error: <?php echo $feild3_error; ?> please try again.<?php } ?>
<?php if (isset($feild4_error)) {?>There was an error: <?php echo $feild4_error; ?> please try again.<?php } ?>
<?php if (isset($feild5_error)) {?>There was an error: <?php echo $feild5_error; ?> please try again.<?php } ?>
<?php if (isset($feild6_error)) {?>There was an error: <?php echo $feild6_error; ?> please try again.<?php } ?>
<?php if (isset($feild7_error)) {?>There was an error: <?php echo $feild7_error; ?> please try again.<?php } ?>
<?php if (isset($feild8_error)) {?>There was an error: <?php echo $feild8_error; ?> please try again.<?php } ?>
<?php if (isset($feild9_error)) {?>There was an error: <?php echo $feild9_error; ?> please try again.<?php } ?>
<?php if (isset($feild10_error)) {?>There was an error: <?php echo $feild10_error; ?> please try again.<?php } ?>
<?php if (isset($feild11_error)) {?>There was an error: <?php echo $feild11_error; ?> please try again.<?php } ?>
<?php if (isset($feild12_error)) {?>There was an error: <?php echo $feild12_error; ?> please try again.<?php } ?>
<?php if (isset($feild13_error)) {?>There was an error: <?php echo $feild13_error; ?> please try again.<?php } ?>
<form action="edit.php" method="POST" name="editprofile">
feild1
<select name="feild1">
<OPTION selected value="<?php echo $q1?>"><?php echo $q1?></OPTION>
<option value=""></option>
<option value="option1">option1</option>
<option value="option2">option2</option>
<option value="option3">prefer not to say</option>
</select><br>
feild2<input type="text" size="20" maxlength="20" name="feild2" value="<?php echo $q2?>" align="" tabindex=""><br>
feild3<input type="text" size="20" maxlength="20" name="feild3" value="<?php echo $q3?>" align="" tabindex=""><br>
feild4<input type="text" size="20" maxlength="20" name="feild4" value="<?php echo $q4?>" align="" tabindex=""><br>
feild5<input type="text" size="20" maxlength="20" name="feild5" value="<?php echo $q5?>" align="" tabindex=""><br>
feild6<input type="text" size="20" maxlength="20" name="feild6" value="<?php echo $q6?>" align="" tabindex=""><br>
feild7<input type="text" size="20" maxlength="20" name="feild7" value="<?php echo $q7?>" align="" tabindex=""><br>
feild8<input type="text" size="20" maxlength="20" name="feild8" value="<?php echo $q8?>" align="" tabindex=""><br>
feild9<input type="text" size="20" maxlength="20" name="feild9" value="<?php echo $q9?>" align="" tabindex=""><br>
feild10<input type="text" size="20" maxlength="20" name="feild10" value="<?php echo $q10?>" align="" tabindex=""><br>
feild11<input type="text" size="20" maxlength="20" name="feild11" value="<?php echo $q11?>" align="" tabindex=""><br>
feild12<input type="text" size="20" maxlength="20" name="feild12" value="<?php echo $q12?>" align="" tabindex=""><br>
feild13<input type="text" size="20" maxlength="20" name="feild13" value="<?php echo $q13?>" align="" tabindex=""><br>
<input type="submit" value="EDIT" name="submit" tabindex="">
</form>
</div>
<div class=footerbox><?php include "footer.php";?></div>
</body></html>

 

 

this is edit.php just does checks on the data input then calls for form_edit function

<?php
include 'Connect.php';

if(!isset($_POST[submit]))   
{
   	 include 'editform.php';
   	 exit;
}
else
{
if(!preg_match("/^[\d]{1,2}$/", $_POST[feild1]))
{  
	// Reshow the form with an error
    	$feild1_error = "1";
	include 'editform.php';
    	exit;
}	  
if(!preg_match("/^[\d]{1,2}$/i", $_POST[feild2]))
{  
	// Reshow the form with an error
    	$feild2_error = "2";
	include 'editform.php';
    	exit;  
}
//CHECKS dobyear
if(!preg_match("/^[\d]{4}$/", $_POST[feild3]))
{  
	// Reshow the form with an error
    	$feild3_error = "3";
	include 'editform.php';
    	exit;  
}
//CHECKS sexuality
if(!preg_match("/^[a-z ]{0,8}$/i", $_POST[feild4]))
{  
	// Reshow the form with an error
    	$feild4_error = "4";
	include 'editform.php';
    	exit;  
}	
//CHECKS relationshipstatus
if(!preg_match("/^[a-z ]{0,20}$/i", $_POST[feild5]))
{  
	// Reshow the form with an error
    	$feild5_error = "5";
	include 'editform.php';
    	exit;  
}
//CHECKS location
if(!preg_match("/^[a-z ]{0,20}$/i", $_POST[feild6]))
{  
	// Reshow the form with an error
    	$feild6_error = "6";
	include 'editform.php';
    	exit;  
}	
//CHECKS gender
if(!preg_match("/^[a-z ]{0,6}$/i", $_POST[feild7]))
{  
	// Reshow the form with an error
    	$feild7_error = "7";
	include 'editform.php';
    	exit;  
}	
//CHECKS lookingfor
if(!preg_match("/^[a-z ]{0,10}$/i", $_POST[feild8]))
{  
	// Reshow the form with an error
    	$feild8_error = "8<br />";
	include 'editform.php';
    	exit;  
}	
//CHECKS favouritemusic
if(!preg_match("/^[a-z ,.]{0,50}$/i", $_POST[feild9]))
{  
	// Reshow the form with an error
    	$feild9_error = "9";
	include 'editform.php';
    	exit;  
}	
//CHECKS favouritetv
if(!preg_match("/^[a-z ,.]{0,50}$/i", $_POST[feild10]))
{  
	// Reshow the form with an error
    	$feild10_error = "10";
	include 'editform.php';
    	exit;  
}	
//CHECKS favouritefilms
if(!preg_match("/^[a-z\d ,.]{0,50}$/i", $_POST[feild11]))
{  
	// Reshow the form with an error
    	$feild11_error = "11";
	include 'editform.php';
    	exit;  
}	
//CHECKS favouritequotations
if(!preg_match("/^[a-z\d ,.]{0,25}$/i", $_POST[feild12]))
{  
	// Reshow the form with an error
    	$feild12_error = "12";
	include 'editform.php';
    	exit;  
}	
//CHECKS aboutme
if(!preg_match("/^[a-z\d ,.]{0,200}$/i", $_POST[feild13]))
{  
    	$feild13_error = "13";
	include 'editform.php';
    	exit;  
}	

// Everything is ok, register
    form_edit ($_POST['feild1'], $_POST['feild2'], $_POST['feild3'], $_POST['feild4'], $_POST['feild5'], $_POST['feild6'], $_POST['feild7'], $_POST['feild8'], $_POST['feild9'], $_POST['feild10'], $_POST['feild11'], $_POST['feild12'], $_POST['feild13']);
echo "updated";
}
?>

 

this is the function


function form_edit($feild1, $feild2, $feild3, $feild4, $feild5, $feild6, $feild7, $feild8, $feild9, $feild10, $feild11, $feild12, $feild13)
{                   
$one = $feild1.$feild2.$feild3;
// And lastly, store the information in the database
$query = ("UPDATE users SET feild1='$feild1, feild2='$feild2, feild3='$feild3, one='$dob', feild4='$feild4, feild5='$feild5, feild6='$feild6, feild7='$feild7, feild8='$feild8, feild9='$feild9, feild10='$feild10, feild11='$feild11, feild12='$feild12, feild13='$feild13 WHERE username = '$username'");
    $result = mysql_query ($query) or die ('Could not edit user.');
if($result)
{	
echo"hello1";
}
else
{
echo"hello2";
}
}

 

i must add that that in connect.php i do start a session and this does a include to function.php i also stored session data in my login function

Link to comment
https://forums.phpfreaks.com/topic/181554-solved-updating-database/
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.