[solved]im going to try and code a php edit script here.

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

hi, ok here it goes...

PHP Code: [ Select ]
 
<?PHP
 
include("http://www.69kilobytes.co.uk");
 
if$submit
 
{
 
include("connect.php")
 
UPDATE members WHERE (Username,'$user',Password,'$pass')
 
else if
 
}
 
 
  1.  
  2. <?PHP
  3.  
  4. include("http://www.69kilobytes.co.uk");
  5.  
  6. if$submit
  7.  
  8. {
  9.  
  10. include("connect.php")
  11.  
  12. UPDATE members WHERE (Username,'$user',Password,'$pass')
  13.  
  14. else if
  15.  
  16. }
  17.  
  18.  


I think i done the Update line wrong. What i want to do is, create a username and password thing first, so if the the username and password matches one of the rows in the members table. All the others will show up with the previous comments inside ready to edit. then there is a submit form to update the table.

Is what im doing ok?


(was a spelling mistake, just edited)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • harryhood
  • Graduate
  • Graduate
  • harryhood
  • Posts: 141

Post 3+ Months Ago

I would think the update command should look more like:

PHP Code: [ Select ]
 
$sql = mysql_query("UPDATE members SET field1= '$field1value', field2 = '$field2value', fieldN = '$fieldNvalue'  WHERE username =  '$user' and password = '$pass'");
 
 
  1.  
  2. $sql = mysql_query("UPDATE members SET field1= '$field1value', field2 = '$field2value', fieldN = '$fieldNvalue'  WHERE username =  '$user' and password = '$pass'");
  3.  
  4.  


You'll have to collect the information to update before the $submit becomes true.

I don't know what you are trying to do exactly but it kinda sounds like you want to be doing an insert command.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

i have a table called members

there are 8 fields, 2 of which are username and password.

Now, if the username and password match one of the records then the details will show up.

else

and error shows

but if they do match, the fields show up and they can edit and then update.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

so... from what you mentioned:

PHP Code: [ Select ]
 
<?PHP
 
include("http://www.69kilobytes.co.uk");
 
if$submit
 
{
 
include("connect.php")
 
$sql = mysql_query("UPDATE members SET field1= '$field1value', field2 = '$field2value', fieldN = '$fieldNvalue'  WHERE username =  '$user' and password = '$pass'");
 
else if
 
}
 
 
  1.  
  2. <?PHP
  3.  
  4. include("http://www.69kilobytes.co.uk");
  5.  
  6. if$submit
  7.  
  8. {
  9.  
  10. include("connect.php")
  11.  
  12. $sql = mysql_query("UPDATE members SET field1= '$field1value', field2 = '$field2value', fieldN = '$fieldNvalue'  WHERE username =  '$user' and password = '$pass'");
  13.  
  14. else if
  15.  
  16. }
  17.  
  18.  
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

PHP Code: [ Select ]
 
<?
 
include("http://www.69kilobytes.co.uk/header.php");
 
include 'connect.php';
 
 
 
$table_name = 'members';
 
$entry_id = 'username';
 
 
 
if(array_key_exists('EditIt', $_POST) && !empty($_POST['EditIt'])){  
 
   $fieldst = 'SET ';
 
   $increment = 0;
 
   $count = count($_POST['fields']);
 
   foreach ($_POST['fields'] as $key => $value){      
 
   $increment++;
 
   ($count == $increment) ? $fieldst .= $key . "='" . $value . "' " : $fieldst .= $key . "='" . $value . "', ";
 
   }
 
   $result = mysql_query("UPDATE " . $table_name . " " . $fieldst . " WHERE " . $entry_id . "='" . $_POST['selectid'] . "'");  
 
   $result ? print 'Done! <br />' : print 'Opps...i did it again! <br />';
 
}
 
elseif(isset($_POST['ShowIt'])){  
 
   $result = mysql_query("SELECT * FROM " . $table_name . " WHERE " . $entry_id . "='" . $_POST['selectid'] . "'");      
 
   print ('<form name="editform" action="' . $_SERVER['PHP_SELF'] . '" method="post">');
 
   print ('<b>Editing entry: id #</b>'. $_POST['selectid'] .'<p>');
 
   print ('<table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#7F9DB9" align="center">');
 
   while($row = mysql_fetch_row($result)){
 
   for($i = 0; $i < mysql_num_fields($result); $i++){          
 
   print ('<tr><td valign="middle" bgcolor="#F7F7F7" width="35%">');
 
   print ('<b>' . mysql_field_name($result,$i) . '</b>: ');      
 
   print ('</td>');
 
   print ('<td valign="middle" bgcolor="#F7F7F7">');
 
   print ('<input name="fields[' . mysql_field_name($result,$i) . ']" value="' . htmlspecialchars($row[$i]) . '">');
 
   print ('</td></tr>');
 
    }
 
   }
 
   print '</table><br />';
 
   print '<input type="hidden" name="selectid" value="' . $_POST['selectid'] . '"><input type="submit" name="EditIt" value="Submit"></form>';
 
}
 
