Jump to content

What is wrong here?


Fira

Recommended Posts

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

[quote]
$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";
[/quote]

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.
Link to comment
https://forums.phpfreaks.com/topic/22062-what-is-wrong-here/
Share on other sites

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

I believe your query should be:

[code]INSERT INTO user (userid, password, email) VALUES ('$newid', '$newpass', '$newemail')[/code]

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

Give that a try...
Link to comment
https://forums.phpfreaks.com/topic/22062-what-is-wrong-here/#findComment-98718
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.