karq Posted June 11, 2009 Share Posted June 11, 2009 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. Link to comment https://forums.phpfreaks.com/topic/161800-how-to-update-multiplie-fields/ Share on other sites More sharing options...
Mark Baker Posted June 11, 2009 Share Posted June 11, 2009 UPDATE tablename SET field1 = value1, field2 = value2, field3 = value3 WHERE idField = selectionValue Link to comment https://forums.phpfreaks.com/topic/161800-how-to-update-multiplie-fields/#findComment-853693 Share on other sites More sharing options...
karq Posted June 11, 2009 Author Share Posted June 11, 2009 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"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/161800-how-to-update-multiplie-fields/#findComment-853711 Share on other sites More sharing options...
haku Posted June 11, 2009 Share Posted June 11, 2009 What he told you was correct. If it is only updating the most recent fields, it's because your 'WHERE' clause is wrong - meaning that $num is not what you think it is. Link to comment https://forums.phpfreaks.com/topic/161800-how-to-update-multiplie-fields/#findComment-853723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.