else{
 
    $result = mysql_query('SELECT * FROM ' . $table_name);
 
    print 'Select entry:';
 
    print '<form name="ddform" action="' . $_SERVER['PHP_SELF'] . '" method="post">';
 
   print '<select name="dropdown" onChange="javascript&#058;document.ddform.selectid.value = document.ddform.dropdown.options[document.ddform.dropdown.selectedIndex].value;">' . '<br />';
 
    print '<option value=""> -- </option>' . "\n";
 
   while($row = mysql_fetch_array($result)){
 
   print ('<option value="'. $row[$entry_id] . '">');
 
   print ($row[$entry_title]);      
 
   print ('</option>');
 
    }
 
    print ('</select> <input type="hidden" name="selectid" value=""><input type="submit" name="ShowIt" value="Show"></form>' . '<br />');
 
}
 
include("http://www.69kilobytes.co.uk/footer.php");
 
?>
 
 
 
 
  1.  
  2. <?
  3.  
  4. include("http://www.69kilobytes.co.uk/header.php");
  5.  
  6. include 'connect.php';
  7.  
  8.  
  9.  
  10. $table_name = 'members';
  11.  
  12. $entry_id = 'username';
  13.  
  14.  
  15.  
  16. if(array_key_exists('EditIt', $_POST) && !empty($_POST['EditIt'])){  
  17.  
  18.    $fieldst = 'SET ';
  19.  
  20.    $increment = 0;
  21.  
  22.    $count = count($_POST['fields']);
  23.  
  24.    foreach ($_POST['fields'] as $key => $value){      
  25.  
  26.    $increment++;
  27.  
  28.    ($count == $increment) ? $fieldst .= $key . "='" . $value . "' " : $fieldst .= $key . "='" . $value . "', ";
  29.  
  30.    }
  31.  
  32.    $result = mysql_query("UPDATE " . $table_name . " " . $fieldst . " WHERE " . $entry_id . "='" . $_POST['selectid'] . "'");  
  33.  
  34.    $result ? print 'Done! <br />' : print 'Opps...i did it again! <br />';
  35.  
  36. }
  37.  
  38. elseif(isset($_POST['ShowIt'])){  
  39.  
  40.    $result = mysql_query("SELECT * FROM " . $table_name . " WHERE " . $entry_id . "='" . $_POST['selectid'] . "'");      
  41.  
  42.    print ('<form name="editform" action="' . $_SERVER['PHP_SELF'] . '" method="post">');
  43.  
  44.    print ('<b>Editing entry: id #</b>'. $_POST['selectid'] .'<p>');
  45.  
  46.    print ('<table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#7F9DB9" align="center">');
  47.  
  48.    while($row = mysql_fetch_row($result)){
  49.  
  50.    for($i = 0; $i < mysql_num_fields($result); $i++){          
  51.  
  52.    print ('<tr><td valign="middle" bgcolor="#F7F7F7" width="35%">');
  53.  
  54.    print ('<b>' . mysql_field_name($result,$i) . '</b>: ');      
  55.  
  56.    print ('</td>');
  57.  
  58.    print ('<td valign="middle" bgcolor="#F7F7F7">');
  59.  
  60.    print ('<input name="fields[' . mysql_field_name($result,$i) . ']" value="' . htmlspecialchars($row[$i]) . '">');
  61.  
  62.    print ('</td></tr>');
  63.  
  64.     }
  65.  
  66.    }
  67.  
  68.    print '</table><br />';
  69.  
  70.    print '<input type="hidden" name="selectid" value="' . $_POST['selectid'] . '"><input type="submit" name="EditIt" value="Submit"></form>';
  71.  
  72. }
  73.  
  74. else{
  75.  
  76.     $result = mysql_query('SELECT * FROM ' . $table_name);
  77.  
  78.     print 'Select entry:';
  79.  
  80.     print '<form name="ddform" action="' . $_SERVER['PHP_SELF'] . '" method="post">';
  81.  
  82.    print '<select name="dropdown" onChange="javascript&#058;document.ddform.selectid.value = document.ddform.dropdown.options[document.ddform.dropdown.selectedIndex].value;">' . '<br />';
  83.  
  84.     print '<option value=""> -- </option>' . "\n";
  85.  
  86.    while($row = mysql_fetch_array($result)){
  87.  
  88.    print ('<option value="'. $row[$entry_id] . '">');
  89.  
  90.    print ($row[$entry_title]);      
  91.  
  92.    print ('</option>');
  93.  
  94.     }
  95.  
  96.     print ('</select> <input type="hidden" name="selectid" value=""><input type="submit" name="ShowIt" value="Show"></form>' . '<br />');
  97.  
  98. }
  99.  
  100. include("http://www.69kilobytes.co.uk/footer.php");
  101.  
  102. ?>
  103.  
  104.  
  105.  
  106.  


