Page 1 of 1

change it!!?!

Posted: Mon Nov 07, 2005 6:54 pm
by joecrack
There are two thing that is not working right ...
When i click the button to change a dataset, the script always takes the first one i cant select the second or third.
Also it doesnt change it ... there must be a mistake that i just dont see !!!

Code: Select all

<html><head><title>Change Dataset</title></head><body>
<?php
error_reporting(E_ALL);

$db = mysql_connect("localhost","root","") or die ("MySQL-Fehler: " . mysql_error());
mysql_select_db("safe",$db) or die ("MySQL-Fehler: " . mysql_error());
$sql = 'SELECT * FROM `sam_artikel`';
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
$cols = mysql_num_fields($result);

echo '<p><b>You have '.$rows.' CDs:</b></p>';
echo '<table border="1"><tr><th>#</th>';
for ($i = 0; $i<$cols; $i++)
   {
   echo '<th>'.htmlentities(mysql_field_name($result,$i)).'</th>';
   }
echo "<th>update?</th>";
echo "</tr>";

for ($i = 0; $i < $rows; $i++)
   {
   $z = $i+1;
   echo "<tr><td>$z</td>";
   
   for ($k = 0; $k < $cols; $k++
      {
      $cell = mysql_result($result, $i, $k);
      echo '<td>'.$cell.'</td>';
      }
   ?>
   <td><a href="http://localhost/aendern.php?i=<?php echo $i; ?>">aendern</a></td>
   <?php }
   mysql_close();
   ?>
   </tr>
</table></body></html>

Code: Select all

<html><head><title>Change!</title></head>
<body>
You can now change the selected:<br><br>
<?php
error_reporting(E_ALL);

$db = mysql_connect("localhost","root","") or die ("MySQL-Fehler: " . mysql_error());
mysql_select_db("safe",$db) or die ("MySQL-Fehler: " . mysql_error());

$sql="SELECT * FROM sam_artikel";
$result=mysql_query($sql);
$rows=mysql_num_rows($result);
$cols=mysql_num_fields($result);
echo "<form>";
echo "<table border=1><tr>";
$cell=mysql_result($result,$i=0);
echo "<td>$cell</td>";
for ($k=1;$k<$cols;$k++)
   {
   $cell=mysql_result($result,$i,$k);
   $name=htmlentities(mysql_field_name($result,$k));
   echo "<td><input type=\"text\" name=\"$name\" value=\"$cell\"></td>";
   }
echo "</tr></table><br>";
?>

<input type="submit" name="update" value="Ändern">&nbsp;&nbsp;&nbsp;
<input type="hidden" name="i" value="<?php echo $i; ?>"><br><br></form>
<?php
$nummer=mysql_result($result,$i,0);
if ($update)
   {
   mysql_query("UPDATE sam_artikel SET eqdes='$eqdes', designer='$designer', value='$value', beschreibung='$beschreibung', eqdesignation='$eqdesignation' WHERE id='$nummer'");
   echo "The CD $nummer was changed";
   }
mysql_close();
?>
</body></html>
PLEASE HELP

Posted: Mon Nov 07, 2005 7:50 pm
by feyd
with this much code and no sign of what it's actually doing, I want to see a live example of this..

and please work on coming up with more helpful titles to your topics :?

Posted: Mon Nov 07, 2005 8:44 pm
by joecrack
sorry about the topic ..
so here are to pictures of what the script is doing

http://rzserv2.fhnon.de/~lg016500/1.JPG

u just select a dataset to change it ...

http://rzserv2.fhnon.de/~lg016500/2.JPG

and here you can change the values.
but it always selects the first dataset and it doesnt change it !!!
joe

Posted: Mon Nov 07, 2005 8:47 pm
by feyd
no... live... as in working... interactive...

Posted: Mon Nov 07, 2005 9:01 pm
by joecrack
Thats what you see when you have it LIVE WORKING
cant you think of anything that could be wrong ... plz .. you dont even try to help me!!!

Posted: Mon Nov 07, 2005 9:37 pm
by feyd
I'm trying to help, but you're trying my patience now.. I want to see a fully working page.. as in a link to the actual "working" page, so I, myself, can see it in action... This is the last time I ask for it.

Posted: Mon Nov 07, 2005 11:12 pm
by joecrack
sry i dont know how to do that!!!
what would you need for that my IP and ...?
just dont get it ..
thx for trying

Posted: Mon Nov 07, 2005 11:16 pm
by dallasx
joecrack wrote:sry i dont know how to do that!!!
what would you need for that my IP and ...?
just dont get it ..
thx for trying
Don't know how to do what? Copy / paste a link?

Posted: Tue Nov 08, 2005 12:03 am
by joecrack
its on my localhost server ...
how can i post a link so that someone can use my scripts ???

Posted: Tue Nov 08, 2005 4:04 am
by n00b Saibot
from what i understand your editing code is absolutely wrong. the form tag has no defined attributes... you are displaying the 1st record everytime instead of the selected one and lastly your update query is downright wrong.

Posted: Tue Nov 08, 2005 6:16 am
by yum-jelly
I don't understand the logic in this...

1. you set FORM, SUBMIT, but you don't use it's values any where.

The only input used in the UPDATE FORM is * update *, so how in the world do you expect to update anything.

2. you set the form before the update control, so you will never see the update result until the second page load!


yj

Posted: Tue Nov 08, 2005 7:41 pm
by joecrack
So at least I fixed one error ...
Now it is showing me the record that i select when i click change on the first page.
No i still got the Prob that I dont update.

Code: Select all

<?php
error_reporting(E_ALL);
$db = mysql_connect("localhost","root","") or die ("MySQL-Fehler: " . mysql_error());
mysql_select_db("safe",$db) or die ("MySQL-Fehler: " . mysql_error());
$sql="SELECT * FROM sam_artikel";
$result=mysql_query($sql);
$rows=mysql_num_rows($result);
$cols=mysql_num_fields($result);
echo "<form>";
echo "<table border=1><tr>";
$cell=mysql_result($result,$i);
echo "<td>$cell</td>";
for ($k=0;$k<$cols;$k++)
   {
   $cell=mysql_result($result,$i,$k);
   $name=htmlentities(mysql_field_name($result,$k));
   echo "<td><input type=\"text\" name=\"$name\" value=\"$cell\"></td>";
   }
echo "</tr></table><br>";
?>
<input type="submit" name="update" value="Ändern">&nbsp;&nbsp;&nbsp;
<input type="hidden" name="i" value="<?php echo $i; ?>"><br><br></form>
<?php
$nummer=mysql_result($result,$i,0);
if ($update)
   {
   mysql_query("UPDATE sam_artikel SET eqdes='".$eqdes."', groupp='".$groupp."', beschreibung='".$cell."' WHERE id='".$_GET['i']."'");
   echo "Artikel $nummer was chaged - press F5 to see results!!";
   }
mysql_close();
?>
Its about this line right:
echo "<td><input type=\"text\" name=\"$name\" value=\"$cell\"></td>";
I just dont know how to set the right values??!
Please HELP
I am a bloody newbie but I have to do this script!!!
thx
joe

Posted: Tue Nov 08, 2005 7:50 pm
by feyd
  1. $update will not magically appear (likely) when a submission happens.
  2. if the submit button isn't used to submit the page, your update code will not be run when using IE
Look for the hidden field, using $_GET or $_POST...