Jump to content

joel24

Members
  • Posts

    760
  • Joined

  • Last visited

Posts posted by joel24

  1. after the query string put in

     
    $query = "INSERT INTO driversnew (id, name, location, date_of_birth, car_number, favourite_track, least_favourite_track, achievements, sponsors, email, image)
    
    echo $query; 
    exit();
    
    VALUES ('$_POST[id]', '$_POST[name]', '$_POST[location]','$_POST[date_of_birth]', '$_POST[car_number]','$_POST[favourite_track]', '$_POST[least_favourite_track]','$_POST[achievements]', '$_POST[sponsors]','$_POST[email]', '$image_name')";
    
    mysql_query( $query ) or die( '<br>Query string: ' . $query . '<br>Created error: ' . mysql_error() ); 

    so you can view the mysql query and debug

  2. for starters, you're inserting the image_name into the email field, not the image field and also, you need to wrap the values in {} when accessing an array value in quotes, and the index must be wrapped in single quotes i.e. $_POST[id] should be {$_POST['id']}

     

    for that code you need to verify an image is uploaded before you insert the row into the database, and do the changes to the code mentioned above... also it would probably be best to have a default value for that field (image), so that if no value is sent mysql automatically sets it to the default value.

    i.e.

    if ($image_name=='')
    {
    $image_name = "xxx.jpg";
    }
    
    mysql_query("INSERT INTO driversnew (id, name, location, date_of_birth, car_number,
       favourite_track, least_favourite_track, achievements, sponsors, email, image)
    VALUES ('$_POST[id]', '$_POST[name]', '$_POST[location]','$_POST[date_of_birth]', '$_POST[car_number]','$_POST[favourite_track]', '$_POST[least_favourite_track]','$_POST[achievements]', '$_POST[sponsors]','$_POST[email]', '0')");
    
    

  3. you'll need to cycle through a loop and echo out each clip ID/url in the object url.

     

    a foreach loop will cycle through every index in an array, no need for count like in your for loop.

     

    and then if you wish to use the current embed code string, you'll have to replace __YOUTUBE_ID__ with the corresponding youtube id with str_replace()

     

    
    <?php
    
    $number = 0;
    $youtubeIds = array("MX0D4oZwCsA","2v-v3jh-Cco","WuYDSa4BRaw","zwo48StJSr4","exOxUAntx8I");
    
    $embedCode = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/__YOUTUBE_ID__?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/__YOUTUBE_ID__?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
    
    $string = implode($youtubeIds);
    
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/">
    <head>
    <title>Youtube Videos</title>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="language" content="en" />
    </head>
    
    <body>
    <h1>Youtube Videos</h1>
    
    <p><?php
    foreach($youtubeIds as $value)
    {
    //replace
    echo '<div>' . str_replace("__YOUTUBE_ID__", $value, $embedCode) . '</div>';
    } ?> </p>
    </body>
    </html>
    

  4. I don't use PHPmyadmin, I'm sure there is a default value option for each column?

    if you were writing the create table query in SQL, it would look something like

    CREATE TABLE articles (
    
      articleID int(11) NOT NULL auto_increment,
    
      name varchar(50) NOT NULL default '',
    
      articleText TEXT NOT NULL default '',
    
      image varchar(150) NOT NULL default 'default.jpg',
    
      PRIMARY KEY  (articleID)
    
    )
    

     

    ... or if you've already created the table, you can alter it with sql

    ALTER TABLE articles MODIFY image varchar(150) NOT NULL DEFAULT 'default_image.jpg';
    

  5. something like this will get you started.

     

    //text array
    $my500lines = array();
    $tempText = '';
    
    $string = "line 1
    line 2
    ....
    line 3453
    line 3454
    etc...";
    
    $count = 0;
    
    foreach(preg_split("/(\r?\n)/", $string) as $line){
        $count++;
    
    if ($count == 500)
    {
    //reset count and temptext
    $my500lines[] = $tempText;
    $tempText = '';
    $count = 0;
    }
    else
    {
    $tempText .= $line;
    }
    
    }
    
    

  6. you need to enclose the string you wish to echo inside quotes unless they are constants... which they're not in that script

    i.e.

    <?php
    $link = mysql_connect  ('localhost','root', 'PASSWORD');
    if (!$link)
       print "unsuccessful";
    else
       print :successful";
    mysql_close($link);
    ?>
    

  7. i would have a db table like

    articleID | title | articleText | image

     

    with the image column storing the filename of the image, i.e. image1.jpg

     

    I would then wait for the image script to execute and then if that is successful insert the article details into the DB.

    i.e. swap the last part of the upload script to something like

     

    // move file into the directory and the path name into the database// also must execute if no image has been uploadedif (move_uploaded_file($image['tmp_name'], $TARGET_PATH)){        $sql = @mysql_query("INSERT INTO xxx SET rarara = rara, image = {$image['name']}");if ($sql){$success = "successful!";}else{$error = "error!";}        exit;}else{                $_SESSION['error'] = "Could not upload file.  Check read/write persmissions on the directory";                exit;}

     

     

    then you will have to ensure the script is capable of allowing a user to upload an article without an image, i.e. set the mysql image field to default to "default.jpg" and then ensure default.jpg exists in the images folder.

  8. I added the alert (pop box) line in so you could ensure the correct data was being sent to the PHP page.

    you can remove the line "alert(option);" in the jquery / javascript.

     

    as for the 'Array ( [select] => option2 ) ", that is the print_r($_GET); telling us what is being received by $_GET.

     

    You should use a switch statement instead of all your if/else ifs. read about switch here

     

    switch ($_GET['select']) {
        case "option1":
            echo "option1";
            break;
        case "option2":
            echo "option2";
            break;
        case "option3":
            echo "option3";
            break;
    default:
    echo "No Option Selected";
    }
    
    //you can finish switch code to include all your options and their corresponding data
    

     

     

    ######

    and also, the problem in your current code is that you are trying to echo $_GET['select2'], then $_GET['select3'] etc when in your Jquery you are sending the $_GET variables with the index "select" in "select:option"

        $.get('option.php', {select:option}, function(data) {
          $('#result').html(data).hide().fadeIn(1000);
        });
    

     

    if you wish to have it sent via $_GET with index option2, option3 etc, you can change select:option in the jquery to $(this).attr("name") > the name of the form element

    //put in 
    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script><br>
    
    <script type="text/javascript">
    
    $(document).ready(function(){
      $('.select').change(function() {
                            
    var myIndex = $(this).attr("name");
        var option = $(this).val();
    alert(option);
        $.get('option.php', {myIndex:option}, function(data) {
          $('#result').html(data).hide().fadeIn(1000);
        });
      });
    
    });
    </script>
    

  9. //put in 
    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script><br>
    
    <script type="text/javascript">
    
    $(document).ready(function(){
      $('.select').change(function() {
                            
        var option = $(this).val();
    alert(option);
        $.get('option.php', {select:option}, function(data) {
          $('#result').html(data).hide().fadeIn(1000);
        });
      });
    
    });
    </script>
    

     

     

    and then change the PHP script to echo all $_GET values

    <?php
    
    print_r($_GET);
    exit();
    
       // Multiple Selections
    if ($_GET['select'] == 'option1' && $_GET['select2'] == 'option3') {
      echo 'the option you have chosen is 1 and 3';} 
    elseif ($_GET['select2'] == 'option4' && $_GET['select3'] == 'option5' && $_GET['select4'] == 'option7') {
      echo 'the option you have chosen is 4, 5 and 7';}   
      
      // and so on
      
      //Selection 1
      elseif($_GET['select'] == 'option1') {
      echo 'the option you have chosen is 1';} 
      elseif($_GET['select'] == 'option2') {
      echo 'the option you have chosen is 2';} 
      
      //Selection 2
      elseif($_GET['select2'] == 'option3') {
      echo 'the option you have chosen is 3';} 
      elseif($_GET['select2'] == 'option4') {
      echo 'the option you have chosen is 4';} 
    
      //Selection 3
      elseif($_GET['select3'] == 'option5') {
      echo 'the option you have chosen is 5';} 
      elseif($_GET['select3'] == 'option6') {
      echo 'the option you have chosen is 6';} 
    
      // Selection 4
      elseif($_GET['select4'] == 'option7') {
      echo 'the option you have chosen is 7';} 
      elseif($_GET['select4'] == 'option8') {
      echo 'the option you have chosen is 8';} 
    
    ?>
    

     

    this should help you to rectify the problem, knowing what $_GET values are being sent and ensuring they are as they should be.

  10. use htmlentities()

     

     

    *edit: if you want it exactly the same, i.e. not translated with HTML entities, you can wrap the input value in single quotes and ensure none are in the string, or vice-versa i.e.

    $test = '<object height="81" width="100%"> <param value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fgeneralpie%2Fdukebox001&secret_url=false" name="movie"> <param value="always" name="allowscriptaccess"> <embed height="81" width="100%" type="application/x-shockwave-flash" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Fgeneralpie%2Fdukebox001&secret_url=false" allowscriptaccess="always"> </object>';
    
    //html, ensure to wrap in single quotes as $test string contains double quotes.
    <input type='text' value='<?php echo $test; ?>' />
    

  11. should work, the $_SERVER['http_referer'] must not be getting set...

     

    i.e. try this

    //print $_server variables to see that the referer is being set.
    print_r($_SERVER);
    
    //test code
    $xsblock = "http://www.bob.com/testchan";
    $url = "testchan";
    $pos = strpos($xsblock, $url);
    if ($pos == false) {
    echo "not found";
    } else {
    echo "found";
    }
    

     

  12. also, do a print_r($_GET); to ensure that the $_GET values are being sent as suspected.

     

    //remove this line once everything is working
    print_r($_GET);
    
    switch($_GET){
    
    case 'topic':
    include 'modules/pages/posts.php';
    break;
    case 'forum':
    include 'modules/pages/topics.php';
    break;
    case 'parent':
    include 'modules/pages/parents.php';
    break;
    case 'do':
    if ($_GET['do'] == 'unanswered') {
    
    include 'modules/pages/unanswered.php';
    
    } elseif (isset($_GET['do']) == 'today') {
    
    include 'modules/pages/today.php';
    
    }
    break;
    
    //default, include forums page
    default:
    include 'modules/pages/forums.php';
    break;
    
    }
    
    
    

  13. when the session is started, you can set a session variable with the current unix timecode... then check to see if it is more than 1hour past the sign in time...

    session_start();
    
    //log in etc etc
    //when login authenticated, add this line
    $_SESSION['sessionStart'] = time();
    

     

    then in your script where it checks the user is logged in each time a page is viewed, add a line like

    if ((time() - $_SESSION['sessionStart']) > 60*60)
    {
    session_destroy();
    exit("Session expired");
    }
    

  14. ... because isset($_GEt['do']) is returning true, or false.

    so your if statement is transformed to

    elseif (true/false == 'today')

     

    you need to have

    } elseif (isset($_GET['do']) && $_GET['do'] == 'today') {
    

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