Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Drop Down Executes Query On Post?

  • This topic is empty.
Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #170743
    MBM
    Participant

    I’m having problems debugging following the use of error_reporting(E_ALL);

    Warning: mysql_query() expects at most 2 parameters, 3 given on line 29

    Warning: Cannot modify header information – headers already sent on line 34

    if(mysql_query ($DBName, $Query, $Link)){
    $message = "Thank you for your comments";
    header("Location: snickers.php?message=$message");
    }else{
    $message = "Error Inserting!";
    header("Location: snickers.php?message=$message");
    

    So I changed it to :

    if(mysql_query ($query, $Link)){
    $message = "Thank you for your comments";
    header("Location: snickers.php?message=$message");
    }else{
    $message = "Error Inserting!";
    header("Location: snickers.php?message=$message");
    

    Now there are no errors and the data is written but :

    Error Inserting!
    

    Displays after insert.

    #170745
    __
    Participant

    “headers already sent” means you already have output (e.g., you’ve echoed something), and so you can no longer use functions that send headers (e.g., header()).

    As for mysql_query, $query,$Link is the correct order (and number) of args. If it returns false (and because you see your “error inserting!” message, it seems it has), then there was an error in your database. Use mysql_error to get the error message from the database.

    #170747
    MBM
    Participant
    $message = "Error Inserting!" . mysql_error();
    header("Location: snickers.php?message=$message");
    

    Gives :

    Error Inserting!You Have An Error In Your Sql Syntax; Check The Manual That Corresponds To Your Mysql Server Version For The Right Syntax To Use Near \'1\' At Line 1
    

    Line 1.

    <?php

    So I’m guessing it’s a syntax error somewhere else however the query does execute and writes data into the database.

    I’ve removed all php leaving only this and the error still flags so it has to be in here somewhere.

    <?php
    session_start();
    include ("connect.php");
    require("checkLoginSession.php");
    $message = isset( $_GET['message'] )? $_GET['message']: "";
    //COLLECT POST data
    $formValue=array();
    foreach ($_POST as $key => $value) {
    $formValue[$key] = strip_tags($value);
    $usercomments = nl2br($_POST['usercomments']);
    //Register post backs to repopulate form fields
    $_SESSION['post_vars'][$key] = $value;
    }//close for loop
    if(isset($_POST['Submit'])){
    //Check for empty fields 
    if($formValue['subject']=="" || $formValue['usercomments']=="" || $formValue['rating']==""){
    
    $message = "Please enter data in the form" ;
    header("Location: films.php?message=$message");
    
    }else{
    //Carry on with routine
    $Link = mysql_connect($Host, $User, $Password);
    $user = $_SESSION['UserName'];
    //Inserts the data entered in the form into the db table and records the date and time the comment is posted
    
    $query = mysql_query("INSERT INTO films VALUES ('0', '".mysql_escape_string($user)."','".mysql_escape_string($formValue["subject"])."',NOW(),'".mysql_escape_string($usercomments)."','".mysql_escape_string($formValue["rating"])."','films')"); 
    
    if(mysql_query ($query, $Link)){
    $message = "Thank you for your comments";
    header("Location: films.php?message=$message");
    }else{
    $message = "Error Inserting!" . mysql_error();
    header("Location: films.php?message=$message");
    

    BTW this is not the filter ratings script.

    #170755
    __
    Participant

    BTW this is not the filter ratings script.

    Ahh… useful info.

    $query = mysql_query("INSERT

    Instead of doing it all in one line, write the SQL first, and pass the variable to mysql_query. That way, for troubleshooting, you can print the actual query that MySQL sees:

    $sql = "INSERT {your sql goes here}…";
    
    // for troubleshooting only: remove/comment out when done
    exit( $sql );
    
    $query = mysql_query( $sql );
    

    So I’m guessing it’s a syntax error somewhere else however the query does execute and writes data into the database.

    …really? That doesn’t seem right. Is there a second query anywhere in the code?

    #170784
    MBM
    Participant

    I removed all the other queries! Yes the query was exectuting, the data was written into the table and the while loop retrevied it but I still got the syntax error. It was a syntax error. I removed all the escapes then made sure it worked :

    $query = "INSERT INTO films VALUES ('0', '$user','$formValue[subject]',NOW(),'$usercomments','$formValue[rating]','action')";
    

    Then put them back in.

    $query = "INSERT INTO films VALUES ('0', '".mysql_escape_string($user)."','".mysql_escape_string($formValue[subject])."',NOW(),'".mysql_escape_string($usercomments)."','".mysql_escape_string($formValue[rating])."','action')";
    

    Finally no errors. I ‘finished’ the trading card generator website by the way. It needs a bit of work but the design and functionality is there.

    http://thetradingcardgenerator.com

    #170809
    __
    Participant

    I removed all the escapes then made sure it worked
    Then put them back in.
    Finally no errors.

    There was probably a typo somewhere in the original code that you fixed when you rewrote it. Glad you got it working!

    I ‘finished’ the trading card generator website by the way.

    Cool. Looks pretty good, too. I might suggest keeping the navigation in the same place across all pages (putting it below on some pages makes it look a bit unfinished). Is the whole site supposed to be centered or left-aligned?

    #170879
    MBM
    Participant

    Could you briefly explain what this block of code does for the ratings?

    &lt;style type="text/javascript"&gt;
    $('.rating input[type="radio"]').hover(function() {
      $(this).nextAll('span').removeClass().addClass('jshoverNext');
      $(this).next('span').removeClass().addClass('jshover');
      $(this).prevAll('span').removeClass().addClass('jshover');
    },
    function() {
      $('.rating input[type="radio"] + span').removeClass();
    });
    &lt;/style&gt;
    

    Re the trading cards, I’m not happy with the navigation either. Ideally I want users to be able to see the cards without having to scroll a browser window which is why I moved navigation to the bottom of the screen for those pages. I’ll move the cards to the left of the screen and have navigation elements on the right and use a series of dropdowns (instead of text links) for content.

    The website is left aligned in 1920 x 1080. In other resolutions alignment may be off. I am going to start making changes on it next week. My main aim was to get it online and get a set of cards printed as quickly as possible. I’m not happy with the results as the cards are the same size as playing cards so the text loses clarity although the company did actually offer to integrate a shopping cart and pay me a commission on sales so they must have liked the concept!

    I’ve found a company that print large custom poker cards so will use them and if I’m happy with the results see if we can arrange a deal. I will add several more themes next month. Someone suggested using generic variables then allowing users to create their own fields but I wouldn’t know where to start and I imagine it would require changing most of the code so it’s probably better if I just create the tables manually. I have started to switch to mysqli. The query structure is still puzzling to me.

    #170883
    __
    Participant

    Could you briefly explain what this block of code does for the ratings?

    Switches around class names on your radio buttons when they are hovered over. I don’t know what specific effects it will have; probably changes their appearance somehow.

    <style type="text/javascript">

    Actually, if it really is in a <style> tag, it probably does nothing at all.

    Someone suggested using generic variables then allowing users to create their own fields but I wouldn’t know where to start and I imagine it would require changing most of the code so it’s probably better if I just create the tables manually…

    What he’s talking about is called the EAV (entity-attribute-value) pattern. It’s popular with some people because it allows them to ignore the question of how their database should be designed. Other than that, it has few advantages (but noticeable downfalls).

    The website is left aligned in 1920 x 1080. In other resolutions alignment may be off.

    If the width (1920) is static, the simple solution would be to center-align the whole thing.

    #171031
    MBM
    Participant
    What he’s talking about is called the EAV (entity-attribute-value) pattern. It’s popular with some people because it allows them to ignore the question of how their database should be designed. Other than that, it has few advantages (but noticeable downfalls)."
    

    Thanks. I’ll stick to current structure and focus on adding more functionality.

Viewing 9 posts - 16 through 24 (of 24 total)
  • The forum ‘Back End’ is closed to new topics and replies.