Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Update db via a php/html form
Old 03-04-2010, 07:01 PM Update db via a php/html form
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Hello to everyone!
I need a mode to modify (edit) and update the db via a php/html form. I have now a mode to insert and delete form but i don;t know how to proceed for a update form. Can someone help me please?

Thank you in advance!
Kleidi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-04-2010, 07:06 PM Re: Update db via a php/html form
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
What I do is:

Use whatever you do to VIEW whats in the db and then direct it to a page
ie:
edit.php?id=1

Then on edit php.
Just have a bunch of text fields that get populated by php SELECT on the DB based on your _GET['id']

Then when you click EDIT / COMPLETE

it will submit the form to something like editaction.php

and then update the row based on the $_POST data.

( if that makes any sense? )
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 03-04-2010, 07:18 PM Re: Update db via a php/html form
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Ok ... what i understand is:

I will create a page that will be named edit.php where will be the html form and the form should retrieve datas from db with _GET['xx'] mode as default text on the fields. Ex:
i have table name on the db and to retrieve datas from it, i should use _GET['name']?
After that, i will create a process page for the edit form to be processed and submitted on the db with sql UPDATE syntax?

Hope that i got the idea!
Kleidi is offline
Reply With Quote
View Public Profile
 
Old 03-05-2010, 11:48 AM Re: Update db via a php/html form
Junior Talker

Posts: 1
Name: Valeriy
Trades: 0
If i understand u right, you need this code:

Code:
<?php
//connecting to db.........



	//form handling-------
	if(isset($_POST['save']))
	{
	$data=$_POST['data'];
	mysql_query("UPDATE my_data SET my_data='$data';");
	}
	//---------------------


$row=mysql_query("SELECT my_data FROM table_name;");
if($row=mysql_fetch_assoc($res))
{
$data=$row['my_data'];
}
?>
<form method="post">
<textarea name="data"><?=$data;?></textarea><br /> 
<input type="submit" name="save" value="save" />
</form>

Last edited by valerik; 03-05-2010 at 11:49 AM..
valerik is offline
Reply With Quote
View Public Profile
 
Old 03-05-2010, 04:23 PM Re: Update db via a php/html form
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Hello there!

Thank you for your reply valerik but i'm a newb and i don;t know how to develop that code you gived.

What i need is a a way to edit/update a row via an html/php form. To explain better i'll give an example:

I have a php page that retrieves datas from db. At that page i have a link that offer the delete option for the respective row and i need to have another link that offers me a way to edit that row.
The delete link, when i click on it, redirects me on a delete.php?delete=true?id=$id page where $id is a number that the delete.php page recognize when i clicked on the row that i want to delete. Working with $_GET[ID].
In the same wai, i need a page that offers me a way to modify a db row that is listed on the showpage.
What i have now is this mess :

edit.php
PHP Code:
<?php
session_start
();

if(!isset(
$_SESSION['loggedin'])) {
   
header('Location: '.$domain.'index.php?error=1');
   exit();
}
?>
<?php
include 'D:/Program Files/VertrigoServ/www/live/admini/includet/variabla.php';
include (
BPATH_ADM 'includet/dbconfig.php');
include (
BPATH_ADM 'includet/dblidhja.php');
$query="SELECT * FROM ndeshje";
$result=mysql_query($query);
$num=mysql_numrows($result);

mysql_close();

$id=mysql_result($result,$i,"ID");
$ndeshja=mysql_result($result,$i,"ndeshja");
$ora=mysql_result($result,$i,"ora");
$kodi=mysql_result($result,$i,"kodi");
$data=mysql_result($result,$i,"data");
$menyra=mysql_result($result,$i,"menyra");
$sporti=mysql_result($result,$i,"sporti");
$permalink=mysql_result($result,$i,"permalink");
?>
<form method="post" name="shtondeshje" action="modulet/ndeshje/p.edit.php">

