SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast Red Blaze's Avatar
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP not Inserting to MySQL, error confusing.

    PHP Code:
    mysql_select_db($database_wcag$wcag);
    $query_CallArtists "SELECT * FROM artist ORDER BY artistID";
    $CallArtists mysql_query($query_CallArtists$wcag) or die(mysql_error());
    $row_CallArtists mysql_fetch_assoc($CallArtists);
    $totalRows_CallArtists mysql_num_rows($CallArtists);

    //This is to add the User to the Database!!
    if($_POST['Add_User']){

    list (
    $first$last) = preg_replace("#\s*([a-z])[a-z]*#i""$1"$name);
    $initials $first[0].$last[0];

    $startedcareer $month " " $day ", " $year;

    $sql_check 'SELECT * FROM artist WHERE initials = "'$initials .'"';
    $querycheck mysql_query($sql_check) or die(mysql_error());
                if (
    mysql_num_rows($querycheck) != 0){
                
    //Uh oh! There is already an initials like that... what to do?
                
    $lastID $row_CallArtists['artistID'] + 1;
                
    $initials $first[0].$last[0].$lastID;
                }
        
    mysql_query("INSERT INTO artist (group,name,bio,initials,login,password,email,technique,genre,startedcareer) VALUES ('$group','$name','$bio','$initials','$login','$password','$email','$technique','$genre','$startedcareer')") or die(mysql_error());
    }

    ?> 
    That's the PHP code I'm using. At first, I kept trying and trying insert a new user, but it didn't let me. It didn't even show me an error. So I added "or die" error function to see if it would give me an error and it gave me this:

    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 'group,name,bio,initials,login,password,email,technique,genre,startedcareer) VALU' at line 1
    I, personally, don't see an error in this line. This is my form:

    PHP Code:
    <form action="artists.php" method="post" name="addUser" id="addUser" onsubmit="MM_validateForm('name','','R','year','','RisNum','login','','R','password','','R','email','','RisEmail','technique','','R','genre','','R','bio','','R');return document.MM_returnValue">
          <
    table width="500" cellspacing="5" cellpadding="5">
            <
    tr>
              <
    td>Artist Name </td>
              <
    td><input name="name" type="text" id="name" /></td>
            </
    tr>
            <
    tr>
              <
    td>Started Art Career </td>
              <
    td><select name="month" id="month">
                <
    option value="January" selected="selected">January</option>
                <
    option value="February">February</option>
                <
    option value="March">March</option>
                <
    option value="April">April</option>
                <
    option value="May">May</option>
                <
    option value="June">June</option>
                <
    option value="July">July</option>
                <
    option value="August">August</option>
                <
    option value="September">September</option>
                <
    option value="October">October</option>
                <
    option value="November">November</option>
                <
    option value="December">December</option>
              </
    select>
               -           
               <
    select name="day" id="day">
                 <
    option value="01">01</option>
                 <
    option value="02">02</option>
                 <
    option value="03">03</option>
                 <
    option value="04">04</option>
                 <
    option value="05">05</option>
                 <
    option value="06">06</option>
                 <
    option value="07">07</option>
                 <
    option value="08">08</option>
                 <
    option value="09">09</option>
                 <
    option value="10">10</option>
                 <
    option value="11">11</option>
                 <
    option value="12">12</option>
                 <
    option value="13">13</option>
                 <
    option value="14">14</option>
                 <
    option value="15">15</option>
                 <
    option value="16">16</option>
                 <
    option value="17">17</option>
                 <
    option value="18">18</option>
                 <
    option value="19">19</option>
                 <
    option value="20">20</option>
                 <
    option value="21">21</option>
                 <
    option value="22">22</option>
                 <
    option value="23">23</option>
                 <
    option value="24">24</option>
                 <
    option value="25">25</option>
                 <
    option value="26">26</option>
                 <
    option value="27">27</option>
                 <
    option value="28">28</option>
                 <
    option value="29">29</option>
                 <
    option value="30">30</option>
                 <
    option value="31">31</option>
               </
    select
               - 
               <
    input name="year" type="text" id="year" value="1990" size="4" maxlength="4" /></td>
            </
    tr>
            <
    tr>
              <
    td>Bio</td>
              <
    td><textarea name="bio" cols="30" rows="5" id="bio"></textarea></td>
            </
    tr>
            <
    tr>
              <
    td>Login Name </td>
              <
    td><input name="login" type="text" id="login" /></td>
            </
    tr>
            <
    tr>
              <
    td>Password</td>
              <
    td><input name="password" type="text" id="password" /></td>
            </
    tr>
            <
    tr>
              <
    td>E-mail</td>
              <
    td><input name="email" type="text" id="email" /></td>
            </
    tr>
            <
    tr>
              <
    td>Technique</td>
              <
    td><input name="technique" type="text" id="technique" /></td>
            </
    tr>
            <
    tr>
              <
    td>Genre</td>
              <
    td><input name="genre" type="text" id="genre" /></td>
            </
    tr>
            <
    tr>
              <
    td>Admin?</td>
              <
    td><input name="group" type="radio" value="Admin" />
                
    Yes 
                
    <input name="group" type="radio" value="No" checked="checked" />
                
    No</td>
            </
    tr>
            <
    tr>
              <
    td>&nbsp;</td>
              <
    td><input name="Add_User" type="submit" id="Add_User" value="Add User" /> <input name="Submit2" type="button" onclick="MM_goToURL('parent','artists.php');return document.MM_returnValue" value="Cancle" /></td>
            </
    tr>
          </
    table>
          </
    form
    I'm pretty stumped. I don't know why it's giving me that error. ~.~

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is just a guess, but I think 'group' is being parsed as part of GROUP BY. Try putting it in backticks like so: `group`.

  3. #3
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are using many reserve words. escape those

    PHP Code:
    mysql_query("INSERT INTO artist (`group`,`name`,`bio`,`initials`,`login`,`password`,`email`,`technique`,`genre`,`startedcareer`) VALUES ('$group','$name','$bio','$initials','$login','$password','$email','$technique  ','$genre','$startedcareer')") or die(mysql_error()); 
    Not all are, but many. So, try either not to use those, or always escape those. at least i think thats the error
    ---------------------------
    Errors = Improved Programming.
    My Site

  4. #4
    SitePoint Enthusiast Red Blaze's Avatar
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, chris_fuel, that fixed the problem. Why does it do that problem if it's inside a "()"? And in an INSERT function? >.~

  5. #5
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it doesn't matter what type of function it is. mysql has reserved words. it's not like the human brain, and it wont think "oh hang on, this is an insert, so group doesnt need to be reserved. its a language, and group is reserved, as chris said, by the "group by" attribute.


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
  •