Jump to content

Php help :( link img


VazNih

Recommended Posts

<?php
    $xtpl_quangcao   = new XTemplate('views/quangcao.htm');
        If(isset($_SESSION['admin'])){
   
            // show thong tin cu
            $query  = "SELECT * FROM img_header WHERE id=1 AND stt=1";
			
            $result     = mysqli_query($conn, $query);
            while($row = mysqli_fetch_object($result)){
                        $xtpl_quangcao ->assign('old_img1', $row->img);
                        $xtpl_quangcao ->assign('old_linkto1', $row->link);
                        
                         }   
            if(isset($_POST['submit'])){
                $link1      = $_POST['linkto1'];
                $sql    = "UPDATE img_header SET link = '" . $link1 . "' WHERE id = '1'  ";
                $result = mysqli_query($conn, $sql);
                
                if($_FILES["up"]["name"] != NULL){
                   
                    $imgname = $_FILES["up"]["name"];
                    $linkimg = 'images/'.$imgname;    
                    move_uploaded_file($_FILES["up"]["tmp_name"],'images/'.$_FILES["up"]["name"]);
                    
                    $sql    = "UPDATE img_header SET img = '" . $linkimg . "' WHERE id = '1'  ";
                    $result = mysqli_query($conn, $sql);
                    if($result){
                        header("Location:index.php?page=index&module=quangcao");
                    }
                    else{
                        echo 'loi';
                        die();
                    }
                }
                else {
                 
                }
                    
                }             

            // show thong tin cu
            $query  = "SELECT * FROM img_header WHERE id=2 AND stt=1";
			
            $result     = mysqli_query($conn, $query);
            while($row = mysqli_fetch_object($result)){
                        $xtpl_quangcao ->assign('old_img2', $row->img);
                        $xtpl_quangcao ->assign('old_linkto2', $row->link);
                        
                         }   
            if(isset($_POST['submit'])){
                $link1      = $_POST['linkto2'];
                $sql    = "UPDATE img_header SET link = '" . $link1 . "' WHERE id = '2'  ";
                $result = mysqli_query($conn, $sql);
                
                if($_FILES["up1"]["name"] != NULL){
                   
                    $imgname = $_FILES["up1"]["name"];
                    $linkimg = 'images/'.$imgname;    
                    move_uploaded_file($_FILES["up1"]["tmp_name"],'images/'.$_FILES["up1"]["name"]);
                    
                    $sql    = "UPDATE img_header SET img = '" . $linkimg . "' WHERE id = '2'  ";
                    $result = mysqli_query($conn, $sql);
                    if($result){
                        header("Location:index.php?page=index&module=quangcao");
                    }
                    else{
                        echo 'loi';
                        die();
                    }
                }
                else {
                 
                }
                    
                }     
    $xtpl_quangcao -> parse('QUANGCAO');
    $content    = $xtpl_quangcao -> text('QUANGCAO');              
            }

    //
	

Problem is

When link a link abc.com with img A. everything works great // abc.com ( A )

but when link : 123.com with img B. img A can not link to abc.com anymore  // 123.com ( B ) none link (A)

Sry 4 my bad english :

Link to comment
https://forums.phpfreaks.com/topic/288106-php-help-link-img/
Share on other sites

the problem is because your form processing code isn't testing which form has been submitted. all you are testing is - if(isset($_POST['submit'])){ for both forms.

 

when the second form is submitted, $_POST['linkto1'] and $_FILES["up"]["name"] don't exist, but your php code for the first form is running and updating the row WHERE id = '1' with empty values.

 

you must detect which form has been submitted and only run the correct piece of php code. the best way of doing this is to use a hidden form field with a different name attribute for each form. you would then change the two if(isset($_POST['xxxxxxx])){ lines to test for the correct name.

Link to comment
https://forums.phpfreaks.com/topic/288106-php-help-link-img/#findComment-1477604
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.