Jump to content

toonz

Members
  • Posts

    26
  • Joined

  • Last visited

Posts posted by toonz

  1. I got it! Here is the code that I got to work

    <?php
    //Include Common Files @1-8E58AE89
    define("RelativePath", "..");
    include(RelativePath . "/Common.php");
    include(RelativePath . "/Template.php");
    include(RelativePath . "/Sorter.php");
    include(RelativePath . "/Navigator.php");
      
    //End Include Common Files
    
    error_reporting(E_ALL); 
    ini_set('display_errors', 1);
    
    //echo var_dump($_POST);
    
    // foreach ($_POST as $key => $value) {
    //  echo '<p>'.$key.'</p>';
    //  foreach($value as $k => $v)
    //  {
    //  echo '<p>'.$k.'</p>';
    //  echo '<p>'.$v.'</p>';
    //  echo '<hr />';
    //  }
    //} 
    
    $con = mysqli_connect("localhost",yada yada yada) or die ("could not connect to mysql");
    
    if ($sPOST= $_POST['retired']) {
    $aFromPOST = explode (',',$sPOST);
    //echo var_dump($aFromPOST) .'is retired';
    	
    	global $show_id, $con;
    	$show_id = trim($aFromPOST[1]);
    	
    	//header( "Refresh:3; url=books.php?show_id=".$show_id, true, 303);
    	mysqli_query($con,"UPDATE ttb_books SET status_id = '2' WHERE show_id='".$show_id."'");
    	mysqli_close($con);
    	header("Location:books.php?show_id=".$show_id);
    	die();
    
    } elseif ($sPOST= $_POST['upcoming']){
    $aFromPOST = explode (',',$sPOST);
    //echo var_dump($aFromPOST) .'is upcoming';
    		
    	global $show_id;
    	$show_id = trim($aFromPOST[1]);
    	
    	//header( "Refresh:3; url=books.php?show_id=".$show_id, true, 303);
    	mysqli_query($con,"UPDATE ttb_books SET status_id = '37' WHERE show_id='".$show_id."'");
    	mysqli_close($con);
    	header("Location:books.php?show_id=".$show_id);
    	die();
    
    } elseif ($sPOST= $_POST['current']){
    $aFromPOST = explode (',',$sPOST);
    //echo var_dump($aFromPOST) .'is current';
    		
    	global $show_id;
    	$show_id = trim($aFromPOST[1]);
    	
    	//header( "Refresh:3; url=books.php?show_id=".$show_id, true, 303);
    	mysqli_query($con,"UPDATE ttb_books SET status_id = '1' WHERE show_id='".$show_id."'");
    	mysqli_close($con);
    	header("Location:books.php?show_id=".$show_id);
    	die();
    }
    
    
    ?>

     

  2. I changed the 'retired' part of the IF statement to 

    if ($sPOST= $_POST['retired']) {
    $aFromPOST = explode (',',$sPOST);
    //echo var_dump($aFromPOST) .'is retired';
    
    	//echo '<p>'. $aFromPOST[0];
    	//echo '<p>'. $aFromPOST[1];
    	
    	global $show_id, $con;
    	$show_id = trim($aFromPOST[1]);
    	
    	//header( "Refresh:3; url=books.php?show_id=".$show_id, true, 303);
    	$sql = "UPDATE ttb_books SET status_id = '2' WHERE show_id='".$show_id."'"; //the code is dying here
    	
    	  if (!mysqli_query($sql,$con)) {  
        die('<p>Error: ' . mysqli_error());  
    	}
    	
    	$db = new database();
    	$db->mysqli_query($sql, $con);
    	header("Location:books.php?show_id=".$show_id);
    	die();
    
    }

     

    to test the connection and it's not spitting out any errors in the output. It shows "Error:" with nothing after it, so I can't tell if it's a connection issue or a sql issue

  3. Ok, I completely changed the layout and it seems to be dying at the $sql line. Below is the updated code. The echo outputs are showing the exact values I need based on the button being clicked, and the $show_id is capturing the correct value.

     

    The form on the html page:

                  <center><table width=25%>
                  <tr><td valign="top" align="center">
    
                  <!-- ---- retired --- -->
                  <form method="post" action="updatethis.php" name="form1">
                  <input type="image" src="../images/icon-Red_Light.png" width="20" name="retired" alt="Set status to Out of Print" title="Set status to Out of Print" onclick="return confirm('Set ALL status to Out of Print?')">
                  <input name="retired" type="hidden" value="retired,{show_id}">
                  </form>
                  </td><td valign="top" align="center">
    
                  <!-- --- upcoming --- -->
                  <form method="post" action="updatethis.php" name="form2">
                  <input type="image" src="../images/icon-Yellow_Light.png" width="20" name="upcoming" alt="Set status to Upcoming Release" title="Set status to Upcoming Release" onclick="return confirm('Set ALL status to Upcoming Release?')">
                  <input name="upcoming" type="hidden" value="upcoming,{show_id}">
                  </form>
                  </td><td valign="top" align="center">
    
                  <!-- --- current --- -->
                  <form method="post" action="updatethis.php" name="form3">
                  <input type="image" src="../images/icon-Green_Light.png" width="20" name="current" alt="Set status to In Print" title="Set status to In Print" onclick="return confirm('Set ALL status to In Print?')">
                  <input name="current" type="hidden" value="current,{show_id}" >
                  </form>
                  </td></tr>
                  </table></center>

     

    updatethis.php

     

    <?php
    //Include Common Files @1-8E58AE89
    define("RelativePath", "..");
    include(RelativePath . "/Common.php");
    include(RelativePath . "/Template.php");
    include(RelativePath . "/Sorter.php");
    include(RelativePath . "/Navigator.php");
      
    //End Include Common Files
    
    
    if ($sPOST= $_POST['retired']) {
    $aFromPOST = explode (',',$sPOST);
    //echo var_dump($aFromPOST) .'is retired';
    
    	echo '<p>'. $aFromPOST[0];
    	echo '<p>'. $aFromPOST[1];
    	
    	global $show_id;
    	$show_id = trim($aFromPOST[1]);
    	
    	header( "Refresh:3; url=books.php?show_id=".$show_id, true, 303);
    	$sql = "UPDATE ttb_books SET status_id = '2' WHERE show_id='".$show_id."'"; //the code is dying here
    	$db = new database();
    	$db->myquery($sql, 1);
    	//header("Location:books.php?show_id=".$show_id);
    	die();
    
    } elseif ($sPOST= $_POST['upcoming']){
    $aFromPOST = explode (',',$sPOST);
    //echo var_dump($aFromPOST) .'is upcoming';
    	
    	echo '<p>'. $aFromPOST[0];
    	echo '<p>'. $aFromPOST[1];
    	
    	global $show_id;
    	$show_id = trim($aFromPOST[1]);
    	
    	header( "Refresh:3; url=books.php?show_id=".$show_id, true, 303);
    	$sql = "UPDATE ttb_books SET status_id = '37' WHERE show_id='".$show_id."'";
    	$db = new database();
    	$db->myquery($sql, 1);
    	//header("Location:books.php?show_id=".$show_id);
    	die();
    
    } elseif ($sPOST= $_POST['current']){
    $aFromPOST = explode (',',$sPOST);
    //echo var_dump($aFromPOST) .'is current';
    	
    	echo '<p>'. $aFromPOST[0];
    	echo '<p>'. $aFromPOST[1];
    	
    	global $show_id;
    	$show_id = trim($aFromPOST[1]);
    	
    	header( "Refresh:3; url=books.php?show_id=".$show_id, true, 303);
    	$sql = "UPDATE ttb_books SET status_id = '1' WHERE show_id='".$show_id."'";
    	$db = new database();
    	$db->myquery($sql, 1);
    	//header("Location:books.php?show_id=".$show_id);
    	die();
    }
    
    
    ?>

    I only have the header above the sql as a test, to redirect after I see the echo output to verify it sees which of the 3 form buttons I am clicking. They will be commented back out after I get this operational. In the current code, it loads fine, displays the output, then sends me back to where I was after a few seconds. When I comment the first header and echos out and open up the bottom headers, the page won't load and gives a 500 error. So something about the $sql line it crashing it, but I can't see why. I've compared it to tons of other similar statements online and it looks the same. Can someone spot something I am missing? Thank you again for the help.

     

     

  4. 36 minutes ago, ginerjm said:

    So  now show us the code immediately surrounding this new code that is supposed to output the post data so we can see if you did it correctly

    For future reference - when advised to make coding changes it is important to show us what you did so we don't have to ask.

    This is what it looks like now

     

    	function UpdateAllShowBooks()
    	{
    	echo "<pre>"; print_r($_POST); echo "</pre>";
    			
    	if(strlen(($_POST['retired'])) > 0){
    		
    	$sql = "UPDATE ttb_books SET status_id = '2' WHERE show_id='$show_id'";
    	$db = new database();
    	$db->myquery($sql, 1);
    	header('Location:books.php?show_id=$show_id');
    	die();
    		}
    		
    	if(strlen(($_POST['upcoming'])) > 0){
    
    	$sql = "UPDATE ttb_books SET status_id = '37' WHERE show_id='$show_id'";
    	$db = new database();
    	$db->myquery($sql, 1);
    	header('Location:books.php?show_id=$show_id');
    	die();
    		}
    		
    	if(strlen(($_POST['current'])) > 0){
    
    	$sql = "UPDATE ttb_books SET status_id = '1' WHERE show_id='$show_id'";
    	$db = new database();
    	$db->myquery($sql, 1);
    	header('Location:books.php?show_id=$show_id');
    	die();
    		}
    			
    	}

     

  5. 17 minutes ago, requinix said:

    Wherever you put this new PHP code that didn't work, you can't put it there because it doesn't support PHP code.

    It needs to go in books.php. Yes I know the stuff to detect that the image was clicked isn't working, and in order to figure out why I'm saying you need to have that new bit of code run. So put it inside UpdateAllShowBooks, but not inside any of those if blocks. Then you try clicking the image like normal, except this time you should get some output that shows you the POST array. It still won't work. Don't care, just want the output for now.

    If UpdateAllShowBooks isn't running at all then you have some other problem, but I don't think that's the case.

    Just tried putting it in the function, but not in one of the IF statements. Page doesnt load now; HTTP ERROR 500

     

    EDIT: I got the page to load with it in the function now, but there is no output displayed after I click on a POST image

     

  6. 15 minutes ago, requinix said:

    Did you put it in books.php? That's where it needs to be, since that's where the form is going.

    The php function already doesnt recognize the form POST, so if I don't use the <?php  ?> in the HTML file itself, nothing would even register and display

  7. 10 minutes ago, requinix said:

    Use a function like print_r or var_dump on $_POST, then do a View Source of the page so you can see the raw output (which won't be nicely formatted HTML... probably).

    I tried using this above the form in the html file

     

    <?php echo "<pre>"; print_r($_POST); echo "</pre>"; ?>

    but it displays on the page like this on reload, so it isnt recognizing it as php code

    "; print_r($_POST); echo ""; ?>

     

    what changes do I need to make to my original code in order for it to be posting properly to the underlying function?

  8. 1 minute ago, requinix said:

    Dump out the contents of $_POST to see what values are actually being sent through the form. It won't be what you expect.

    I tried using echo before in the html file but it wasnt loading anything. How do I display the POST value so I can actually see it when I reload the html file in the browser? Thank you

  9. I am trying to have an UPDATE query run when I click an image on a web page. I just need to have the image call the function to run the mysql from the corresponding php file. The image is a form object, which I need the php function to recognize when it is clicked, and then run the query(ies) within. I don't really know much php, so the php code is based on a snippet I have from one of my other sites, which works fine over there, but I am missing something here that is keeping it from doing the same here.

    The page already loads and displays all values in a list associated with $show_id, so that variable is already being pulled from the web page in to the php code. I'm not going to paste the entire books.php file here as there are too many things it does which doesnt have anything to do with this little add-on I am making. I just need to be able to pull that variable in to the query below and have it run when I click on the icon associated with it. The php file also already has the proper config and settings files linked to it that connect to the database, so I do not need to set that up here. It is just a form, calling a function, and running the query. It is also not visible to the user side. It is in an admin page, only visible and accessible to me.

    This is code I have in the php file:

        function UpdateAllShowBooks()
        {
        if(strlen(($_POST['retired'])) > 0){
    
        $sql = "UPDATE ttb_books SET status_id = '2' WHERE show_id='$show_id'";
        $db = new database();
        $db->myquery($sql, 1);
        header('Location:books.php?show_id=$show_id');
        die();
            }
            
        if(strlen(($_POST['upcoming'])) > 0){
    
        $sql = "UPDATE ttb_books SET status_id = '37' WHERE show_id='$show_id'";
        $db = new database();
        $db->myquery($sql, 1);
        header('Location:books.php?show_id=$show_id');
        die();
            }
            
        if(strlen(($_POST['current'])) > 0){
    
        $sql = "UPDATE ttb_books SET status_id = '1' WHERE show_id='$show_id'";
        $db = new database();
        $db->myquery($sql, 1);
        header('Location:books.php?show_id=$show_id');
        die();
            }
        }

    This is the current image/form html:

                  <center><table width=25%>
                  <tr><td valign="top" align="center">
                  <!--<form method="post" action="books.php?show_id={show_id}">-->
                  <form method="post" action="books.php" name="retired">
                  <input type="image" src="../images/icon-Red_Light.png" width="20" name="retired" alt="Set status to Out of Print" title="Set status to Out of Print" onclick="return confirm('Set ALL status to Out of Print?')">
                  <input name="shid1" type="hidden" id="shid1" value="{show_id}" />
                  </form>
                  </td><td valign="top" align="center">
                  <form method="post" action="books.php" name="upcoming">
                  <input type="image" src="../images/icon-Yellow_Light.png" width="20" name="upcoming" alt="Set status to Upcoming Release" title="Set status to Upcoming Release" onclick="return confirm('Set ALL status to Upcoming Release?')">
                  <input name="shid2" type="hidden" id="shid2" value="{show_id}" />
                  </form>
                  </td><td valign="top" align="center">
                  <form method="post" action="books.php" name="current">
                  <input type="image" src="../images/icon-Green_Light.png" width="20" name="current" alt="Set status to In Print" title="Set status to In Print" onclick="return confirm('Set ALL status to In Print?')">
                  <input name="shid3" type="hidden" id="shid3" value="{show_id}" />
                  </form>
                  </td></tr>
                  </table></center>

    So clicking on the form image would call the function with that mysql string and update all items in the list accordingly. At this time, when I click the image, it reloads the page fine, but it is not activating the sql in the function and making the Update occur. Thank you for any help you can provide. I really appreciate it.

  10. Thanks in advance to those who can help with this!!

    I have code in a php file that pulls values from a table to display in a dropdown field in a form

         $rarity = $dbObj->cgs("tbl_rarity", "", "del_status", "0","rarity_name","",false);
      while($row_rarity = @mysql_fetch_array($rarity))
      {   
          $rarity_id[] = $row_rarity['id'];
          $rarity_value[] = $row_rarity['rarity_name'];
          $rarity_min[] = $row_rarity['price_from'];
          $rarity_max[] = $row_rarity['price_to'];
      }
      $smarty->assign("rarity_id", $rarity_id);
     $smarty->assign("rarity_value", $rarity_value);
     $smarty->assign("rarity_min", $rarity_min);
     $smarty->assign("rarity_max", $rarity_max);

    The code works fine and does what I need on the user form. There is also a field on the user form for PRICE, which is
     

       <input type="text" name="price" id="exD_price"/>

     

    Right now, I have to manually enter a value in that field of my choosing. The goal is to have it take the $rarity_min and $rarity_max values associated with the chosen rarity from the dropdown menu, and automatically insert a value in the price field that falls within the range of the min and max numbers, and each time I change a value in the dropdown it generates a new number and inserts it in to the price field.

    In the php code I tried creating something
     

     $rprice=rand($rarity_min, $rarity_max);

    and had added a value to the <input /> like value="{$rprice}", but after I select an option in the dropdown, nothing appears in the price field. I imagine there has to be an OnUpdate sort of function that needs to be called after the dropdown value is changed, but how do I do that in php?

×
×
  • 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.