i found this code, i just hate doing this copy n pasting but i havent really got much time.

there is a drop down box in the script, why doesnt the members names show up in there?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Okay I am left wondering why you are trying to populate a drop down list with member names? Aren't they supposed to be secret?

PHP Code: [ Select ]
 
<?php
 
include("http://www.69kilobytes.co.uk/header.php");
 
include 'connect.php';
 
 
 
$table_name = 'members';
 
$entry_id = 'username';
 
 
 
if(array_key_exists('EditIt', $_POST) && !empty($_POST['EditIt'])){  
 
   $fieldst = 'SET ';
 
   $increment = 0;
 
   $count = count($_POST['fields']);
 
   foreach ($_POST['fields'] as $key => $value){        
 
   $increment++;
 
   ($count == $increment) ? $fieldst .= $key . "='" . $value . "' " : $fieldst .= $key . "='" . $value . "', ";
 
   }
 
   $result = mysql_query("UPDATE " . $table_name . " " . $fieldst . " WHERE " . $entry_id . "='" . $_POST['selectid'] . "'");  
 
   $result ? print 'Done! <br />' : print 'Opps...i did it again! <br />';
 
}elseif(isset($_POST['ShowIt'])){  
 
   $result = mysql_query("SELECT * FROM " . $table_name . " WHERE " . $entry_id . "='" . $_POST['selectid'] . "'");        
 
   print ('<form name="editform" action="' . $_SERVER['PHP_SELF'] . '" method="post">');
 
   print ('<b>Editing entry: id #</b>'. $_POST['selectid'] .'<p>');
 
   print ('<table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#7F9DB9" align="center">');
 
   while($row = mysql_fetch_row($result)){
 
   for($i = 0; $i < mysql_num_fields($result); $i++){          
 
      print ('<tr><td valign="middle" bgcolor="#F7F7F7" width="35%">');
 
      print ('<b>' . mysql_field_name($result,$i) . '</b>: ');        
 
      print ('</td>');
 
      print ('<td valign="middle" bgcolor="#F7F7F7">');
 
      print ('<input name="fields[' . mysql_field_name($result,$i) . ']" value="' . htmlspecialchars($row[$i]) . '">');
 
      print ('</td></tr>');
 
    }
 
   }
 
   print '</table><br />';
 
   print '<input type="hidden" name="selectid" value="' . $_POST['selectid'] . '"><input type="submit" name="EditIt" value="Submit"></form>';
 
}else{
 
   $sql  = 'SELECT * FROM ' . $table_name
 
    $result = mysql_query($sql);
 
    print 'Select entry:';
 
    print '<form name="ddform" action="' . $_SERVER['PHP_SELF'] . '" method="post">';
 
   print '<select name="dropdown" onChange="javascript&#058;document.ddform.selectid.value = document.ddform.dropdown.options[document.ddform.dropdown.selectedIndex].value;">' . '<br />';
 
    print '<option value=""> -- </option>' . "\n";
 
   while($row = mysql_fetch_array($result)){
 
   print ('<option value="'. $row[$entry_id] . '">');
 
   print ($row[$entry_title]);        
 
   print ('</option>');
 
    }
 
    print ('</select> <input type="hidden" name="selectid" value=""><input type="submit" name="ShowIt" value="Show"></form>' . '<br />');
 
}
 
include("http://www.69kilobytes.co.uk/footer.php");
 
