Problem with insert command in php script.

Could someone please help me to resolve the following problem... I have written 3 files. There are input.html, input.php, and dbaccess.php. What I intended to do were to let user enter data into specific field, in input.html, then once submitted, the inputs will be posted with ...



..
...



include('dbaccess.php');

mysql_select_db("lotusmsiadb", $db_conn);
$add_enquiry =
"INSERT INTO visitor VALUES( '" . $txtName . "', '" . $txtEmail . "', '" . $txtAddress . "', '" . $txtCity . "', '" . $txtPostcode . "', '" . $cboCountry . "', '" . date("Y-m-d", mktime(0, 0, 0, $txtArrMonth, $txtArrDay, $txtArrYear)) . "', '" . date("Y-m-d", mktime(0, 0, 0, $txtDepMonth, $txtDepDay, $txtDepYear)) . "', '" . $txtAdultQty . "', '" . $txtChildQty . "', '" . $txtEnquiry . "')";

@ $query = mysql_query($add_enquiry, $db_conn);
if (!$query){
echo nl2br("Your enquiry is not process!
");
echo nl2br("Please try again!
");
echo mysql_errno($db_conn) . ": " . mysql_error($db_conn);
}
if ($db_conn){
mysql_close($db_conn);
}
echo nl2br("
Your enquiry will be attended shortly!
");



$id = xxx;
$passwd = xxx;
@ $db_conn = mysql_connect('localhost', $id, $passwd);
if (!$db_conn){
echo "Database connection failed";
exit;
}
else{
return $db_conn;
}


what happen after I have submitted the form was the input.php was loaded but it is a blank page without echo any single thing. Do anyone experience this b4?

Comments

  • : Could someone please help me to resolve the following problem... I have written 3 files. There are input.html, input.php, and dbaccess.php. What I intended to do were to let user enter data into specific field, in input.html, then once submitted, the inputs will be posted with ...
    :
    :
    :
    : ..
    : ...
    :
    :
    :
    : include('dbaccess.php');
    :
    : mysql_select_db("lotusmsiadb", $db_conn);
    : $add_enquiry =
    : "INSERT INTO visitor VALUES( '" . $txtName . "', '" . $txtEmail . "', '" . $txtAddress . "', '" . $txtCity . "', '" . $txtPostcode . "', '" . $cboCountry . "', '" . date("Y-m-d", mktime(0, 0, 0, $txtArrMonth, $txtArrDay, $txtArrYear)) . "', '" . date("Y-m-d", mktime(0, 0, 0, $txtDepMonth, $txtDepDay, $txtDepYear)) . "', '" . $txtAdultQty . "', '" . $txtChildQty . "', '" . $txtEnquiry . "')";
    :
    : @ $query = mysql_query($add_enquiry, $db_conn);
    : if (!$query){
    : echo nl2br("Your enquiry is not process!
    ");
    : echo nl2br("Please try again!
    ");
    : echo mysql_errno($db_conn) . ": " . mysql_error($db_conn);
    : }
    : if ($db_conn){
    : mysql_close($db_conn);
    : }
    : echo nl2br("Your enquiry will be attended shortly!
    ");
    :
    :
    :
    : $id = xxx;
    : $passwd = xxx;
    : @ $db_conn = mysql_connect('localhost', $id, $passwd);
    : if (!$db_conn){
    : echo "Database connection failed";
    : exit;
    : }
    : else{
    : return $db_conn;
    : }
    :
    :
    : what happen after I have submitted the form was the input.php was loaded but it is a blank page without echo any single thing. Do anyone experience this b4?
    :



    I got a couple of tips for ya

    First of all, you don't need to remove variables from strings, you could have written your insert like this:

    "INSERT INTO visitor VALUES( '$txtName', '$txtEmail', '$txtAddress', '$txtCity', '$txtPostcode', '$cboCountry', '" . date("Y-m-d", mktime(0, 0, 0, $txtArrMonth, $txtArrDay, $txtArrYear)) . "', '" . date("Y-m-d", mktime(0, 0, 0, $txtDepMonth, $txtDepDay, $txtDepYear)) . "', '$txtAdultQty', '$txtChildQty', '$txtEnquiry')"

    All those extra quotes makes it extremely difficult to read.



    and it's kind of easier to store the dates like this (instead of useing mktime)

    "date='$txtYear-$txtMonth-$txtDay'"

    That works as long as the database column is of DATE type

    This is your new insert:

    "INSERT INTO visitor VALUES( '$txtName', '$txtEmail', '$txtAddress', '$txtCity', '$txtPostcode', '$cboCountry', '$txtArrYear-$txtArrMonth-$txtArrDay', '$txtDepYear-$txtDepMonth-$txtDepDay', '$txtAdultQty', '$txtChildQty', '$txtEnquiry')"




    I would use the SET clause instead of VALUES myself.. that way i know what columns each index refers to, such as:

    "INSERT INTO visitor SET name='$txtName', email='$txtEmail'"



    A question: what's with all of the nl2br's???????
    If you are echoing a 50k length file (easy on some webpages) you could really slow down the processing if you nl2br every single string you output.

    echo nl2br("Your enquiry is not process!
    ");

    should become

    echo "Your enquiry is not process!
    ";

    Just use '
    ' instead of





    Another tip..
    Unless you are opening a lot of connections to other databases or have a script thats like 100,000kbs long (all in php) that takes a long time to process then you DO NOT need to close your mysql connection. It will close automatically when the page is done.
    (in other words, don't worry about it)



    As for the blank page.. there can be many reasons for a blank page.
    Most likely you did not close a tag (gets me all the time) or a tag.. or all those other heading tags.. (style/script)


    It's most likely that either you have a quote out of place or a tag left open. (is the title of the page listed in your browser?)

    Seeings how it is a white page, it's probably a head tag meaning no body information was sent.



    If you cannot find a problem, save the sourcecode of input.php as (inputSOURCE.txt) and post the link here, i'll have a look at it and see what i can do, okay?
    [b][blue]Snoochie Boochies[/blue][/b]

  • : I got a couple of tips for ya
    :
    : First of all, you don't need to remove variables from strings, you could have written your insert like this:
    :
    : "INSERT INTO visitor VALUES( '$txtName', '$txtEmail', '$txtAddress', '$txtCity', '$txtPostcode', '$cboCountry', '" . date("Y-m-d", mktime(0, 0, 0, $txtArrMonth, $txtArrDay, $txtArrYear)) . "', '" . date("Y-m-d", mktime(0, 0, 0, $txtDepMonth, $txtDepDay, $txtDepYear)) . "', '$txtAdultQty', '$txtChildQty', '$txtEnquiry')"
    :
    : All those extra quotes makes it extremely difficult to read.
    :
    :
    :
    : and it's kind of easier to store the dates like this (instead of useing mktime)
    :
    : "date='$txtYear-$txtMonth-$txtDay'"
    :
    : That works as long as the database column is of DATE type
    :
    : This is your new insert:
    :
    : "INSERT INTO visitor VALUES( '$txtName', '$txtEmail', '$txtAddress', '$txtCity', '$txtPostcode', '$cboCountry', '$txtArrYear-$txtArrMonth-$txtArrDay', '$txtDepYear-$txtDepMonth-$txtDepDay', '$txtAdultQty', '$txtChildQty', '$txtEnquiry')"
    :
    :
    :
    :
    : I would use the SET clause instead of VALUES myself.. that way i know what columns each index refers to, such as:
    :
    : "INSERT INTO visitor SET name='$txtName', email='$txtEmail'"
    :
    :
    :
    : A question: what's with all of the nl2br's???????
    : If you are echoing a 50k length file (easy on some webpages) you could really slow down the processing if you nl2br every single string you output.
    :
    : echo nl2br("Your enquiry is not process!
    ");
    :
    : should become
    :
    : echo "Your enquiry is not process!
    ";
    :
    : Just use '
    ' instead of

    :
    :
    :
    :
    : Another tip..
    : Unless you are opening a lot of connections to other databases or have a script thats like 100,000kbs long (all in php) that takes a long time to process then you DO NOT need to close your mysql connection. It will close automatically when the page is done.
    : (in other words, don't worry about it)
    :
    :
    :
    : As for the blank page.. there can be many reasons for a blank page.
    : Most likely you did not close a tag (gets me all the time) or a tag.. or all those other heading tags.. (style/script)
    :
    :
    : It's most likely that either you have a quote out of place or a tag left open. (is the title of the page listed in your browser?)
    :
    : Seeings how it is a white page, it's probably a head tag meaning no body information was sent.
    :
    :
    :
    : If you cannot find a problem, save the sourcecode of input.php as (inputSOURCE.txt) and post the link here, i'll have a look at it and see what i can do, okay?
    : [b][blue]Snoochie Boochies[/blue][/b]
    :
    :

    I have figure out the problem here. It is because of the lo.....ng insert statement that could invoke some parsing error[i guess]. After I have replace the insert statement with the one u suggested, then it's okay..

    Thanx skylar. :)

  • cool :) glad to help
    [b][blue]Snoochie Boochies[/blue][/b]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories