Page 1 of 1

Creating A Page To Edit Information And Update The Informati

Posted: Thu Apr 28, 2005 7:10 pm
by Arsenal Rule
I recently (with some help from some good guys) created a page which displays the data in my sql database, in table form. I then designed it so that when you click on the users name in the table it will go to a view.php page, which shows further details of the user in question.

this is the code once we've gone into the view.php:

Code: Select all

<?php
			if(isset($_REQUEST['id']))
			{
			$user_id = $_REQUEST['id'];
			
			$conn = mysql_connect("localhost","root","") or die("Could Not 

Connect To The Database"); 
		mysql_select_db("aziz",$conn) or die("Could Not Select The Database"); 
			
			//sql query somethinglike
			
			$sql = "SELECT * FROM azizpassword WHERE user_id = '".$user_id."'"; 
			$result = mysql_query($sql); 
			$row = mysql_fetch_assoc($result); 
			
		echo "<h1>"."Name:" . " " . $row['az_firstname'] . " " . $row['az_surname'] 

. "</h1>"; 
		echo "<h4>"."Username:" . " " . $row['username'] . " " . "</h4>";
		echo "<h4>"."User ID:" . " " . $row['user_id'] . " " . "</h4>";
		echo "<h4>"."Password:"." " . $row['password']. "</h4>";
		echo '<br> ';
		echo '<br> ';
		if (isset($HTTP_REFERER)) {echo "<a href='$HTTP_REFERER'>BACK</a>"; } 
		else {echo "<a href='javascript:history.back()'>BACK</a>"; 
		}
			  
			
			}
			?>
What I need to do is to do is allow the information shown on view.php of the selected username to be allowed to be edited and then allowed to be updated on it's correct place on the database. Making sure that the data updated is the data chosen and shown on view.php.So I was wondering if anyone had any ways or suggestions in which to bring the data shown back in text boxes, so that i can update the table by typing, deleting and modifying, basically editing the information and then there will be a submit button which then clicking on the submit button it will update the information about that chosen user only on my sql database.

I hope someone can help me with this problem that would be great

Thank You really appreciate it

Take Care

re:

Posted: Thu Apr 28, 2005 7:37 pm
by harrisonad
Simply change this part:

Code: Select all

$row = mysql_fetch_assoc($result);                     
echo "<h1>"."Name:" . " " . $row['az_firstname'] . " " . $row['az_surname']  . "</h1>";         
echo "<h4>"."Username:" . " " . $row['username'] . " " . "</h4>";        
echo "<h4>"."User ID:" . " " . $row['user_id'] . " " . "</h4>";        
echo "<h4>"."Password:"." " . $row['password']. "</h4>";
into...

Code: Select all

$row = mysql_fetch_assoc($result);            
echo "
<form method=post action=''>
<input type=text name=firstname value='" . $row['az_firstname'] . "'>
<input type=text name=firstname value='" . $row['az_lastname'] . "'>
<input type=text name=username value='" . $row['username'] . "'>
<input type=text name=user_id value='" . $row['user_id'] . "'>
<input type=text name=password value='" . $row['password'] . "'>
<input type=submit value='update'>
</form>
";
this will load all the info about the user into an editable form.
then submit this form to a script that will update the selected record

Creating A Page To Edit Information And Update The Informati

Posted: Thu Apr 28, 2005 9:31 pm
by Arsenal Rule
Thank you so much for replying so quickling I understand how to make it into text boxes thank you so much. And I know to Update the database is an SQL statement with Update. However I am not sure the SQL statement submit this form to a script that will update the selected record. Basically I have a Table called azizpassword, And the attributes I want to update are az_firstname, az_lastname,username,password but I don't want update user_id coz thats auto incremented.

Code: Select all

if ($_POST['submitForm']) {

$sql = "Update INTO azizpassword // I dunno how to do the this Sql Statement to edit and update the correct inforamtion chosen on the database 
}
<input type=text name=firstname value='" . $row['az_firstname'] . "'>
<input type=text name=firstname value='" . $row['az_lastname'] . "'>
<input type=text name=username value='" . $row['username'] . "'>
<input type=text name=password value='" . $row['password'] . "'>
<input type=submit name"submitForm" value='update'></form>";
I am having problems with this because I am a beginner with PHP I'm still on the learning curve and I just want to understand this to solve this problem efficiently so I hope you or anyone can help me to solve this problem so I can understand it properly that would be so great

Take Care tahnk You For Your Time

re

Posted: Fri Apr 29, 2005 3:03 am
by harrisonad

Code: Select all

$query = "UPDATE azizpassword SET
    az_firstname='$firstname', 
    az_lastname='$lastname',
    username='$username',
    password='$password'
    WHERE user_id=$selected_user_id";
more info like these can be found at mySQL documentation.
read, read, read.

Posted: Fri Apr 29, 2005 3:39 am
by phpScott
so in yor form have a hidden field that holds the username_id

nearly there!!!!

Posted: Sat Apr 30, 2005 8:49 am
by Arsenal Rule
Hey, phpScott and Harrisonad and anyone else who can help, i am really nearly there!! in the view.php file, i am getting a return on all the data in the text boxes which is what i want!!!

here is the code:

Code: Select all

<?php
			if(isset($_REQUEST['id']))
			{
			$user_id = $_REQUEST['id'];
			
			$conn = mysql_connect("localhost","root","") or die("Could Not Connect To The Database"); 
		mysql_select_db("aziz",$conn) or die("Could Not Select The Database"); 
			
			if ($_POST['submitForm']) {
			$query = "UPDATE azizpassword SET az_firstname='$firstname',az_surname='$surname',username='$username',password='$password' WHERE user_id=$selected_user_id";
			}
			//sql query somethinglike
			
			$sql = "SELECT * FROM azizpassword WHERE user_id = '".$user_id."'"; 
			$result = mysql_query($sql); 
			$row = mysql_fetch_assoc($result);            
			echo "<form method=post action=''>
			<input type=text name=firstname value='" . $row['az_firstname'] . "'>
			<input type=text name=surname value='" . $row['az_surname'] . "'>
			<input type=text name=username value='" . $row['username'] . "'>
			<input type=text name=user_id value='" . $row['user_id'] . "'>
			<input type=text name=password value='" . $row['password'] . "'>
			<input type=submit name='submitForm' value='update'></form>";
			
		if (isset($HTTP_REFERER)) {echo "<a href='$HTTP_REFERER'>BACK</a>"; } 
		else {echo "<a href='javascript:history.back()'>BACK</a>"; 
		}
			  
			
			}
			?>
as you can see, the only thing stopping us now, is the submit form button, but everything else is reading properly, any suggestions?

If I could do this now, it would be great!! i know it is something really small, but i am inexperienced in PHP, im a noobie, so I dont have an eye for picking certain things up, whereas you lot are experienced, and know exactly what to do!!

thanks a lot matey's, your help until now has been very helpful indeed,

take care!! :)

Posted: Sat Apr 30, 2005 10:53 am
by phpScott
can you explain what is not happening with the submit button.

Check out your form tag as there is no action or method in it.

Code: Select all

<form name=&quote;someForm&quote; id=&quote;someId&quote; action=&quote;somePage.php&quote; method=&quote;post&quote;>