<p><label for="ndeshja">Ndeshja : <input name="ndeshja" type="text" id="ndeshja" value="<?php echo $ndeshja?>" size="50" maxlength="255" />
</label></p>
<p><label for="menyra">Permalink : <input name="menyra" type="text" id="menyra" value="<?php echo $permalink?>" size="50" maxlength="255" />
</label>
<p>
  <label for="sporti">Sporti : 
  <select name="sporti" id="sporti">
    <option value="/imazhet/ikona/football.gif" selected="selected">Football</option>
    <option value="/imazhet/ikona/basketball.gif">Basketball</option>
    <option value="/imazhet/ikona/baseball.gif">Baseball</option>
    <option value="/imazhet/ikona/tennis.gif">Tennis</option>
    <option value="/imazhet/ikona/motorsports.gif">Motorsports</option>
    <option value="/imazhet/ikona/cycling.gif">Cycling</option>
    <option value="/imazhet/ikona/cricket.gif">Cricket</option>
    <option value="/imazhet/ikona/americanfootball.gif">American Football</option>
    <option value="/imazhet/ikona/other.gif">Other</option>
  </select>
  </label>
</p>
<p><label for="ora">Ora : <input name="ora" type="text" id="ora" value="<?php echo $ora?>" />
</label>
</p>
<p><label for="data">Data : <input name="data" type="text" id="data" value="<?php echo $data?>" />
</label>
</p>
<p><label for="menyra">Menyra : <input name="menyra" type="text" id="menyra" value="<?php echo $menyra?>" />
</label>
</p>
<p><label for="kodi">Kodi : <textarea name="kodi" cols="50" rows="8" id="kodi"> <?php echo $kodi?></textarea>
 </label></p>

<p><input class="buton" type="submit" name="submit" value="Modifikoje" /> <input class="buton" type="reset" name="reset" value="Rifillo" /></p>
</form>

<?php
if (isset($_GET['error']) AND !empty($_GET['error'])) 
 {
    echo 
'Ndodhi nje Gabim. Provoje Serish';
    echo 
'<form><input type="button" class="buton" value="Kthehu Mbrapa" 
ONCLICK="history.go(-1)"></form>'
;
 }
?>
p.edit.php
PHP Code:
<?php
session_start
();

if(!isset(
$_SESSION['loggedin'])) {
   
header('Location: '.$domain.'index.php?error=1');
   exit();
}
?>
<?php
include 'D:/Program Files/VertrigoServ/www/live/admini/config.php';

$ndeshja $_POST['ndeshja'];
$ora $_POST['ora'];
$data $_POST['data'];
$kodi $_POST['kodi'];
$menyra $_POST['menyra'];
 
// $permalink = preg_replace("#[^a-z0-9\-]#i", "", str_replace(" ", "_", strtolower($ndeshja))); - Nese dua linkun me shkronja te vogla
$permalink preg_replace("#[^a-z0-9\-_]#i""",str_replace(' ''_'$ndeshja));

$db mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbname,$db);

$sql="INSERT INTO ndeshje (`ndeshja`, `ora`, `data`, `kodi`, `menyra`, `permalink`, `sporti` ) VALUES ('$ndeshja', '$ora', '$data', '$kodi', '$menyra', '$permalink', '$sporti')";
// mysql_query($sql, $db) or die('Gabim! Shtimi i ndeshjes deshtoi.');
mysql_query($sql$db) or die('Gabim! Shtimi i ndeshjes deshtoi.<br / > ' mysql_error());

mysql_close();
ob_start();
header('Location: '.$domain.'admin.php?sukses=1');
ob_flush();

?>
When i manually load the edit.php page, it loads the values for the first entry on the database :P ... i tried to access edit.php?id=44 (where 44 is an id on my db) and nothing happens; the page loads the first id on the db :P

Can you help me?

Thank you in advance!
Kleidi is offline
Reply With Quote
View Public Profile
 
Old 03-06-2010, 06:43 PM Re: Update db via a php/html form
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Any help please?
Kleidi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Update db via a php/html form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30143 seconds with 12 queries