Jump to content


Photo

What is wrong here?


  • Please log in to reply
8 replies to this topic

#1 Fira

Fira
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 26 September 2006 - 03:01 AM

Here is my PHP code in adding a new user to two tables, one being USER and the other being CHARACTER.

$newpass = "1"; //substr(md5(time()),0,6);
   
$sql = "INSERT INTO user SET
      userid = '$_POST[newid]',
        password = '$newpass',
        email = '$_POST[newemail]'";
           
if (!mysql_query($sql))
    error('Error at insert user info.' . mysql_error());

echo "pass1";
             
$sql = "INSERT INTO character SET
          chara = '0'";

if (!mysql_query($sql))
    error('Error at insert character info.' . mysql_error());

echo "pass2";


Both tables USER and CHARACTER have an auto-increment variable "id," both starting at 1. The code adds in the information into table USER, but not CHARACTER. When I run the code, "pass2" doesn't display, and when I check my character table, it's empty. What's wrong?

Note that both tables are empty to begin with, and after the code is run, table USER has been filled out, but table CHARACTER has not.

#2 Guest_WarpNacelle_*

Guest_WarpNacelle_*
  • Guests

Posted 26 September 2006 - 03:48 AM

It looks like you have used the syntax for an UPDATE statement rather then an INSERT.

I believe your query should be:

INSERT INTO user (userid, password, email) VALUES ('$newid', '$newpass', '$newemail')

(I would suggest vaildating your $_POST variables and setting them like so - $newid = $_POST[newid])

Give that a try...

#3 Fira

Fira
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 26 September 2006 - 03:55 AM

Yes, either way works, but the problem is the second part of the code, where I'm trying to set chara=0 in table CHARACTER.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 September 2006 - 05:56 PM

Not sure... if you're not getting an error, something else is wrong.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 Fira

Fira
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 26 September 2006 - 07:59 PM

I've just removed the ". mysql_error()" portion of the code, and it displays the error "Error at insert character chara."

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 September 2006 - 08:37 PM

Maybe it's a reserved keyword.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 Daen

Daen
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 26 September 2006 - 11:35 PM

http://dev.mysql.com...rved-words.html

This page says that 'Character' is a reserved word.  That might be affecting it, since that's your table name.

#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 27 September 2006 - 06:34 PM

If adding backticks works, then yes...
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#9 Fira

Fira
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 07 October 2006 - 07:52 AM

Awesome, I changed the table name to chara and it worked. Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users