Need help with MySQL Update!!

Discussion in 'PHP' started by tjsocr22, Dec 4, 2009.

  1. #1
    Hey guys,

    I am trying to update an image SRC but I need a little help. This is what I have so far:

    update.php
    <?php
    
    include_once("viewitem.php");
    include_once("../config.inc.php");
    include_once("../db_connect.php");
    
    
    // get vars
            $j    = $_REQUEST['j'];
    	$newimg = $_REQUEST['newimg'];
    
    
    if($submitmetwo) {
    
    
    $query="UPDATE tracks SET email='$newimg' WHERE id='$j'";
    mysql_query($query);
    echo "Record Updated";
    mysql_close();
    	
    	
    	}	
    
    ?>
    
    PHP:
    viewitem.php

    <?php
    
    include_once("../config.inc.php");
    include_once("../db_connect.php");
    
    // get vars
    $j    = $_REQUEST['j'];
    $r    = $_REQUEST['r'];
    
    
    
    	$get_info  = mysql_query("SELECT * FROM tracks WHERE id = ".$j." LIMIT 1");
    	if($get_info) {
    	  $artist    = mysql_result($get_info, 0, artist);
    	  $title     = mysql_result($get_info, 0, title);
    	  $album     = mysql_result($get_info, 0, album);
    	  if(strlen($album) == 0) $album = "Unknown";
    	  $lyrics    = mysql_result($get_info, 0, lyrics);
    	  $dateadded = mysql_result($get_info, 0, dateadded);
    	  $emailadd  = mysql_result($get_info, 0, email);
    	  $userip    = mysql_result($get_info, 0, ip);
    	
    
    	$ptitle    = substr($joke, 0, 50)."";
    	$meta_keys = "";
    	$meta_desc = "";
    	$selected  = "VIEW";
    
    	include("../header1.php");
    
    ?>
    
    	<table width="100%" cellspacing="5" cellpadding="0">
    	  <tr>
    
    <td>
    <form method="post" action="update.php"><input type="hidden" name="submitmetwo" value="yes">
    <font size='2.5'>New IMG : </font><input type="text" id="textarea" name="newimg" class="form" style="width:130px;" value="<?php echo stripslashes($newimg); ?>">
    <input type="submit" id="submitbutton" value="SUBMIT" class="form">
    </form>
    </td>
    
    
    
    	    <td valign="top">
    		<?php
    		  echo "<table width='100%' cellspacing='0' cellpadding='0'>";
    		  echo "<form method='POST' action='index.php'><input name='item' type='hidden' value='".$j."'><tr><td colspan='2'><b>";
    		  if($r == 1) echo "Random";
    		  else echo "Viewing";
    		  echo " Profile Of ".$artist.":</b><br><br></td><td></td></tr>";
    		  echo "<tr><td width='90'><font class='listingtitle'>Listing:</font></td><td>".$artist."</td><td rowspan='9' valign='top'>
    		 
    		 		  
    		  </td></tr>";
                      echo "<tr><td style='padding-top:4px;'></td><td>&nbsp;</td></tr>";
    		  echo "<tr><td width='90'><font class='listingtitle'>Nickname:</font></td><td>".$album."</td></tr>";
                      echo "<tr><td style='padding-top:4px;'></td><td>&nbsp;</td></tr>";
    		  echo "<tr><td width='90'><font class='listingtitle'>Category:</font></td><td>".$title."</td></tr>";
    		  
    		  echo "<tr><td style='padding-top:4px;'></td><td>&nbsp;</td></tr>";
    		  echo "<tr><td style='padding-top:4px;'><font class='listingtitle'>Date Added:</font></td><td style='padding-top:4px;'>".$dateadded."</td></tr>";
    
    		  echo "<tr><td style='padding-top:4px;'></td><td>&nbsp;</td></tr>";
    		  echo "<tr><td valign='top' style='padding-top:4px;'><font class='listingtitle'>Country:</font></td><td valign='top' style='padding-top:4px;'>".$lyrics."</td></tr>";
    
                      if ( $emailadd == "" ) {
    	echo "";
    } else {
    	echo "<tr><td>Image:</td><td><div align='center'><IMG SRC='$emailadd' height='' width='375'></center></td></tr>"; 
    }
    	
    		  
    		  echo "<tr><td style='padding-top:4px;'></td><td>&nbsp;</td></tr>";
    		  $this_url   = $site_path."view-".$j."-".urlconvert($artist)."_".urlconvert($title).".php";
    		  $this_title = $title." - ".$artist." ";
    		  		  
    		  echo "<tr><td valign='top' style='padding-top:24px;'></td><td valign='top' style='padding-top:24px;'><input name='approve' value='keep' type='submit'>&nbsp;<input name='decline' value='delete' type='submit'></td></tr>";
    		  echo "</form></table>";
    		  
    		?>
    		</td>
    	  </tr>
    	</table>
    	
    <?php
    }
    ?>
    
    <?php
    include("footer.php");
    ?>
    PHP:
    When I enter a value into the "newimg" textbox and press submit it redirects to update.php but nothing happens and nothing executed. Any help on how to get this working??

    Thanks!

    By the way this is the "newimg" text box that I have written and am refering too. It is also in the above code:

     
    tjsocr22, Dec 4, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    'j' is not defined in HTML.

    You are trying to retrieve 'j' from $_REQUEST but since it is not available in HTML, you would be getting it blank and hence UPDATE query is not updating any row.

    Is there something I have overlooked or 'j' is present in HTML but not in code snippet you gave?
     
    mastermunj, Dec 5, 2009 IP
  3. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #3
    also if($submitmetwo) {} not defined
     
    crivion, Dec 5, 2009 IP
  4. tjsocr22

    tjsocr22 Active Member

    Messages:
    1,251
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Thanks for the help! I updated the code but it is still not working. I get the text "Record Updated" but the records don't get updated. Here is what I have now:

    In the viewitem.php
    update.php
    I have been playing with this for 4 hours and still can't get it! Please helpp!

    Thanks!
     
    tjsocr22, Dec 5, 2009 IP
  5. akhil1311

    akhil1311 Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I think you are not getting a value for $artist in update.php. Check whether you are getting a value for $artist. then updation will be ok.
     
    akhil1311, Dec 5, 2009 IP
  6. tjsocr22

    tjsocr22 Active Member

    Messages:
    1,251
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    80
    #6
    Still didn't work :(

    I think the problem exists within locating the files but I don't really know how to to that. I tried incorporating the update into viewitem but the same thing happens and nothing gets updated.
     
    tjsocr22, Dec 5, 2009 IP
  7. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #7
    try replacing query with this

    $query1 = "UPDATE tracks SET email = '".$newimg."' WHERE artist = '".$artist."' ";
     
    crivion, Dec 5, 2009 IP
  8. tjsocr22

    tjsocr22 Active Member

    Messages:
    1,251
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    80
    #8
    Still didn't work :( This shouldn't be that complicated, I think I am messing up on something really simple too. The "Record updated" states but nothing gets updated. Thanks for the help though :)
     
    tjsocr22, Dec 5, 2009 IP
  9. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #9
    put this after mysql_query() line

    print mysql_error();
     
    crivion, Dec 6, 2009 IP
  10. ankit_frenz

    ankit_frenz Active Member

    Messages:
    1,111
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    63
    #10
    Try this

    also use the print_r(mysql_error());
    to debug errors..if you still get any
     
    ankit_frenz, Dec 6, 2009 IP
  11. tjsocr22

    tjsocr22 Active Member

    Messages:
    1,251
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    80
    #11
    Thx for the help =)

    I just ran the Update sql in phpMyAdmin and it worked for inputing the values, my guess is it just doesn't know what "artist" is in my code, but I can't declare what artist is because it requires a mysql_query function.
     
    tjsocr22, Dec 6, 2009 IP
  12. Edgar_fox

    Edgar_fox Active Member

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #12
    There's always many mistakes with ' or " or / in mysql and php codes... so be aware of not making them :)
     
    Edgar_fox, Dec 9, 2009 IP