Page 3 of 6 FirstFirst 123456 LastLast
Results 33 to 48 of 81

Thread: Review system

  1. #33
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts
    he, sorry, i wasnt very specific!!

    first off the id is set in the url ie index.php?id=2

    second, the problem is that nothing is being inserted into the db, otherwise it seems fine

    and more info on includes and a function call would be greatly appreciated

    Im fiddling with the code atm, but if you still want it ill post it up a bit later

    thanks, neil
    (\__/)
    (='.'=)
    (")_(")

  2. #34
    www.dougmcdonald.co.uk
    Join Date
    May 2007
    Location
    Bath
    Posts
    523
    Thanks
    5
    Thanked
    20 times in 20 posts
    • DougMcDonald's system
      • Motherboard:
      • Asus P5B Deluxe
      • CPU:
      • Inter Core 2 Duo E6600
      • Memory:
      • 2 x 2GB - Geil Black Dragon PC6400
      • Storage:
      • 2 x 400GB Samsung Spinpoints (Running in Matrix array) 100GB @ RAID0 + 300GB @ RAID1
      • Graphics card(s):
      • BFG nVidia 8800GTS 320MB OC2
      • PSU:
      • Corsair HX520W modular
      • Case:
      • Lian-Li PC7 II Plus
      • Monitor(s):
      • LG 17" Flat Thingy
      • Internet:
      • Crappy BT 1MB Unreliable wank :s
    It would certainly be worth attempting the insert via the myPHPAdmin interface, does the SQL throw any errors?

    I do remember encountering a similar issue in the past *digs around for old code* ah yes, I remember, try setting your query string to a variable, then putting some basic error catching around it, like this:

    PHP Code:
            $sql "INSERT INTO restreview VALUES 
            ('
    $id','$name_rev','$email_rev','$rating_rev','$review_rev')";      
            print(
    $sql);

            
    mysql_query($sql) or die ('I cannot update the database because: ' mysql_error()); 
    Also, if you echo/print your query, ($sql) what does it show?

    First glance would suggest you need to escape the string for the query better. I would think when you reference the variables you would want syntax more like this:

    PHP Code:
            $sql "INSERT INTO restreview VALUES 
            (" 
    $id "," $name_rev "," $email_rev "," $rating_rev "," $review_rev")";      
            print(
    $sql); 
    Last edited by DougMcDonald; 02-08-2007 at 12:42 PM.

  3. Received thanks from:

    nvening (02-08-2007)

  4. #35
    Member
    Join Date
    Nov 2006
    Posts
    103
    Thanks
    10
    Thanked
    6 times in 6 posts
    • jamiesalter's system
      • Motherboard:
      • Abit IP35 Pro
      • CPU:
      • Intel Q6600 (w/ Scythe ninja @ 3Ghz)
      • Memory:
      • 4 x 1Gb Corsair PC2-6400
      • Storage:
      • 1 x WD 500GB AAKS
      • Graphics card(s):
      • XFX 8800GTS (w/ Thermalright HR-03 PLUS)
      • PSU:
      • Corsair 620Watts
      • Case:
      • CM690
      • Monitor(s):
      • HannsG 216D (21.6")
    I've just knocked this up quickly so it may not work perfectly

    There are two files...one of which is include.php which contains the connection information needed to access the database. This file (include.php) should be placed in the directory above the current file for security.

    Include.php:
    PHP Code:
    <?php

    function db_connect()
    {
       
    $username "";
       
    $password "";
       
    $database "";
        
       
    $handle mysql_connect ("localhost""$username""$password") or die ('I cannot connect to the database because: ' mysql_error());
       
    mysql_select_db('gkelly_siteopening'$handle) or die('Could not select database.');
       return 
    $handle;
    }

    ?>

    Product.php:
    PHP Code:
    <?php
    //Include a file include.php which is above the current directory (so can't be accessed directly from a browser = more security)
    require_once('../include.php');

    if(isset(
    $_POST['validation'])) {
        
        
    //Put ID in URL into $id variable
        
    $id $_REQUEST['id'];
        
        
    $name_rev=$_POST['name'];
        
    $email_rev=$_POST['email'];
        
    $rating_rev=$_POST['rating'];
        
    $review_rev=$_POST['review'];
        
        
    //Check if the form was filled out correctly...if not print an error and change $error variable to true
        
    $error false
        
    if (empty($name_rev)){echo 'You forgot to enter your name'$error true;}
        if (empty(
    $email_rev)){echo 'You forgot to enter your email'$error true;}//remove this line if the email isn't necessary
        
    if (empty($review_rev)){echo 'You forgot to write a review'$error true;}
        
        
    //Only continue if the form was filled out correctly
        
    if ($error false){
        
        
    //Do some basic handling of submitted stuff:
        //Make sure the rating is a number
        
    $rating_rev=doubleval($rating_rev);
        
    //Add slashes to the text to prevent problems occuring [remember to use stripslashes(...) when printing the review]
        
    $email_rev=addslashes(email_rev);
        
    $review_rev=addslashes(review_rev);
        
    $name_rev=addslashes(name_rev);
        
        
    //Open database connection by calling function in include.php
        
    $dbh=db_connect();
        
        
    $query_review "INSERT INTO restreview VALUES ('$id','$name_rev','$email_rev','$rating_rev','$review_rev')";
        
        
    //Run the query and if it fails print an error
        
    if (!$result $mysql_query($query_review)){
        
    $echo 'An error has occured.  Please try again later.';
        } else {
        echo 
    'Your review was successfully submitted';
        }
        
        }
    //end if ($error = false){...

        
    mysql_close();
    }
    ?>
    <h1>Your Details:</h1>

    <form action="product.php?id=<? echo $id?>" method="post">
    <span class="det">Name:</span> <input style="margin-left: 5px;" type="text" name="name"><br/>
    <span class="det">Email:</span> <input style="margin-left: 7px;" type="text" name="email"> <span class="det">(will not be displayed)</span><br/>

    <span class="det">Rating:</span> <select name="rating">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3" selected="selected">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select>
    <br/>
    <h1>Review:</h1>
    <textarea rows="5" cols="50" name="review">
    Enter your review here
    </textarea>
    <input type="hidden" name="validation" value="1"/>
    <p style="margin-left: 50px;" >
    <input type="submit" value="Submit" >
    <input type="reset" value="Reset">
    </p>
    </form>
    Hope this helps

    Jamie

  5. Received thanks from:

    nvening (02-08-2007)

  6. #36
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts
    wow, thanks jamie!

    ive fixed a missing ; which was throwing up and error however i can seem to fix this part:

    //Run the query and if it fails print an error
    if (!$result == mysql_query($query_review)){
    $echo 'An error has occured. Please try again later.';
    } else {
    echo 'Your review was successfully submitted';
    }

    as you can see ive tried adding the extra = and removing the $ as as afaik that how it should be, but im still getting an error - however i dont really understand where the $result variable is coming from or what the ! is for??

    The error is Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

    thanks
    (\__/)
    (='.'=)
    (")_(")

  7. #37
    Member
    Join Date
    Nov 2006
    Posts
    103
    Thanks
    10
    Thanked
    6 times in 6 posts
    • jamiesalter's system
      • Motherboard:
      • Abit IP35 Pro
      • CPU:
      • Intel Q6600 (w/ Scythe ninja @ 3Ghz)
      • Memory:
      • 4 x 1Gb Corsair PC2-6400
      • Storage:
      • 1 x WD 500GB AAKS
      • Graphics card(s):
      • XFX 8800GTS (w/ Thermalright HR-03 PLUS)
      • PSU:
      • Corsair 620Watts
      • Case:
      • CM690
      • Monitor(s):
      • HannsG 216D (21.6")
    Try this instead:
    PHP Code:
        //Run the query
        
    $result $mysql_query($query_review);
        
    //Check for an error
        
    if (!$result){ 
        
    $echo 'An error has occured.  Please try again later.'
        } else { 
        echo 
    'Your review was successfully submitted'
        } 
    The ! in an IF statement is the PHP's negation operator which means it flips a false value to true and vice versa. So in this example, if the query doesn't run correctly and $result is returned as false, then the ! in the IF statement flips it to true. This means 'An error has occured...' is echoed.

    If it still doesn't work, I'll look at it further.
    Last edited by jamiesalter; 02-08-2007 at 02:36 PM.

  8. Received thanks from:

    nvening (02-08-2007)

  9. #38
    www.dougmcdonald.co.uk
    Join Date
    May 2007
    Location
    Bath
    Posts
    523
    Thanks
    5
    Thanked
    20 times in 20 posts
    • DougMcDonald's system
      • Motherboard:
      • Asus P5B Deluxe
      • CPU:
      • Inter Core 2 Duo E6600
      • Memory:
      • 2 x 2GB - Geil Black Dragon PC6400
      • Storage:
      • 2 x 400GB Samsung Spinpoints (Running in Matrix array) 100GB @ RAID0 + 300GB @ RAID1
      • Graphics card(s):
      • BFG nVidia 8800GTS 320MB OC2
      • PSU:
      • Corsair HX520W modular
      • Case:
      • Lian-Li PC7 II Plus
      • Monitor(s):
      • LG 17" Flat Thingy
      • Internet:
      • Crappy BT 1MB Unreliable wank :s
    Just for you infomation Niel, the exclamation mark means 'no' or 'not'

    In this example, it means 'no' !$variable_name, you would use this to establish whether or not a variable exists.

    You could also use the exclamation mark to mean 'not' using something like this if ($my_variable != 10) to establish when $my_variable is not equal to ten

    EDIT: Beaten to it!
    Last edited by DougMcDonald; 02-08-2007 at 02:42 PM. Reason: Beaten to it!

  10. Received thanks from:

    nvening (02-08-2007)

  11. #39
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts
    ah, well that fixed one problem jamie!!

    However im now getting this:

    Warning: mysql_close(): no MySQL-Link resource supplied in /home/gkelly/public_html/stives/product.php on line 350

    when i try and submit the form, erm, ill google it as well but i cant make out what its talking about!!

    thanks
    (\__/)
    (='.'=)
    (")_(")

  12. #40
    www.dougmcdonald.co.uk
    Join Date
    May 2007
    Location
    Bath
    Posts
    523
    Thanks
    5
    Thanked
    20 times in 20 posts
    • DougMcDonald's system
      • Motherboard:
      • Asus P5B Deluxe
      • CPU:
      • Inter Core 2 Duo E6600
      • Memory:
      • 2 x 2GB - Geil Black Dragon PC6400
      • Storage:
      • 2 x 400GB Samsung Spinpoints (Running in Matrix array) 100GB @ RAID0 + 300GB @ RAID1
      • Graphics card(s):
      • BFG nVidia 8800GTS 320MB OC2
      • PSU:
      • Corsair HX520W modular
      • Case:
      • Lian-Li PC7 II Plus
      • Monitor(s):
      • LG 17" Flat Thingy
      • Internet:
      • Crappy BT 1MB Unreliable wank :s
    You are getting this message because the connect statement is only executed when the

    PHP Code:
    if(isset($_POST['validation'])) 
    evaluates to true.

    You have two options here, either move the

    PHP Code:
        //Open database connection by calling function in include.php
        
    $dbh=db_connect(); 
    To outside (before) the:

    PHP Code:
    if(isset($_POST['validation'])) 
    Statement.

    This will force a db connect even if the form is not submitted. A better way to solve this, would be to move the close command to inside the if statement.

    Move this:
    PHP Code:
     mysql_close(); 
    to above the close brackets on the if(isset) statement so the last few lines read like this:

    PHP Code:
        echo 'Your review was successfully submitted';
        }
               
    mysql_close();    
        }
    //end if ($error = false){...




  13. Received thanks from:

    nvening (02-08-2007)

  14. #41
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts
    ok, thats fixed the error but its still not submitting anything to the database, it also does not say its submitted correctly or to try again later. - i have the include setup with my correct password and everything


    on a brighter note ive just completely sorted out all the sites files (old ones cluttering everything out) and converted the pages so that the layout/ nav bar etc is kept in two include files which are used for each page, making maintenance and construction much easier!

    Hopefully that should stop me getting so muddled up in all this code!!

    Furthermore once ive got this php script sorted out is it best to combine all the scripts into one and place it before everything else - assuming its possible with how ive set it out??

    thanks!
    (\__/)
    (='.'=)
    (")_(")

  15. #42
    www.dougmcdonald.co.uk
    Join Date
    May 2007
    Location
    Bath
    Posts
    523
    Thanks
    5
    Thanked
    20 times in 20 posts
    • DougMcDonald's system
      • Motherboard:
      • Asus P5B Deluxe
      • CPU:
      • Inter Core 2 Duo E6600
      • Memory:
      • 2 x 2GB - Geil Black Dragon PC6400
      • Storage:
      • 2 x 400GB Samsung Spinpoints (Running in Matrix array) 100GB @ RAID0 + 300GB @ RAID1
      • Graphics card(s):
      • BFG nVidia 8800GTS 320MB OC2
      • PSU:
      • Corsair HX520W modular
      • Case:
      • Lian-Li PC7 II Plus
      • Monitor(s):
      • LG 17" Flat Thingy
      • Internet:
      • Crappy BT 1MB Unreliable wank :s
    In terms of file locations, i often keep a main 'library.php' file with generic functions in it such as displaynavigation(), displayfooter() connectoDB() etc etc and include this on all pages calling the functions where needed.

    I would then split like functions into seperate files too, so maybe you would call this one 'review_scripts.php' or something like that, and create seperate ones for other pages.

    What is displayed if you comment out this lot:

    PHP Code:
        $query_review "INSERT INTO restreview VALUES ('$id','$name_rev','$email_rev','$rating_rev','$review_rev')";
        
        
    //Run the query and if it fails print an error
        
    if (!$result $mysql_query($query_review)){
        
    $echo 'An error has occured.  Please try again later.';
        } else {
        echo 
    'Your review was successfully submitted';
        } 
    and replace it with this:

    PHP Code:
    $sql "INSERT INTO restreview VALUES 
            ('
    $id','$name_rev','$email_rev','$rating_rev','$review_rev')";      
            print(
    $sql);

            
    mysql_query($sql) or die ('I cannot update the database because: ' mysql_error()); 
    What does the print($sql); return on screen?

  16. Received thanks from:

    nvening (02-08-2007)

  17. #43
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts
    Nothing is displayed (ie after i submit it just clears the form and refreshes) and nothng is added to the database.



    In responce to your library idea im guessing this would be usefull if you had scripts which you wanted to use multiple times, like classes in css?

    I can see that being very useful but assuming i only needed the scripts which are in the layout files which i have put in seperate include files (im going to call them the header and footer) the once, is there any harm in keeping the scripts with the html in those files?

    Thanks
    Last edited by nvening; 02-08-2007 at 04:20 PM.
    (\__/)
    (='.'=)
    (")_(")

  18. #44
    www.dougmcdonald.co.uk
    Join Date
    May 2007
    Location
    Bath
    Posts
    523
    Thanks
    5
    Thanked
    20 times in 20 posts
    • DougMcDonald's system
      • Motherboard:
      • Asus P5B Deluxe
      • CPU:
      • Inter Core 2 Duo E6600
      • Memory:
      • 2 x 2GB - Geil Black Dragon PC6400
      • Storage:
      • 2 x 400GB Samsung Spinpoints (Running in Matrix array) 100GB @ RAID0 + 300GB @ RAID1
      • Graphics card(s):
      • BFG nVidia 8800GTS 320MB OC2
      • PSU:
      • Corsair HX520W modular
      • Case:
      • Lian-Li PC7 II Plus
      • Monitor(s):
      • LG 17" Flat Thingy
      • Internet:
      • Crappy BT 1MB Unreliable wank :s
    can you load the page and do a 'view source' and paste the resulting HTML here?

    Chances are maybe the form is not posting to the correct location.

    Also, since you main function which will perform the insert it based on the html variable 'validation' try setting a php variable to be the result of that, and echoing it back, what does it display?

    e.g.

    PHP Code:
    $test_variable $_GET['validation'];
    echo 
    "Test variable: " $test_variable

  19. Received thanks from:

    nvening (02-08-2007)

  20. #45
    www.dougmcdonald.co.uk
    Join Date
    May 2007
    Location
    Bath
    Posts
    523
    Thanks
    5
    Thanked
    20 times in 20 posts
    • DougMcDonald's system
      • Motherboard:
      • Asus P5B Deluxe
      • CPU:
      • Inter Core 2 Duo E6600
      • Memory:
      • 2 x 2GB - Geil Black Dragon PC6400
      • Storage:
      • 2 x 400GB Samsung Spinpoints (Running in Matrix array) 100GB @ RAID0 + 300GB @ RAID1
      • Graphics card(s):
      • BFG nVidia 8800GTS 320MB OC2
      • PSU:
      • Corsair HX520W modular
      • Case:
      • Lian-Li PC7 II Plus
      • Monitor(s):
      • LG 17" Flat Thingy
      • Internet:
      • Crappy BT 1MB Unreliable wank :s
    I can see that being very useful but assuming i only needed the scripts which are in the layout files which i have put in seperate include files (im going to call them the header and footer) the once, is there any harm in keeping the scripts with the html in those files?
    No harm in putting includes with plain HTML in there, make sure you end your string with \n (new line) or you'll get ugly long lines.

    e.g. echo "<p>some text</p>\n";

    You could argue that one long line reduces the amount of whitespace and therefore increases the efficiency of the site (which is true, but in my experience the difference is negligible)

  21. Received thanks from:

    nvening (02-08-2007)

  22. #46
    lazy student nvening's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    4,656
    Thanks
    196
    Thanked
    31 times in 30 posts
    printing that variable give nothing - is that the problem then?
    Last edited by nvening; 02-05-2011 at 01:51 PM.
    (\__/)
    (='.'=)
    (")_(")

  23. #47
    www.dougmcdonald.co.uk
    Join Date
    May 2007
    Location
    Bath
    Posts
    523
    Thanks
    5
    Thanked
    20 times in 20 posts
    • DougMcDonald's system
      • Motherboard:
      • Asus P5B Deluxe
      • CPU:
      • Inter Core 2 Duo E6600
      • Memory:
      • 2 x 2GB - Geil Black Dragon PC6400
      • Storage:
      • 2 x 400GB Samsung Spinpoints (Running in Matrix array) 100GB @ RAID0 + 300GB @ RAID1
      • Graphics card(s):
      • BFG nVidia 8800GTS 320MB OC2
      • PSU:
      • Corsair HX520W modular
      • Case:
      • Lian-Li PC7 II Plus
      • Monitor(s):
      • LG 17" Flat Thingy
      • Internet:
      • Crappy BT 1MB Unreliable wank :s
    Yeah it could be,

    one alternative, is to give your submit input item a name e.g.

    Code:
    <input type="submit" name="posted" value="submit"/>
    This will enable you to use:

    PHP Code:
    isset($_GET['posted']) 
    In the place of the 'validated', and should work for you.

    Also, what happens if you print out your SQL query?

  24. Received thanks from:

    nvening (02-08-2007)

  25. #48
    Member
    Join Date
    Nov 2006
    Posts
    103
    Thanks
    10
    Thanked
    6 times in 6 posts
    • jamiesalter's system
      • Motherboard:
      • Abit IP35 Pro
      • CPU:
      • Intel Q6600 (w/ Scythe ninja @ 3Ghz)
      • Memory:
      • 4 x 1Gb Corsair PC2-6400
      • Storage:
      • 1 x WD 500GB AAKS
      • Graphics card(s):
      • XFX 8800GTS (w/ Thermalright HR-03 PLUS)
      • PSU:
      • Corsair 620Watts
      • Case:
      • CM690
      • Monitor(s):
      • HannsG 216D (21.6")
    Place this:
    PHP Code:
    echo 'this is displayed because the form has been submitted'
    below this
    PHP Code:
    if(isset($_POST['validation'])) { 
    to check if the form submitting correctly.

    You could also try changing the above line to:
    PHP Code:
    if(isset($_REQUEST['validation'])) { 
    (remember to change validation to 'posted' if you change the submit button's name)

  26. Received thanks from:

    nvening (02-08-2007)

Page 3 of 6 FirstFirst 123456 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 24-11-2006, 07:40 PM
  2. Mesh Again!!
    By atomicjeep in forum Pre-Built Laptops and Desktops
    Replies: 34
    Last Post: 03-04-2006, 07:54 PM
  3. Abit NF7-S revision 2 information
    By Lee H in forum SCAN.care@HEXUS
    Replies: 22
    Last Post: 30-10-2004, 07:13 PM
  4. Newbie needing help with Barton XP2500+ system...
    By adlamb in forum PC Hardware and Components
    Replies: 17
    Last Post: 12-04-2004, 05:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •