General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 29th, 2003, 05:01 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
update/ delete in a db

alright I have a few things to do for my site which require that the user get to update or delete their info, so, how can I do this? Here is the coide that I thought was needed:

PHP Code:
 $strQuery "UPDATE users WHERE username = " $handle "(";
                    
$strQuery .= "`firstname`, `lastname`, `location`, `age`) VALUES (";
                    
$strQuery .= "'{$_POST['strFirstName']}', '{$_POST['strLastName']}', '{$_POST['strLocation']}', '{$_POST['strAge']}')";
                        if(
mysql_query($strQuery)) 


it then goes on to do some other code, not important.
so what is wrong here, is UPDATE even a function i can use here? how can i do this? and delete?

thanks guys.
__________________
hey it's the CHARKING

Reply With Quote
  #2  
Old June 29th, 2003, 10:06 AM
DudeThatWasRude DudeThatWasRude is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 7 DudeThatWasRude User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Is it a SQL query for Updating data?
Where is SET?
You are probably confused with correctness of query of SQL update syntax.

Reply With Quote
  #3  
Old June 29th, 2003, 10:10 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
You're pretty close, cept update statements look like this:

UPDATE tablename SET field = value, field2 = value2 WHERE field = foo

So, just move the WHERE part to the end.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #4  
Old June 29th, 2003, 12:48 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Try this:
PHP Code:
<?php

  $strQuery 
.= "UPDATE users SET";
  
$strQuery .= " firstname = " $_POST['strFirstName'] .
               
",lastname  = " $_POST['strLastName']  .
               
",location  = " $_POST['strLocation']  .
               
",age       = " $_POST['strAge'];
  
$strQuery .= " WHERE " .
               
"username   = " $handle .
               
";";

  print 
$strQuery;

?>
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #5  
Old June 29th, 2003, 05:07 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
still not working

okay i tried using the code guys, and it made sense, but it still wont work. here is my code... can anyone see the msitake?

PHP Code:
<?php
// Configuration part 
$dbhost "localhost"// Database host 
$dbname "users"// Database name 
$dbuser "dbuser"// Database username 
$dbpass ""// Database password 

// Connect to database 
$db mysql_connect($dbhost$dbuser$dbpass) or die("Error: Couldn't connect to database"); 
mysql_select_db($dbname$db) or die("Error: Couldn't select database.");

function 
update()
{
if(
$_POST['what'] == 'process')
  {
    
$dbVars = new dbVars;
    @
$svrConn mysql_connect($dbVars->strServer$dbVars->strUser$dbVars->strPass);
        if(
$svrConn)
            { 
            
// Connected to the database server OK
            
$dbConn mysql_select_db($dbVars->strDb$svrConn);
                if(
$dbConn)
                    {

  
$strQuery .= "UPDATE users SET";
  
$strQuery .= " firstname = " $_POST['strFirstName'] .
               
",lastname  = " $_POST['strLastName']  .
               
",location  = " $_POST['strLocation']  .
               
",age       = " $_POST['strAge'];
  
$strQuery .= " WHERE " .
               
"username   = " $_GET['username'] .
               
";";

if(
mysql_query($strQuery))
    {
?>
  
  
                  <?php /*    $strQuery = "UPDATE users WHERE username = " . $handle . "(";
                    $strQuery .= "`firstname`, `lastname`, `location`, `age`) VALUES (";
                    $strQuery .= "'{$_POST['strFirstName']}', '{$_POST['strLastName']}', '{$_POST['strLocation']}', '{$_POST['strAge']}')";
                        if(mysql_query($strQuery))
                            {
                                */
?>

<span class="title">Profile Updated!</span></span><br>
<br>You have successfully updated your Profile!<br>
<a href="index.php">Continue</a>
<?php } else { echo "it didnt work"; } } } } }

  function 
MatchUp()
       {
         
$changeIt = @mysql_query("SELECT * FROM users WHERE sessionid ="
         
$_GET['strMethod'] . "");
          while (
$changeRow mysql_fetch_row($changeIt))
              { 
$strMethod2 $changeRow[1]; }
header("Location: index.php?page=editprofile&strMethod=$strMethod2"); }
                    
  function 
