Introduction and question

    Date: 09/26/05 (PHP Community)    Keywords: php, mysql, html, database, sql

    Hi everyone! I've slowly been teaching myself php and mysql over the past few months, but it's slow going, and I tend to learn better from someone teaching me something than I do from a book. I finally got the bright idea today (after having been on LJ for how long? lol) to look for a php help community, and lo and behold, I find you! :D If anyone could help me, I'd be very appreciative.

    Here's the situation: I'm trying to build forms that will gather the information provided, check to make sure that everything necessary is included, and either redirect to an error page or a success page as needed. The html form looks like this (obviously without the spaces):

    < form action="add_entry.php" method="post">
    Subject: < input type="text" name="subject" />
    Text: < textarea rows=6 cols=60 name="text">< /textarea>
    < input type ="submit" name="add_entry" value="Add Entry" />
    < /form>

    add_entry.php looks like this (again, without the spaces):


    include('common.php');
    if(isset($formname) && $formname == 'add_entry'){
    if($subject != '' && $description != ''){
    $dbh=mysql_connect ($host, $user, $pass) or die
    ('I cannot connect to the database because I do not like you' . mysql_error());
    mysql_select_db ($database) or die('I could not find the database you are searching for');
    $query = "INSERT INTO journal
    SET dateadd = NOW(),
    subject = '$subject',
    message = '$description'";
    mysql_query($query);
    mysql_close($dbh);
    $redirect = 'success.html';
    }
    else{
    $redirect = 'error.html';
    }
    }
    else{
    $redirect = 'error.html';
    }

    < html>
    < head>
    < meta http-equiv="Refresh" content="1;url=< ?php echo $redirect ?>" />
    < /head>
    < /html>

    My problem is that it never seems to go through the mysql query and always redirects to the error page. I know that the query is good--I've checked it through phpMyAdmin--so I'm thinking it has something to do with the isset.

    Any help would be greatly appreciated! :D

    Source: http://www.livejournal.com/community/php/347463.html

« Converting time to seconds || sendfile in PHP »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home