Jump to content

paul2463

Members
  • Posts

    955
  • Joined

  • Last visited

    Never

Posts posted by paul2463

  1. you would not call the function direct, you would post the values back to the page and have the function at the top of the page, first of all checking to see if the posted value match what is needed

     

    if (isset($_POST['purchase']))
    {
    $amended = reduceItem($_POST['id'], $_POST['qty']); 
    if ($amended == 1)
    {
    	echo "Table updated";
    }
    else
    {
    	echo "For some reason table not updated";
    }
    unset $_POST['id']; // to prevent refresh
    unset $_POST['qty'];
    }
    

  2. something like this??

     

    function reduceItem($id, $qty)
    {
    $query = "UPDATE tablename SET quantity = quantity - '$qty' WHERE tableid = '$id'";
    if ($result = mysql_query($query))
    {
    	$rows = mysql_affected_rows($result);//should be equal to 1 or 0 as an id is being used
    }
    else
    {
    	$rows = 0; // unable to carry out query set affected rows to 0
    }
    return $rows;
    }
    
    $amended = reduceItem(14, 1); //reduce item 14 by 1
    echo $amended; //1 if the reduction has happened, 0 if no rows affected or error with the query
    

  3. change this line

    $account = mysql_query("SELECT * FROM members WHERE MemberRef='$MemberRef' AND  Password='$Password'");
    

     

    to read

     

    $account = mysql_query("SELECT Password FROM members WHERE MemberRef='$MemberRef' ");
    

     

    so it pulls the password for that selected MemberRef, before you were checking to see if both the memberRef and Password existed, this would never happen if you input a wrong password

     

    hope that helps

  4. change this bit

    if (isset($_POST['submit']) && $error_stat == 0) {  
    
    $account = mysql_query("SELECT * FROM members WHERE MemberRef='$MemberRef' AND  Password='$Password'"); 
    
    if ($MemberRef != $Password) {
    
        $error_stat = 1; 
    
    //Set the message to tell the user to enter a username 
    $Password2_message = '*Incorrect Password*';
    }    
    }
    

     

    to this, i have put some comments in so you should be able to follow it through

    if (isset($_POST['submit']) && $error_stat == 0) {  
    
    $account = mysql_query("SELECT * FROM members WHERE MemberRef='$MemberRef' AND  Password='$Password'");
    $numrows = mysql_num_rows($account); //get rows returned
    if ($numrows > 0)// if more than 0 its in database, if not throw new error message
    { 
    $row = mysql_fetch_assoc($result);
    $dbpassword = $row['Password']; //get the password from the database
    if ($dbpassword != $Password) { // check it agains the inputted password, if not the same
    
        $error_stat = 1; 
    
    //Set the message to tell the user to enter a username 
        $Password2_message = '*Incorrect Password*'; 
    
    
    
    
    }
    }
    //new error message
    $error_stat = 1;
    $new_message = "MemberRef and Password do not exist";  
    }
    

  5. i am confused as to what you are checking....

    so $MemberRef and $password come from the post variable

    then you run a query to select everything from the database that match the two variables

    then you check to see if $MemberRef does not equal $password

     

    are you trying to get the password from the database and check to see if the entered password matches the one in the database?

  6. try this then, you will notice I have added an "or die" statement to the queries to make sure they are doing what they should and are not failing inside the function and also changed the name of each query and corrsponding calls to that query to save any possible mix up of data

    function fcsteaches()	{
    
    include 'config.php';
    
    //Connect to apache server(MySQL) and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    //get the avg eaches per bay
    $query1 = "SELECT quantity FROM frcstqunt";
    $result1 = mysql_query($query1) or die ("Error in query 1" . mysql_error());
    while ($row1 = mysql_fetch_assoc($result1))
    {
    $arrayqunt[] = $row1['quantity']; 
    }
    
    //sort the array values
    rsort($arrayqunt);
    
    //get number of locations from currentlocations
    $query2 = "SELECT * FROM currentlocations";
    $result2 = mysql_query($query2) or die ("Error in query 2 " . mysql_error());
    $numrows2 = mysql_num_rows($result2);
    
    //slice array so only top movers are left
    $arrayslice = array_slice($arrayqunt, 0, $numrows2);
    
    //sum array
    $arrayfinal = array_sum($arrayslice);
    
    //get number of bays from locsperbay
    $query3 = "SELECT * FROM locsperbay";
    $result3 = mysql_query($query3) or die ("error in query 3 . mysql_error());
    $numrows3 = mysql_num_rows($result3);
    
    $avgfcsteaches = $arrayfinal/$numrows3;
    
    return $avgfcsteaches;
    }//end function
    ?>
    

  7. I think the problem is that you cannot have a function send header information from within the function, unless you can put the "exit;" after the header call. it seems that the answer to the function is "false" and therefore it is sending that header data, then it comes back from the function and tries to send the header info again. it would be better if your function just returned either true or false and then based on that answer send the user to where he/she needs to go

    if ($returnvalue == FALSE)
    {
    header('Location: http://www.runningprofiles.com/members/error.php');
    }
    else
    {
    header('Location: http://somewhereelse.php');
    }
    

  8. move the style below the includes

    <?php  
    ini_set('error_reporting', E_ALL);
    session_start(); 
    include ("../header.php");         
    require_once '../settings.php';
    $id = $_SESSION['user_id']; 
    ?>
    
    <style type="text/css">
    <!--
    body {
        margin-left: 1px;
        margin-top: 1px;
        margin-right: 1px;
        margin-bottom: 1px;
    }
    -->
    </style> 
    <table colspan='0' width="100%" cellpadding="0" bgcolor="#FFFFFF">
    <tr>
    	<td  width="13%" height="505" align="center" valign="top"><table width="100%" height="505" align="center" bgcolor="#D6E0E0">
    <tr>
    	<td height="58" colspan="2" align="center" valign="top" bgcolor="#D6E0E0"><p>Menu</p>
    			<p><? if($id == 1){ echo "<a href=\"admin/index.php\">Admin Index</a>\n";}?></p>
    	</td>
    </tr>
    <tr>
    		<td height="361" colspan="2" align="center" valign="top" bgcolor="#D6E0E0"><a href="http://www.runningprofiles.com/logout.php">Logout</a>
    		</td>
    </tr>         
    </table>
    </td>
    <td width="87%" align="left" valign="top">
    <?php 
    if (isset($_GET['section'])) {
      $section = $_GET['section'];
    } else {
      $section = 'main';
    }
    $file = "include/".$section.".php";
    if (file_exists($file)) {
        require($file);
    } 
    ?>
    </td>
    </tr>      
    </table>
    </td>
    </tr>
    </table>
    

  9. if you are doing a second check i believe you have to use elseif because as far as I was aware it went

    if (bananas are yellow)
    {
    eat them
    }
    else
    {
    there are any colour than yellow and are not fit to eat
    }
    

     

    if you wish to add another check it should be

    if (bananas are yellow)
    {
    eat them
    }
    elseif (bananas are green)
    {
    leave them a while then eat them
    }
    else
    {
    there are any colour than yellow or green and are not fit to eat
    }
    

     

    hope that helps

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