?>
 
 
  1.  
  2. <?php
  3.  
  4. include("http://www.69kilobytes.co.uk/header.php");
  5.  
  6. include 'connect.php';
  7.  
  8.  
  9.  
  10. $table_name = 'members';
  11.  
  12. $entry_id = 'username';
  13.  
  14.  
  15.  
  16. if(array_key_exists('EditIt', $_POST) && !empty($_POST['EditIt'])){  
  17.  
  18.    $fieldst = 'SET ';
  19.  
  20.    $increment = 0;
  21.  
  22.    $count = count($_POST['fields']);
  23.  
  24.    foreach ($_POST['fields'] as $key => $value){        
  25.  
  26.    $increment++;
  27.  
  28.    ($count == $increment) ? $fieldst .= $key . "='" . $value . "' " : $fieldst .= $key . "='" . $value . "', ";
  29.  
  30.    }
  31.  
  32.    $result = mysql_query("UPDATE " . $table_name . " " . $fieldst . " WHERE " . $entry_id . "='" . $_POST['selectid'] . "'");  
  33.  
  34.    $result ? print 'Done! <br />' : print 'Opps...i did it again! <br />';
  35.  
  36. }elseif(isset($_POST['ShowIt'])){  
  37.  
  38.    $result = mysql_query("SELECT * FROM " . $table_name . " WHERE " . $entry_id . "='" . $_POST['selectid'] . "'");        
  39.  
  40.    print ('<form name="editform" action="' . $_SERVER['PHP_SELF'] . '" method="post">');
  41.  
  42.    print ('<b>Editing entry: id #</b>'. $_POST['selectid'] .'<p>');
  43.  
  44.    print ('<table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#7F9DB9" align="center">');
  45.  
  46.    while($row = mysql_fetch_row($result)){
  47.  
  48.    for($i = 0; $i < mysql_num_fields($result); $i++){          
  49.  
  50.       print ('<tr><td valign="middle" bgcolor="#F7F7F7" width="35%">');
  51.  
  52.       print ('<b>' . mysql_field_name($result,$i) . '</b>: ');        
  53.  
  54.       print ('</td>');
  55.  
  56.       print ('<td valign="middle" bgcolor="#F7F7F7">');
  57.  
  58.       print ('<input name="fields[' . mysql_field_name($result,$i) . ']" value="' . htmlspecialchars($row[$i]) . '">');
  59.  
  60.       print ('</td></tr>');
  61.  
  62.     }
  63.  
  64.    }
  65.  
  66.    print '</table><br />';
  67.  
  68.    print '<input type="hidden" name="selectid" value="' . $_POST['selectid'] . '"><input type="submit" name="EditIt" value="Submit"></form>';
  69.  
  70. }else{
  71.  
  72.    $sql  = 'SELECT * FROM ' . $table_name
  73.  
  74.     $result = mysql_query($sql);
  75.  
  76.     print 'Select entry:';
  77.  
  78.     print '<form name="ddform" action="' . $_SERVER['PHP_SELF'] . '" method="post">';
  79.  
  80.    print '<select name="dropdown" onChange="javascript&#058;document.ddform.selectid.value = document.ddform.dropdown.options[document.ddform.dropdown.selectedIndex].value;">' . '<br />';
  81.  
  82.     print '<option value=""> -- </option>' . "\n";
  83.  
  84.    while($row = mysql_fetch_array($result)){
  85.  
  86.    print ('<option value="'. $row[$entry_id] . '">');
  87.  
  88.    print ($row[$entry_title]);        
  89.  
  90.    print ('</option>');
  91.  
  92.     }
  93.  
  94.     print ('</select> <input type="hidden" name="selectid" value=""><input type="submit" name="ShowIt" value="Show"></form>' . '<br />');
  95.  
  96. }
  97.  
  98. include("http://www.69kilobytes.co.uk/footer.php");
  99.  
  100. ?>
  101.  
  102.  

Try this I made one small change and I don't know if it will work

One question, stupid question. Do you have members saved in the members table?
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

yeah 5, roflmao
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

error:

Quote:
Parse error: parse error in /home/virtual/site2/fst/var/www/html/cp/edit_1.php on line 37
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

You need to change:
PHP Code: [ Select ]
  $sql    = 'SELECT * FROM ' . $table_name

to
PHP Code: [ Select ]
  $sql    = 'SELECT * FROM ' . $table_name;

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 50 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.