Jump to content

scottybwoy

Members
  • Posts

    532
  • Joined

  • Last visited

    Never

Posts posted by scottybwoy

  1. tried trim already no joy, does anyone have a working script that may be a bit better, they wouldn't mind posting me.  The strange thing is it's the same php engine working on the script and it's the same browser posting the data, has me baffled.

  2. Your problem is is the html form, where it says action="<?php echo $_SERVER['localhost']; ?>"

     

    That is not a page that deals with the script, all that is the server hosting your script, you should just point it to something like index.php or whatever you have.

     

    By the way you can condense your script a bit here :

    <?php
    if (isset($_POST['submitted'])) {
    
    foreach($_POST as $k => $v) {
    
    $array[$k] = trim(strip_tags($v));
    
    }
    
    $dbid = mysql_connect ('db1118.perfora.net(server)', 'xxxusername', 'xxxpassword');
    
      mysql_select_db("databasename",$dbid);
    
    etc...
    ?>
    

     

    That will put all your vals in a nice little array to work with, look in the manual for foreach and arrays to see how they work, happy proggin

  3. This is what is invoked when login is clicked:

    <?php
    $username = $_POST['username'];
    $password = $_POST['password'];
    $password = md5($password);
    Central::login($username, $password);
    ?>
    

     

    This is the login script:

    <?php
    
    function login($username, $password) {
    	echo $password;
    	$sql = "SELECT f_name FROM members WHERE email = '" . $username . "' AND password = '" . $password . "'";
    
    	if ($qry = mysql_query(mysql_real_escape_string($sql))) {
    		$_SESSION['USERNAME'] = mysql_result($qry, 0);
    	} else {
    		trigger_error("You did not enter valid credentials, Please try again.", E_USER_WARNING);
    	}
    }
    ?>
    

     

    The echo is just to tell me what it's looking for.  Should be really simple.

    Can you see where it's going wrong?

  4. hmm, well no i'm not using a js md5 func, it's pure php.  The php md5's the pass during signup and converts the one entered at login, however the one created at signup is 5f4dcc3b5aa765d61d8327deb882cf99 and when inserted at login returns d41d8cd98f00b204e9800998ecf8427e

     

    Any more suggestions?

  5. I have a signup form that encrypts the password into md5 format, which then stores it in to the database.

     

    I then have a login section that translates the password into md5 to check against the stored version.  However the one that is entered and posted via a password field, results in a different md5 hash, is this due to the nature of the password field or post, if so what is the best way to store an encrypted password and then compare it?

     

    Thanks in advance.

  6. lol, i have been using mssql and it's functions for about a yr now, it is uncommented.  But I want to use this odbc function to retrieve a list of tables in the db.

     

    How am I meant to call the dns.  I have tried IP @ddy, domain.fqns_servername and localhost,port all return the same error.

  7. For a start you need to have <form action='yourscript.php' method='post'> that deals with recieving the data.  Then you need to assign the data to the $var like $username = $_POST['username']; in your script and make it global so your html can find it by putting global $username at the top of yourscript.php

     

    Please go and read w3c schools on html forms and php so you will understand

  8. Hi All,

     

    Not posted in here for a while, and should probably post it in another section, but this forum is fast and the one of the best I know, well done everyone.

     

    Well back to my issue.  I'm trying to connect to MSSQL Server 2005 using this code:

    <?php
    $dbh = odbc_connect("mri.local.mri-server", "user", "pass");
    ?>
    

     

    And get this error :

     

    PHP Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in D:\Inetpub\wwwroot\testing\classes\template.inc on line 105

     

    Is there any additional things I need to install or do?

     

    The php manual suggests that it requires additional libraries to be installed, but doesn't specify.  Any pointers?

  9. Yes that sounds like a viable option.  I was not aware that you could post arrays via post.

     

    However it appears that you can't unless I am doing it wrong.  My form creates the input fields like so :

    <?php
    echo "<input type='text' value='$v' name='" . $modelId . "['" . $k . "']' style='width:45px; text-align:center;' />";
    ?>
    

     

    Which produces the table correctly and the input fields look like so :

     

    <input type='text' value='0' name='KVM1.8['cost']' style='width:45px; text-align:center;' />

    <input type='text' value='1' name='KVM1.8['distPrice']' style='width:45px; text-align:center;' />

    <input type='text' value='2' name='KVM1.8['specialPrice']' style='width:45px; text-align:center;' />

    <input type='text' value='3' name='KVM1.8['reselPrice']' style='width:45px; text-align:center;' />

    <input type='text' value='4' name='KVM1.8['rrp']' style='width:45px; text-align:center;' />

     

    However the a print_f on the returned array seems to only hold the last value (rrp) for the whole array like so :

     

    Array ( [KVM1_8_] => 4 [KVM3_0_] => 6 ...  ... )

     

    Any ideas, how to get around this?

  10. This one is proving a bit too tough for me, hope some of you clever ones out there can show me the light.

     

    I have a big form that lists all our products.  Each product has 5 values : Cost, Dist, Special, Resel, & RRP.

     

    The form for updating the values easily as prices can change on a monthly basis.

     

    However when the form is sent as just one big array.  What I need to do is break this down into an array for each product.

     

    There are two ways I have tried to break this down, but I just can't get it to work.

     

    The first way I tried was by sending the model Id with the column name separated by a ',' and then exploding it, but I couldn't quite work out the grouping.

     

    The second way I tried was to send the model Id as it's own readonly input field, but again couldn't work out how to do the count of 6 fields to group them together.  Here is some code for you to get to grips with it.  Thanks for you time.

    This generates the form

    <?php
    function priceList() {
    global $sql;
    $sql = mssql_query("SELECT * FROM proType");
    
    echo "<table style='width:100%; border:solid 1px navy; border-collapse:collapse;'><tr><th>Model Id</th><th>Cost</th><th>Distrib</th><th>Special</th><th>Resell</th><th>RRP</th></tr>";
    while ($row = mssql_fetch_assoc($sql)) {
    	$tpId = $row['pTypeId'];
    	$type = $this->selectRecord('pType', 'proType', 'pTypeId', $tpId);
    	echo "<tr><th colspan='6' bgcolor='navy'><font  color='white'>$type</font></th></tr>";
    
    	$qry = "SELECT modelId, cost, distPrice, specialPrice, reselPrice, rrp FROM products WHERE endOfLine = 'False' AND pTypeId = $tpId";
    	$iSql = mssql_query($qry);
    
    	while ($iRow = mssql_fetch_assoc($iSql)) {
    		$i++;
    
    		if ($this->isodd($i)) {
    			echo "<tr class='row1'>";
    		} else {
    			echo "<tr class='row2'>";
    		}
    
    		foreach ($iRow as $k => $v) {
    /*				if ($k == 'modelId') {
    				$modelId = $v;
    			} --// Method 1  */
    
    			echo "<td padding='1.5px' align='right'>";
    			if (is_float($v)) {
    //					echo "<center><input type='text' value='" . $v . "' name='" . $modelId . "," . $k . "' style='width:45px; text-align:center;' /></center>"; --// Method 1
    				echo "<center><input type='text' value='" . $v . "' name='" . $k . "' style='width:45px; text-align:center;' /></center>";
    
    			} else {
    //					echo $modelId; --// Method 1
    				echo "<input type='text' value='" . $v . "' name='modelId' style='width:100%; text-align:right;' readonly/>";
    			}
    
    			echo "</td>";
    		}
    
    		echo "</a></tr>";
    	}
    
    }
    
    echo "</table>";
    }
    ?>
    

     

    And this is what tries to break it down and build the new array.  Method 1.

    <?php
    
    function updatePrice($update) {
    
    unset($update['content']);
    unset($update['update']);
    
    $products = array();
    
    function makeArray($val, $key) {
    	global $products;
    
    	$arr = explode(',', $key);
    	$modelId = $arr[0];
    	$header = $arr[1];
    
    	if (!is_array($products[$modelId])) {
    		$modelId = array();
    		array_push($products, $modelId);
    	} else {
    		$products[$modelId][$header] = $val;
    	}
    
    }		
    
    array_walk_recursive($update, 'makeArray');
    print_r($products);
    
    }
    

    Method 2.

    <?php
    function updatePrice($update) {
    
    unset($update['content']);
    unset($update['update']);
    
    foreach ($update as $k => $v) {
    	for ($i = 0; $i < 6; $i++) {
    		if ($k = 'modelId') {
    			$modelId = $v;
    			$modelId = array();
    		} else {
    			array_push($modelId, $v);
    		}
    	}
    }
    }
    ?>
    

     

    As you can probably see neither of these work.  The closest I have got is by having lots of little arrays of two key => value pairs and have not been able to push them together.  Any help would be greatly received, I've been working on this for over a day now.

  11. Why does an include(CONSTANT); work in a single level function but not within a dual level function.

     

    Examples:

    <?php
    
    class Aclass {
    
    function levelone() {
    
    include(WILL_WORK);
    
    }
    
    }
    //=====================//
    function levelone() {
    
    if ($inc == "inside $this->levelone()) {
    
    include(WONT_WORK);
    
    }
    
    }
    
    }
    ?>
    

  12. There are many ways to do it, an easy way is to do something like this:

    <?php
    echo <<<END
    <div id='nav'>
    <a href="home.php?nav=a">nav1</a>
    <a href="home.php?nav=b">nav2</a>
    <a href="home.php?nav=c">nav3</a>
    <a href="home.php?nav=d">nav4</a>
    <a href="home.php?nav=e">nav5</a>
    </div>
    END;
    ?>
    

     

    Then in home.php have a switch case function like :

    <?php
    
    switch ($nav) {
    case a:
    include page1.php;
    break;
    case b:
    include page2.php;
    break;
    case c:
    include page3.php;
    break;
    case d:
    include page4.php;
    break;
    case e:
    include page5.php;
    break;
    default :
    }
    ?>
    

     

    But I suggest you look these up in the php manual pages to get better understanding, happy coding

     

     

  13. Hi Daniel,

     

    I mean that the result in the database is a 0, when I call via a SELECT Query, It fails and triggers the Defined error in my code.

     

    It works fine when the result in the database is not 0.

     

    When entering the same SELECT query directly into MsSQL it reters the 0 as expected.

     

    It seems as if the error is not with the php or MsSQL but the way they communicate with each other.

  14. Now if I run an echo $sql and put that value in MSSQL query editor it returns the value 0 fine, now why does PHP throw up an error?  Also if the value is anything else it will execute and return the result.

  15. Small Question

     

    I have a little function that gets a result from a query when supplied arguments, it works great except when the result is 0.  Here's the func :

    <?php
    function selectRecord($record, $tbl, $where, $val) {
    
    $sql = "SELECT $record FROM $tbl WHERE $where = $val";
    $qry = mssql_query($sql);
    $res = mssql_result($qry, 0, 0) or trigger_error("There was an error selecting $record for $val", E_USER_ERROR);
    
    return $res;
    }
    ?>
    

    When ever it tries to return a 0 it triggers the SQL error.  Any one know why?

  16. Yeah, thanks for all your help.  But I figured I was looking in the wrong place.  For some reason all my timestamps are creating the same date.  I'll need to see why that is.

     

    My problem was not that it's displaying the date wrong, just the wrong date

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