Jump to content

maxxd

Gurus
  • Posts

    1,662
  • Joined

  • Last visited

  • Days Won

    52

Posts posted by maxxd

  1. I can see the existence of $_GET['id'], the code I need is to set $id in the same script as the PDO query, that is already calling the other values from a form

     

    I think I see what you're saying now. *I think*.

     

    So, you're saying the initial two blocks of code in your original post are on the page with the form output, and the third block of code is on the processing page (the value of the form action property), correct?

     

    My question is, where in the script are $date, $installer, $salesman, $category, and $status set and how? Are the values passed from the form via _POST or _GET? The id value should be in there, assuming it's in the form somewhere (this is usually done with a hidden field in the form itself or pulled directly from a session variable).

     

    Perhaps it would help if you posted a bit more code, like the form itself and the code before the "if($valid){" line.

  2. You're mixing and matching SQL approaches. Replace this bit:

    $sql = "INSERT INTO workorder (name, date, installer, salesman, category, status) values('$id', ?, ?, ?, ?, ?);";
    $q = $pdo->prepare($sql);
    $q->execute(array($date,$installer,$salesman,$category,$status));
    

    with this:

    $sql = "INSERT INTO workorder (name, date, installer, salesman, category, status) values(?, ?, ?, ?, ?, ?);";
    $q = $pdo->prepare($sql);
    $q->execute(array($id,$date,$installer,$salesman,$category,$status));
    

    And it should work.

     

    As an aside, why are you checking the id value in _GET and then assigning it from _REQUEST? If somehow there's an 'id' index in both _GET and _POST, one of them is going to overwrite the other. If the value is set in _GET, pull it from _GET.

  3. You can shorten it a bit like so:

    <?php
    if( is_single() || is_home() || is_page() ):
    ?>
    	<div class='container'></div>
    <?php
    endif;
    ?>
    

    Or you can just put the div in the template pages controlling those particular pages. I think (off the top of my head, so check the template hierarchy on the WordPress site), you'd be looking at index.php for the blog (home) page, single.php or page.php for the other two. I haven't had my second cup of coffee yet and just logged on at work, so I may be mistaken about which files you'll need to target.

  4. PDO  is a full API that integrates and abstracts several different database connection types into a unified and standard interface. While it's not technically a framework, and I'm sure many here would disagree with my statement, it's kind of close to a framework in itself - well, in a way that makes sense to me anyway, so there you go.

     

    If you're looking for something a bit more abstracted with more convenience methods, bells, and whistles, you might want to check out the Doctrine Project DBAL classes.

  5. Just one more thing needed for this - on the page where I am inserting the post data into the mysql database (data from the form posted to this page), I want to add auto increment to $_POST['option'] so its option0, option1, option 2 etc. How can I add the auto increment to this?

     

    Make the text input name an array. That way you can simply loop through the values in your php script. Like so:

    //in the form itself
    for ($i=0;$i<$lim;$i++){
    	print("<input type='text' name='custUrserInput[]' id='{$i}' />");
    }
    
    //processing script
    foreach($_POST['custUrserInput'] as $userValue){
    	print("<p>\$_POST['custUrserInput'][] is {$userInput}</p>");
    }
    

    This way, in your processing script, you don't need to know how many fields the user has added. Just loop through the number that are there and process them individually.

  6. I use this or this technique depending. Typically I've used Ryan Fait's in the past, but I just found the second and haven't tested it as thoroughly - where I have tested it, though, it's worked wonderfully.

  7. This may not be the most efficient solution, but it worked in the couple easy tests I just ran on it:

    $err = "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'cowboy@dfwit.co' for key 'username'' in /var/www/html/dfwit/register.php:36 Stack trace: #0 /var/www/html/dfwit/register.php(36): PDOStatement->execute(Array) #1 {main}";
    $colMarkStart = "' for key '";
    $colMarkEnd = "' in /var/";
    
    $startKey = strpos($err, $colMarkStart) + strlen($colMarkStart); //the first occurrence of the first character in the search string plus the length of the search string
    $endKey = (strpos($err, $colMarkEnd) - 1) - $startKey; //-1 from the end string position to account for the end quote, then subtract the starting position to get the desired span of characters
    $column = substr($err, $startKey, $endKey); //pull that span of characters from the error string
    
    print("<p>Duplicate column : {$column}</p>");
    
  8. Actually, the scenario you're concerned about is exactly what SQL is designed to do, and it does it very quickly. Because you're indexing everything by user ID, that's the only column that needs to be scanned. Of course, speed of transactions can slow down, but that's usually due to bad programming - for instance, selecting every column in a row when only 1 is needed.

     

    Read up on database normalization - a good article or three should shed some light on the situation and why working as you've proposed is actually far more wasteful than working the way you're concerned about working...

  9. If you format and re-read your code, I think you'll see what the issue is.

     

    There are only 2 ways I can see that you're not going to be redirected to ./continue.php - if there's nothing in $_POST['username'], $_POST['email'], and $_POST['p'], or if your e-mail is invalid. You don't have an else clause for any of your prepare() statement checks, so the code skips those parts. Nothing is assigned to $error_msg so, when you check the value of $error_msg, it's empty, and you create a password hash only to fail (and therefor skip) the third prepare statement without an else clause, and lickety-split you're being redirected to ./continue.php.

     

    Try adding

    else{
        $error_msg = 'Yup. Failed a prepare';
    }
    

    after the closing brace of both the

    if ($stmt) {
        ...
    }
    
    

    segments, and the

    if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password) VALUES (?, ?, ?)")) {
        ...
    }
    

    segment of code and see what happens. I'm not saying that exactly this is happening, it just looks to me like the most likely possibility.

  10. Wait, now it sounds like the problem isn't in the code that writes the ID into the header location string, but in the receiving page?

     

    Show us the code you're working on. Without seeing the code that's not working and having a detailed and complete description of what 'working' means in the context of the code and project, folks here are stabbing blindly in the dark and can't help, even though they may want to.

  11.  

    Before solving the javascript challenge I need to get my result into a useable format.

    Each row has three cols and I need each row with the three cols for example and with vars.

    $co-ordinate 1=['KT17', 51.34, -0.24, 4],
    $co-ordinate 2=['KT18', 51.31, -0.26, 5]
    $co-ordinate 3 =['KT19', 51.35, -0.26, 5]
    
    $co-ordinate 1=['$postcode1', $lat1, $long1, 4],etc
    $co-ordinate 2=['$postcode2', 51.31, -0.26, 5]
    $co-ordinate 3 =['KT19', 51.35, -0.26, 5]
     

    So my problem is how to get to that from this,

    Any help appreciated.

    $i=0;
                                while($row = mysql_fetch_assoc($result))
                            {
                                $postcode[$i] = $row['postcode'];
                                $latitude[$i] = $row['latitude'];
                                $longitude[$i]= $row['longitude'];
    
                                 $i++;
                                 echo $poatcode[$i] .'<br/>';
                                 echo$latitude[$i] .'<br/>';
                                 echo $longitude[$i] .'<br/>';
                            }
    

     

    Are you having difficulties with php output for screen or php output for JavaScript?

  12. If you use AJAX to load the page content the lag time shouldn't be too bad depending on the amount and type of content. Obviously if you're loading 1006 large images per page, that's going to drag your page load no matter how you navigate through it. You will have to crack into the History API to enable bookmarking and browser navigation. Also, depending on how you set everything up, you may need to build in additional checks at initial page load to make sure you're loading the proper content in case the user is navigating to a page on your site that's not your home page. For instance, if they've bookmarked a specific page and then use that bookmark next time. The only other thing I'd recommend considering early in your dev cycle is whether and how to handle non-JavaScript browsers. If a user has JS turned off, that could seriously affect the display and functionality of your site. Whether it's worth it to enact a back-up methodology or not is obviously up to you, but it's better to think about at the beginning than the end of things...

  13. If I'm understanding your question properly, in WordPress you'll want to take a look at the register_script(), localize_script(), and enqueue_script() functions fired from the wp_enqueue_scripts action hook.

    function enqueueStuff(){
    	wp_register_script('script_id',$this->getPluginDirectory()."/js/yourJSFile.js");
    	wp_localize_script('script_id','script_data',array(
    		'postCode'=>$this->getPostCode(),
    		'latitude'=>$this->getLatitude(),
    		'longitude'=>$this->getLongitude()
    	));
    	wp_enqueue_script('script_id');
    }
    add_action('wp_enqueue_scripts','enqueueStuff');
    

    Of course, the pathing to your JavaScript file and the methods getting the post code, latitude, and longitude will be different for you - these are random stubs, but that's the basic idea of it.

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