Jump to content

updating database by form


bhavin_85

Recommended Posts

hi guys

 

ive had a quick search and couldnt find anything specific to what i wanna dp

 

When a user clicks on their account page it should show all their account details...it already does it...but when they click the edit button i want the data to be put into a form format so that the user can update the details then click save...any ideas how to do it? is it better to have an edit page aswell or is there a way that i can make the page turn into a form?

 

hope that makes sense lol

 

thanks 4 the advice

 

Bhav

Link to comment
https://forums.phpfreaks.com/topic/40768-updating-database-by-form/
Share on other sites

personally i would have a statment like

 

have some hidden fields for userid etc

 

<?php

if(isset($_GET['Action']))
{
if($_GET['Action'] == "Edit")
{
//form page for editing

return;
}
if($_GET['Action'] == "save")
{
//save submitted info 
}
//display normal
}

?>

the code that you are suggesting would mean that the data is showin in a form regardless of if the edit button is pressed or not....would be it be possible to do it the other way i suggested where by it displays the data in a table format them when the edit button is clicked a form appears?

 

or am i totally misinterpriting your code?

hey guys

ive had a crack at attempting that suggested code but it didnt work...when i put the form code into the <?php ?> section i just got parse errors

 

so i tried to change the code just so it would print text when the edit button is pushed but still doesnt work

 

any ideas?

 

<?
session_start();
if ( empty($_SESSION['username'])){
header("location:default.php");
exit;
}

if(isset($_GET['Action']))
{
if($_GET['Action'] == "Submit")
{
//<form>
//<input name="edit" type="Edit"></input>
//</form>
echo "data to be edit";
return;
}
if($_GET['Action'] == "save")
{
echo "data saved";
}
}

$id=$_SESSION['cust_id'];

include('config.php');

$sql="SELECT * FROM customer WHERE cust_id='$id'";
$query=mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($query) != 0) { 
$row = mysql_fetch_assoc($query);
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['surname'] = $row['surname'];
$_SESSION['address1'] = $row['address1'];
$_SESSION['address2'] = $row['address2'];
$_SESSION['town'] = $row['town'];
$_SESSION['county'] = $row['county'];
$_SESSION['postcode'] = $row['postcode'];
$_SESSION['date_of_birth'] = $row['date_of_birth'];
$_SESSION['home_number'] = $row['home_number'];
$_SESSION['mobile_number'] = $row['mobile_number'];
$_SESSION['points'] = $row['points'];
}
?>
<html>
<head>
<title>P.B.L. Jewellers Ltd</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#030102" text="#666666">
<div>
<table width="670" height="546" border="0" align="center" bordercolor="#000000">
  <tr>
      <td colspan="2" align="right" height="10">
        <? 
  echo "You are logged in as " . $_SESSION['uname'] . ""?>
        <a href="default.php">Logout</a> </td>
  </tr>
  <tr> 
    <td colspan="3" valign="top" width="670" height="158"> <img src="images/banner2.png" width="670" height="158" align="top"> 
    </td>
  </tr>
  <tr>
  <td colspan="3" align="center" height="20"><? readfile("menu_account.inc"); ?>
  </td>
  </tr>
<tr>
     <td><br><? echo "Hello " . $_SESSION['first_name'] . "" ?></td>
</tr>
<tr>
<td>
<form>
<input name="Edit" type="submit"">
</form>
</td></tr>
    <tr> 
      <td colspan="2"><p> </p>
        Personal Information <br>
<? 
echo "Name: " . $_SESSION['first_name'] . " " . $_SESSION['surname'] . "<br>";
echo "Address: " . $_SESSION['address1'] . ", " . $_SESSION['address2'] . "<br>";
echo "Town: " . $_SESSION['town'] . "<br>";
echo "County: " . $_SESSION['county'] . "<br>";
echo "Postcode: " . $_SESSION['postcode'] . "<br>";
echo "Status: " . $_SESSION['status'] . "<br>";
echo "Telephone Number: 0" . $_SESSION['home_number'] . "<br>";
?>
        </p></td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</div>
</body>
</html>

ridiculous. you've never send the action through get. Here's a quick example:

 

Create page.php with this form in it:

 

<form name="form1" method="post" action="page2.php">
        <table width="100%" height="30%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="202" height="50%"> </td>
            <td width="28" height="50%"> </td>
            <td colspan="2"> </td>
          </tr>
          <tr>
            <td height="40"><div align="right"><span class="style1">Field you want to edit </span></div></td>
            <td width="28" height="40"> </td>
            <td height="40" colspan="2"><input name="field" type="text" id="songtitle" size="20" /></td>
          </tr>
          <tr>
            <td height="53"> </td>
            <td width="28" height="53"> </td>
            <td width="83" height="53"> </td>
            <td width="157"><div align="left">
              <input type="submit" name="Submit" value="Edit" />
            </div></td>
          </tr>
        </table>
        </form>

 

Create page2.php with this query on it (make sure your connected to database):

 

$sql = "UPDATE [b]TABLE [/b]SET [b]FIELDNAME [/b]= '[b]".$_POST['field']."[/b]' WHERE [b]FIELD [/b]= '[b]SOMETHING TO DEFINE ROW[/b]' LIMIT 1";
mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); 

 

Not tested but should work.

 

Snooble

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.