SQL Statement not executing?

Discussion in 'PHP' started by Sleeping Troll, Sep 16, 2008.

  1. #1
    This is my entire server side script, I have echoed values back to alert box on page to check validity and all is as it should be, but highlighted code does not update my table? What is up? I really hope it is something simple that a moron could spot in a heartbeat, humility would beat the hell out of frustration at this point!

    <?php
    $conn = mysql_connect("xxx","xxx","xxx"); 
    mysql_select_db("xxx",$conn);
    $ClientID = $_COOKIE["user"];
    
    //Get Project Info
    $SQL="Select * From Projects where ClientID = $ClientID and Status = 'Current'";
    $result = mysql_query($SQL);
    $row = mysql_fetch_array($result);
    $ProjectID = $row[0];
    $TemplateID = $row[2];
    
    //Store Input Text
    $TextID = $_GET["TextID"];
    $Text = $_GET["Text"];
    [COLOR="Red"]$SQL="Update ProjectText Set Text = '$Text' Where ProjectID = $ProjectID and TextID = $TextID";
    mysql_query($SQL);[/COLOR]
    
    //Get Stored Text
    $SQL="Select Text From ProjectText Where ProjectID = $ProjectID";
    $result = mysql_query($SQL);
    $texts = mysql_fetch_array($result);
    
    //Scaling to match Preview
    $Inch = 24;
    $overlay = imagecreatefrompng("Images/Overlay_Blanks/24x36.png");
    $red = imagecolorallocate($overlay, 255, 0, 0);
    $black = imagecolorallocate($overlay, 0, 0, 0);
    
    
    //Set Overlay Destination
    $TextOverlays = "Images/Text_Overlays/$ProjectID.png";
    
    $SQL="Select * From Templates Where TemplateID = $TemplateID";
    $result = mysql_query($SQL);
    $Cnt=mysql_fetch_row($result);
    for($i=0;$i<$Cnt[3];$i++)
    {
    		$SQL="Select * From Texts Where TemplateID = $TemplateID and TextID = $i";
    		$result = mysql_query($SQL);
    		$row = mysql_fetch_array($result);
    		$PosLeft = $row[2]*$Inch; 
    		$PosBottom = $row[3]*$Inch;
    		$PosWidth  = $row[4]*$Inch;
    		$PosHeight  = $row[5]*$Inch;
    		$Font  = "Fonts/$row[6]";
    		$Color  = $row[7];
    		$Shadow = $row[8]; 
    		$SQL="Select * From ProjectText Where ProjectID = $ProjectID and TextID = $i";
    		$result = mysql_query($SQL);
    		$row = mysql_fetch_array($result);
    		//Create Cropped Overlay Image
    		imagettftext($overlay , 36 , 0 , $PosLeft , $PosBottom, $red , $Font , $texts[$i]);
    }
    
    //Save TextOverlay
    imagesavealpha($overlay, true);
    imagepng($overlay,$TextOverlays);
    
    //Set Destination for Preview Image
    $preview = "Images/Previews/$ProjectID.png";
    
    //Create Copy of Project Template for Project Preview
    $ProjectPreview = imagecreatefrompng("Images/Project_Templates/$ProjectID.png");
    
    //Create Copy of Photo Overlay
    $Photo = imagecreatefrompng("Images/Photo_Overlays/$ProjectID.png");
    
    //Create Copy of Text Overlay
    $Text = imagecreatefrompng("Images/Text_Overlays/$ProjectID.png");
    
    //Paste Text Overlay 
    imagecopy($ProjectPreview,$Text,0,0,0,0,570,864);
    
    //Paste Photo Overlay
    imagecopy($ProjectPreview,$Photo,0,0,0,0,570,864);
    
    //Save Preview
    imagesavealpha($ProjectPreview, true);
    imagepng($ProjectPreview,$preview);
    ?>
    Code (markup):
     
    Sleeping Troll, Sep 16, 2008 IP
  2. Hade

    Hade Active Member

    Messages:
    701
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    90
    #2
    echo out the SQL statement after it has been contructed to debog. like so:

    $SQL="Update ProjectText Set Text = '$Text' Where ProjectID = $ProjectID and TextID = $TextID";
    die($SQL);
    mysql_query($SQL);


    Then use it manually on your database using a MySQL command line or PHPMyAdmin.
    Let me know how it goes
     
    Hade, Sep 16, 2008 IP
  3. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    How it went? OK this is the server side of an ajax script. So on the client side I had to modify the javascript to save the value in a text box rather than alerting it got all my editing done and save d and my editor crashed.
    Got it back up, oops! Have to log back in to godaddy.com and mysql, Geez is that ridiculously slow in loading!
    OK now lets see... SQL is updating! ???? >???????>?? I have been all morning trying to resolve this, and it looks like Godaddy's mysql server was responsible?

    This is crazy, code is back to what I posted and now it is working fine... Anybody know what is up? I don't need another morning wasted this way!!!
     
    Sleeping Troll, Sep 16, 2008 IP
  4. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Now this part of code is returning squat!!!

    $SQL="Select Text From ProjectText Where ProjectID = $ProjectID";

    and I have echoed copied pasted and tested and it works fine!!!
     
    Sleeping Troll, Sep 16, 2008 IP
  5. Hade

    Hade Active Member

    Messages:
    701
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    90
    #5
    I wouldn't name a column 'Text' as that may be reserved in PHP. Rename it to 'Title' or 'Desc' or something.
     
    Hade, Sep 16, 2008 IP
  6. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Or use backticks:

    Select `Text` From ....

    Jay
     
    jayshah, Sep 16, 2008 IP