SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 33

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php error plz help

    hey im working on a registration page and for some rison it doesnt work , plz help .

    Code:
     <?php
      include "notice.html";
      include "connection.php";
    
    
    
     if (!isset($_POST["insert_button"]))
    
      {
    
         ?>
       <FORM action="<?= $_SERVER["notice.php"]; ?>" method="POST">
          <TABLE border=0 cellpadding=7 cellspacing=7>
             <TR>
                <br><br><br><br>
                <TD><font color="#ffbc8c83">account:</font></TD>
                <TD><INPUT type="TEXT" name="account" size=20 maxlength=20 value="<?= $_POST["account"]; ?>"></TD>
             </TR>
             <TR>
                <TD><font color="#ffbc8c83">password:</font></TD>
                <TD><INPUT type="password" name="password" size=20 maxlength=20 value="<?= $_POST["password"]; ?>"></TD>
             </TR>
             <TR>
                <TD><font color="#ffbc8c83">e-mail:</font></TD>
                <TD><INPUT type="TEXT" name="e-mail" size=30 maxlength=50 value="<?= $_POST["e-mail"]; ?>"></TD>
             </TR>
             <TR>
                <TD><font color="#ffbc8c83">age:</font></TD>
                <TD><INPUT type="TEXT" name="age" size=2 maxlength=2 value="<?= $_POST["age"]; ?>"></TD>
             </TR>
             <TR>
                <TD align="right"><INPUT type="SUBMIT" name="insert_button" value="register"></TD>
                <TD align="left"><INPUT type="RESET" value="reset"></TD>
             </TR>
          </TABLE>
       </FORM>
       <?
      }
    
     if (isset($_POST["insert_button"]))
    
      {
         $account=$_POST["account"];
         $password=$_POST["password"];
         $e_mail=$_POST["e-mail"];
         $age=$_POST["age"];
    
    
         $grade_insert_errors="";
    
         if ($account=="")
            $grade_insert_errors.="<br>account name isnt good.<BR>";
    
         if ($password=="")
            $grade_insert_errors.="password just isnt right.<BR>";
    
         if ($e_mail=="")
            $grade_insert_errors.="type a working e-mail plz.<BR>";
    
         if ($age=="")
            $grade_insert_errors.="age isnt good.<BR>";
    
         if ($grade_insert_errors=="")
    
         {
    
            $account=$account;
            $password=$password;
            $e_mail=$e_mail;
            $age=$age;
    
            $grade_insert_query="INSERT INTO ".$reg." (account".(($account!="")?",account":"")."".(($password!="")?",pass":"")."".(($e_mail!="")?",E-mail":"")."".(($age!="")?",age":"").")  VALUES (";
            $insert_query.=($account!="")?",'$account'":"";
            $insert_query.=($password!="")?",'$password'":"";
            $insert_query.=($e_mail!="")?",'$e-mail'":"";
            $insert_query.=($age!="")?",'$age'":"";
            $insert_query.=")";
            $result=@mysql_query ($grade_insert_query,$grade_con);
    
            if (mysql_affected_rows()==1)
    
            {
               echo "<BR><B><font color=orange>account made sucsesfully</font></B><BR>";
    
            }
            else
    
            {
               echo "<BR><br><B><font color=orange>account could not be made</font></B><BR>";
               unset($_POST["insert_button"]);
    
            }
         }
         else
    
         {
            echo "<BR><br><FONT color=\"#ffbc8c83\">".$grade_insert_errors."</FONT><BR>";
            unset($_POST["insert_button"]);
    
         }
      }
    ?>
    i belive i have an error here :
    Code:
    $grade_insert_query="INSERT INTO ".$reg." (account".(($account!="")?",account":"")."".(($password!="")?",pass":"")."".(($e_mail!="")?",E-mail":"")."".(($age!="")?",age":"").")  VALUES (";
    OR

    Code:
    $result=@mysql_query ($grade_insert_query,$grade_con);
    
    if (mysql_affected_rows()==1)
    how do i know it doesnt work ? it doesnt show me "account made sucssesfully"

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From a quick look, it seems that you haven't defined $reg - which should be the name of the table you want to insert your values into.

    Also, I would test the value of $result, if false, then display the results of mysql_error(), and echo the value of $grade_insert_query before you run the query.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is this ok ?:
    Code:
      $grade_insert_query="INSERT INTO ".$grade_reg_table." (account".(($account!="")?",account":"")."".(($password!="")?",pass":"")."".(($e_mail!="")?",E-mail":"")."".(($age!="")?",age":"").")  VALUES (";
            $insert_query.=($account!="")?",'$account'":"";
            $insert_query.=($password!="")?",'$password'":"";
            $insert_query.=($e_mail!="")?",'$e-mail'":"";
            $insert_query.=($age!="")?",'$age'":"";
            $insert_query.=")";
            $result=@mysql_query ($grade_insert_query,$grade_con);

  4. #4
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try it and see

    But once again, have you defined $grade_reg_table anywhere?

    Also, try my suggestions about echo the SQL command before executing it - makes it easier to spot errors and also check the $result variable.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok sorry im a noob :/ i have no idia how to define the reg table ... and i've done the part of posting the stuff it sandes to the table ...

  6. #6
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We were all noobs once upon a time

    What is the name of the table that you want to insert that data into? Whatever that name is, that is what you shoule set $grade_reg_table to, or just hard-code the table name into the query string.

    e.g
    PHP Code:
     $grade_reg_table 'GradeTable'
    would be good enough, if your table was called GradeTable.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok here is what he posted me when i told him to post what he is going to send :
    Code:
    INSERT INTO reg (reg,Admin,yoman,frerez@hotmail.com,15) VALUES (
    first i duno why he added the "reg" in the start ...
    and reg is the name of the table
    the rest is exacly the info i entered ....
    and this is the code :
    Code:
            if ($grade_insert_errors=="")
    
         {
    
            $account=$account;
            $password=$password;
            $e_mail=$e_mail;
            $age=$age;
            $grade_reg_table='reg';
    
            $grade_insert_query="INSERT INTO ".$grade_reg_table." (reg".(($account!="")?",$account":"")."".(($password!="")?",$password":"")."".(($e_mail!="")?",$e_mail":"")."".(($age!="")?",$age":"").")  VALUES (";
            $insert_query.=($account!="")?",'$account'":"";
            $insert_query.=($password!="")?",'$password'":"";
            $insert_query.=($e_mail!="")?",'$e-mail'":"";
            $insert_query.=($age!="")?",'$age'":"";
            $insert_query.=")";
            $result=@mysql_query ($grade_insert_query,$grade_con);
    
            if (mysql_affected_rows()==1)
    
            {
               echo "<BR><B><font color=orange>account made sucsesfully</font></B><BR>";
    
            }
            else
    
            {
               echo "<BR><br><B><font color=orange>account could not be made</font></B><BR>";
               unset($_POST["insert_button"]);
               echo "<BR><br><FONT color=\"#ffbc8c83\">".$grade_insert_query."</FONT><BR>";
               echo "<BR><br><FONT color=\"#ffbc8c83\">".$grade_con."</FONT><BR>";
    
            }

  8. #8
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok - the syntax for an INSERT SQL statement is

    INSERT INTO table_name (col1, ...) VALUES (val1, ...)


    where

    table_name is the name of the table you want to store the values
    col1 ... are the names of the columns where you want the values stored
    val1... are the values to be stored

    so in your case, guessing at the column names, you want something that looks like

    INSERT INTO GradeTable (AccountID, Password, EMail, Age) VALUES ('account', 'Admin', 'frerez@hotmail.com', 15);

    Note very carfully which values are surrounded by single quotes.

    Hope this helps

  9. #9
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sound cool but is the result
    Code:
    $result=@mysql_query ($grade_insert_query,$grade_con);
    i havent placed any $grade_con
    its nothing ... and i got an error on this line:
    Code:
    $grade_insert_query=INSERT INTO reg (account,password,e-mail,age) VALUES ($account,$password,$e_mail,$age);
    any idia what's wrong?

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    made some changes ... didnt help thought ... still error in the first line here :
    Code:
            $grade_insert_query= INSERT INTO reg (account,password,e-mail,age) VALUES ('$account','$password','$e_mail',$age);
            $insert_query.=($account!="")?",'$account'":"";
            $insert_query.=($password!="")?",'$password'":"";
            $insert_query.=($e-mail!="")?",'$e_mail'":"";
            $insert_query.=($age!="")?",'$age'":"";
            $insert_query.=")";
            $result=@mysql_query ($grade_insert_query,$grade_con);
    and btw to understand the uper info know this :
    Code:
       ?>
       <FORM action="<?= $_SERVER["notice.php"]; ?>" method="POST">
          <TABLE border=0 cellpadding=7 cellspacing=7>
             <TR>
                <br><br><br><br>
                <TD><font color="#ffbc8c83">account:</font></TD>
                <TD><INPUT type="TEXT" name="account" size=20 maxlength=20 value="<?= $_POST["account"]; ?>"></TD>
             </TR>
             <TR>
                <TD><font color="#ffbc8c83">password:</font></TD>
                <TD><INPUT type="password" name="password" size=20 maxlength=20 value="<?= $_POST["password"]; ?>"></TD>
             </TR>
             <TR>
                <TD><font color="#ffbc8c83">e-mail:</font></TD>
                <TD><INPUT type="TEXT" name="e-mail" size=30 maxlength=50 value="<?= $_POST["e-mail"]; ?>"></TD>
             </TR>
             <TR>
                <TD><font color="#ffbc8c83">age:</font></TD>
                <TD><INPUT type="TEXT" name="age" size=2 maxlength=2 value="<?= $_POST["age"]; ?>"></TD>
             </TR>
             <TR>
                <TD align="right"><INPUT type="SUBMIT" name="insert_button" value="register"></TD>
                <TD align="left"><INPUT type="RESET" value="reset"></TD>
             </TR>
          </TABLE>
       </FORM>
       <?

  11. #11
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this code

    PHP Code:
      if ('' == $grade_insert_errors)
      {
        
    // make sure strings are quoted and escaped
        
    $account '\''mysql_real_escape_string($account) . '\'';
        
    $password '\''mysql_real_escape_string($password) . '\'';
        
    $e_mail '\''mysql_real_escape_string($e_mail) . '\'';
        
    $age $age;
        
    $grade_reg_table 'reg';
      
        
    $grade_insert_query 'INSERT INTO '
                          
    $grade_reg_table
                       
    ' (account, password, email, age)'
                          
    ' VALUES ('
                          
    $account
                          
    ', ' $password
                          
    ', ' $email
                          
    ', ' $age
                            
    ')'
                            
    ;
      
        
    // START DIAGNOSTIC - REMOVE WHEN WORKING
        
    echo 'Executing ' $grade_insert_query '<br />';
        
    // END DIAGNOSTIC - REMOVE WHEN WORKING
      
        
    $result = @mysql_query ($grade_insert_query,$grade_con);
        if (
    false == $result)
        {
          echo 
    ' Failed to execute ' $grade_insert_query ' due to ' mysql_error() . '<br />';
        }
        else
        {
          echo 
    'Account created <br />';
        } 

  12. #12
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i got this msg :
    Code:
    Executing INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15)
    Failed to execute INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15) due to
    err was the line suppuse to end like this ? "due to" ..... nothing else was writen m8 ...

  13. #13
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok - change these 2 lines
    PHP Code:
         $result = @mysql_query ($grade_insert_query,$grade_con);
         if (
    false == $result
    to
    PHP Code:
         $result mysql_query ($grade_insert_query,$grade_con);
     
    // START OF DIAGNOSTIC - REMOVE WHEN WORKING
     
    echo 'Result = ' $result '<br />';
     
    // END OF DIAGNOSTIC - REMOVE WHEN WORKING
     
         
    if (false === $result
    The error line should display the MySQL error as well as the query that caused the error

  14. #14
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok now this is wierd:
    Code:
    Executing INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15)
    
    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/www/somatnt.superihost.com/notice.php on line 90
    Result = 
    Account created

  15. #15
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah I think I see what the problem might be

    $grade_con

    Where is the connection defined / set-up?

    Also, you should change the line

    PHP Code:
     if (false === $result
    back to
    PHP Code:
     if (false == $result

  16. #16
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u mean the file that tells me wich host and db to connect to ?

  17. #17
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes

  18. #18
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this ?:
    Code:
    <?php
    
    $db_host = "superihost.com";
    $username = "somatnt_yosoma";
    $password = "******";
    $DB_name = "somatnt_yosoma";
    
    echo "<HTML><BODY>";
    
    $chan = mysql_connect ($db_host, $username, $password);
    mysql_select_db ($DB_name, $chan);
    
    ?>
    i hope u dont mind i changed the pass .... (its not really ****)
    u can see in my first post i've added it (connection.php)

  19. #19
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No - I'm glad you **** out the password.

    As you can see from that code, the MySQL link identifier is called $chan, so this is what you shuold use in the mysql_query function call.

    Try it and post the results

  20. #20
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the resolt ... (long):
    Code:
    Executing INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15)
    Result = 
    Failed to execute INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15) due to 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 '-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com',

  21. #21
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    btw ... the fields in my table are :
    account , password , e-mail , age

  22. #22
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    should i change the field name "e-mail" to somthing else?

  23. #23
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah - ok

    change this line
    PHP Code:
                      ' (account, password, email, age)' 
    to
    PHP Code:
                      ' (account, password, `e-mail`, age)' 
    i.e use backticks around the e-mail column name

  24. #24
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    israel
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cant be done ... made an error on that line ...

  25. #25
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What was the error? It worked ok for me

    Also is it possible to change the name of the e-mail field by removing the '-'?


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
  •