SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy help with mysql insert statement in php

    Here is the code for the section of my php page that is causing problems. I've been following the book... "Database Driven Websites..." and have gotten very useful information out of it. Unfortunatly, i've hit a snag. The problem is with the insert statement. When the information is submitted the first few fields aren't being sent. only the 'date' and the 'problem' fields.
    the other fields are being sent as empty.
    if anyone can help... i'd greatly appreciate it.

    if ($Submit=="Submit") {
    $dbcnx = @mysql_connect("*****", "*****", "*******");
    if (!$dbcnx) {
    echo ("<P>Unable to connect to the database server at this time.</P>");
    exit();
    }
    if (! @mysql_select_db("helpdesk") ) {
    echo("<P>Unable to locate the helpdesk Database at this time.</P>");
    exit();
    }

    $sql = "Insert into hlpdsk set
    tagnum='$tagnum',
    name='$name',
    phone='$phone',
    office='$office',
    date=CURDATE(),
    problem='$problem'";

    if(@mysql_query($sql)) {
    echo("your entry has been added.");
    }else{
    echo("Error");
    }
    }else{
    exit();
    }

  2. #2
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some changes in the way PHP sends data over pages have been made since version 4.2.1, and Kevin's book was printed before this version, and as such doesn't take these changes into account. Try this:
    PHP Code:
    <?php
    if ($_POST['Submit']=="Submit") {
         
    $dbcnx = @mysql_connect("*****""*****""*******");
         if (!
    $dbcnx) {
              echo (
    "<P>Unable to connect to the database server at this time.</P>");
              exit();
         }
         if (! @
    mysql_select_db("helpdesk") ) {
              echo(
    "<P>Unable to locate the helpdesk Database at this time.</P>");
              exit();
         }
         
    $sql "Insert into hlpdsk set
         tagnum='
    {$_POST['tagnum']}',
         name='
    {$_POST['name']}',
         phone='
    {$_POST['phone']}',
         office='
    {$_POST['office']}',
         date=CURDATE(),
         problem='
    {$_POST['problem']}'";

         if(@
    mysql_query($sql)) {
              echo(
    "your entry has been added.");
         }else{
              echo(
    "Error");
         }
    }else{
         exit();
    }
    ?>
    Additionally, make sure if you're using $PHP_SELF to change it to $_SERVER['PHP_SELF'] instead. If you're using GET instead of POST, alter the variable names accordingly (e.g. $_GET['Submit'] instead of $_POST['Submit'], et cetera).

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  3. #3
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Speaking of the changes since the book, I think I ran into a few that may need to be changed, and to be honost, Im not sure what.

    PHP Code:
    <?php 
    if ($_POST['Submit']=="Submit") { 
         
    $dbcnx = @mysql_connect("asdf""asdf""asdf"); 
         if (!
    $dbcnx) { 
              echo (
    "<P>Unable to connect to the database server at this time.</P>"); 
              exit(); 
         } 
         if (! @
    mysql_select_db("planetdraft") ) { 
              echo(
    "<P>Unable to locate the Roster Database at this time.</P>"); 
              exit(); 
         } 
         
    $sql "Insert into f3_roster_profiles set 
         name='
    {$_POST['PlayerName']}', 
         email='
    {$_POST['PlayerEmail']}"

         if(@
    mysql_query($sql)) { 
              echo(
    "You have added player, $name, to the Roster database."); 
         }else{ 
              echo(
    "Error"); 
         }  

         exit(); 



    ?> 

    <p><a href="<?=$_SERVER['PHP_SELF']?>">Add another Member</a></p>
    <p><a href="manage.php">Return to Site management home</a></p>

    <?

      
    else:

    ?>

    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    <p>Enter the new member:<br />
    Name: <input type="text" name="name" size="20" maxlength="255" /><br />
    Email: <input type="text" name="email" size="20" maxlength="255" /><br />
    </form>

    <?php endif; ?>
    Thanks in advance.

    EDIT: This the error I recieve:

    Error: Parse error: parse error, unexpected T_ENDIF in c:\inetpub\wwwroot\newplayer.php on line 77
    Last edited by draft-; Sep 27, 2002 at 14:18.


Bookmarks

Posting Permissions

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