NoMatchUp()
  {
      if(
$_GET['strMethod'])
   {
    
$verifyUser = @mysql_query("SELECT * FROM `session` WHERE sessionid = 
                                '" 
$_GET['strMethod'] . "'");
     while (
$userRow mysql_fetch_row($verifyUser))
      { 
$verifyUser2 = @mysql_query("SELECT * FROM users WHERE username = 
                                      '" 
$userRow[2] . "'");
        while (
$userRow2 mysql_fetch_row($verifyUser2))
         {     
$handle $userRow2[1];
             
$location $userRow2[7];
            
$fname $userRow2[4];
            
$lname $userRow2[5];
            
$age $userRow2[8];
            
$method $_GET['strMethod']; } } }
?>
<tr><td width='100%' bgcolor='#66B4F4'>Edit Profile</td></tr>
<table width="34%" border="0">
  
  <form action="index.php?page=editprofile&strMethod=update&username=<?php echo $handle?>" method="post">
    <input type="hidden" name="what" value="process">
    <tr> 
      <td width="16%"><strong>UserName&nbsp;&nbsp;</strong></td>
      <td><?php echo $handle?></td>
    </tr>
    <tr> 
      <td width="16%"><strong>Location&nbsp;&nbsp;</strong></td>
      <td><input type="text" name="strLocation" value="<?php echo $location?>"></td>
    </tr>
    <tr> 
      <td width="16%"><strong>Age&nbsp;&nbsp;</strong></td>
      <td><select name="strAge" value="<?php echo $age?>">
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30+">30+</option>
        </select></td>
    </tr>
    <tr> 
      <td width="16%"><strong>First&nbsp;Name&nbsp;&nbsp;</strong></td>
      <td><input type="text" name="strFirstName" value="<?php echo $fname?>"></td>
    </tr>
    <tr> 
      <td width="16%"><strong>Last Name&nbsp;&nbsp;</strong></td>
      <td><input type="text" name="strLastName" value="<?php echo $lname?>"></td>
    </tr>
    <tr> 
      <td width="16%"></td>
      <td><input type="submit" value="Edit"></td>
    </tr>
  </form>
<td width='84%'><font size="1">Note : User Names can be changed... for a price. The only other option is to delete your profile and start all over.</td></tr></table>
                        
<?php

}
 
if(
$IsLoggedIn)
 {    
  
$strMethod $_GET['strMethod'];
  
$strEditMethod $_GET['strEditMethod'];
    switch(
$strMethod)
        {
            case 
"adminEdit":
                
MatchUp();
                break;
                case 
"update":
                
update();
                break;
            default:
                
NoMatchUp();
                break;
        }
    } else {
    echo 
'You are not authorized to view this page. 
    This is most likely due to not being 
    <a href="index.php?page=login">Logged In</a>.'
;
    }
//mysql_free_result($Recordset1);
?>

thanks for the help guys

Reply With Quote
  #6  
Old July 2nd, 2003, 12:08 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
any help?

hey guys anyone know what the problem is?

Reply With Quote
  #7  
Old July 2nd, 2003, 12:52 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
In SQL, Strings require single quotes around them, as do dates.

Reply With Quote
  #8  
Old July 2nd, 2003, 01:02 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
PHP Code:
<?php

  $strQuery 
.= "UPDATE users SET";
  
$strQuery .= " firstname = '" $_POST['strFirstName'] . "'" .
               
",lastname  = '" $_POST['strLastName']  . "'" .
               
",location  = '" $_POST['strLocation']  . "'" .
               
",age       = '" $_POST['strAge'];
  
$strQuery .= " WHERE " .
               
"username   = '" $handle "'" .
               
";";

  print 
$strQuery;

?>

Reply With Quote
  #9  
Old July 4th, 2003, 06:28 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
thanks guys

WHEW after much trying and failing and trying again it works. okay thanks a lot you guys.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > update/ delete in a db


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |