Jump to content

insert failing from php script but not command line


straygrey

Recommended Posts

My php script looks like:-

    global $UserNum, $UserName, $Password, $JackpotLevel, $Mailshot, $IPAddress, $LastLogon, $ip;

    $date = date('Y-m-d H:i:s');
    $ip = '127.0.0.1';

echo "DingALing = ".$UserNum." ".$UserName." ".$Password." ".$JackpotLevel." ".$Mailshot." ".$IPAddress." ".$LastLogon."<br />";

    $SQL = sprintf("INSERT INTO users(Name, Password, JackpotLevel, Mailshot, IPAddress)

                VALUES ('%s', '%s', '%d', '%d', '%s');", $UserName, $Password, $JackpotLevel, $Mailshot, $ip);

    $Result = mysql_query($SQL, $link);

    if (!$Result) die('Invalid query: '.$SQL." ".mysql_error()." ".$Result);


I get the following error

DingALing = root@asdfghjkl N0B17ch 100000 yes
Invalid query: INSERT INTO users(Name, Password, JackpotLevel, Mailshot, IPAddress) VALUES ('root@asdfghjkl', 'N0B17ch', '100000', '0', '127.0.0.1'); 

 

but if I now attempt the insert from the command line I get the following success.

mysql> describe users;
+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| UserNum      | int(4)      | NO   | PRI | NULL    | auto_increment |
| Name         | varchar(35) | YES  |     | NULL    |                |
| Password     | varchar(15) | NO   |     | NULL    |                |
| JackpotLevel | int(4)      | NO   |     | NULL    |                |
| Mailshot     | smallint(2) | YES  |     | NULL    |                |
| IPAddress    | varchar(30) | YES  |     | NULL    |                |
| lastlogin    | datetime    | YES  |     | NULL    |                |
+--------------+-------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

mysql> select * from users;
Empty set (0.00 sec)

mysql> INSERT INTO users(Name, Password, JackpotLevel, Mailshot, IPAddress) VALUES ('root@asdfghjkl', 'N0B17ch', '100000', '0', '127.0.0.1');
Query OK, 1 row affected (0.00 sec)

mysql> select * from users;
+---------+----------------+----------+--------------+----------+-----------+-----------+
| UserNum | Name           | Password | JackpotLevel | Mailshot | IPAddress | lastlogin |
+---------+----------------+----------+--------------+----------+-----------+-----------+
|       1 | root@asdfghjkl | N0B17ch  |       100000 |        0 | 127.0.0.1 | NULL      |
+---------+----------------+----------+--------------+----------+-----------+-----------+
1 row in set (0.00 sec)

 

Please tell me what I have done wrong.

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.