Jump to content

how to update multiplie fields


karq

Recommended Posts

So basicly how do I update multiplie fields in mysql? I know how to fetch data from multiplie fields, but when I start to update them, then it only updates the last field.

First file:

<?php
//Kontrollime kas on sisse loginud
session_start();
if (session_is_registered("kasutaja")) {
echo "<center><b>Uudiste muutmine</b><br />
<a href='user.php'>Tagasi</a></center>";
include "db.php";
//tõmbama data
$vot=mysql_query("SELECT * FROM uudis");
while ($g=mysql_fetch_array($vot)) {
echo "<form action='mud.php' method='post'>
<input type='hidden' name='id' value=$g[num] /><br />
<center>Pealkiri:<input type='text' value=$g[pealkiri] name='peal'/><br />
<textarea cols='20' rows='10' name='uudis'>$g[uudis]</textarea><br />
";
} //while
echo "<input type='submit' value='muuda'/></center></form>";
}
//Kui ei ole sisse loginud
else {
echo "<center>Palun <a href='logi.php'>logi sisse</a></center>";
}
?>

Second file

<?php
session_start();
if (session_is_registered("kasutaja")) {
//form data
$pealkiri=$_POST["peal"];
$uudis=$_POST["uudis"];
$num=$_POST["id"];
//If form is not set propally
if (!isset($pealkiri) || !isset($uudis)) {
	echo "Something is wrong<br />";
}
//If form is empty
if (strlen($pealkiri)==0 || strlen($uudis)==0) {
	echo "Please, fill the fields<br />";
}
//If everything is ok
else {
include "db.php";
	for ($i=0;$i < sizeof($pealkiri);$i++){
		echo $i;
	}
}

}
?>

 

 

I know where is the problem, but I dont know how to solve it. And please dont start to scream at me, I'm just a noob. :D

Link to comment
https://forums.phpfreaks.com/topic/161800-how-to-update-multiplie-fields/
Share on other sites

Sorry, I posted the wrong file.

And that what you gave dosent work, it only updates the last fields.

<?php
session_start();
if (session_is_registered("kasutaja")) {
//form data
$pealkiri=$_POST["peal"];
$uudis=$_POST["uudis"];
$num=$_POST["id"];
//If form is not set propally
if (!isset($pealkiri) || !isset($uudis)) {
	echo "Kuskil on viga<br />";
}
//If form is empty
if (strlen($pealkiri)==0 || strlen($uudis)==0) {
	echo "Täitke väljad<br />";
}
//If everything is ok
else {
include "db.php";
$update="UPDATE uudis SET pealkiri='$pealkiri' , uudis='$uudis'
WHERE num='$num'";
if (!mysql_query($update,$con)) {
echo mysql_error();
	}
else {
echo "tehtud";
}
}

}
?>

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.