37 users online (0 members and 37 guests)  


  Results 1 to 3 of 3

Related

  1. The sum of two fields    Forum: Website Scripts Forum
    Replies: 4
  2. emailing forms excluding empty fields    Forum: HTML Forum
    Replies: 2
  3. Query REturns Empty    Forum: PHP Forum
    Replies: 1
  4. Replies: 1
  5. The sum of two fields    Forum: HTML Forum
    Replies: 1
  1. #1
    Zorath's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2003
    Posts
    16

    Unhappy Script inserts empty fields into DB

    form.php:
    Code:
    <HTML>
    <HEAD>
    <TITLE>Form</TITLE>
    </HEAD>
    <BODY>
    
    <FORM METHOD="post" ACTION="action.php">
    
    <P>
    <B>Subject:</B><BR>
    <INPUT type="text" name="subject" SIZE="48">
    </P>
    
    <P>
    <B>Message:</B><BR>
    <TEXTAREA name="message" wrap="physical" cols="50" rows="8"></TEXTAREA>
    </P>
    
    <P>
    <B>Date:</B><BR>
    <INPUT type=text name="date" SIZE="48" VALUE="<? echo date("m.j.Y"); ?>">
    </P>
    
    <P>
    <B>Time:</B><BR>
    <INPUT type=text name="time" SIZE="5" VALUE="<? echo date("G:i"); ?>">
    </P>
    
    <P><INPUT TYPE="submit" NAME="submit" VALUE="Submit"></P>
    
    </FORM>
    
    </BODY>
    </HTML>
    action.php:
    Code:
    <?
    $user="root";
    $password="1234";
    $database="maxck";
    
    if(empty($subject) || empty($message)) exit("Empty fields in the form!");
    mysql_connect(localhost,$user,$password)
    mysql_select_db($database)
    
    $subject = addslashes($subject);
    $message = addslashes($message);
    mysql_query("INSERT INTO news (id,subject,message,date,time) VALUES ('$id','$subject','$message','$date','$time')");
    ?>
    Hello. I have PHP, MySQL and Apache installed on my computer, but when I try to run the above script to insert data into a MySQL database it just returns the "Empty fields in the form!" error message. If I remove the line of code that checks for empty fields, it just inserts empty fields into the database (except for the ID tag, wich auto-increments). I can't find any errors in the code above. Maybe it has something to do with that I have everything installed on my own computer and not on a web server...?

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    You should never rely on register_globals being set to ON. In a default install, it is off.

    Exchange $subject for $_POST['subject']

    Try it for all the other fields too, it should work then.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    Zorath's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2003
    Posts
    16
    Thanks a lot Dean! I more or less just copied and pasted the code directly from some site with PHP tutorials and they didn't think about/know that a problem like this could surface.



Tags for this Thread