change it!!?!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

change it!!?!

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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 :?
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no... live... as in working... interactive...
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post 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!!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post 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
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

Post 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?
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

its on my localhost server ...
how can i post a link so that someone can use my scripts ???
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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.
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post 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
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
Post Reply