Forum Moderators: open

Message Too Old, No Replies

INSERT issue or what? Need guidance.

         

PickleHead

10:00 pm on Apr 11, 2007 (gmt 0)

10+ Year Member


So I've got MySQL, PHP, Apache going...
Everything works with simple queries, but when I try to do the following it just dies..no error, no nothing. I have errors enabled on php/mysql, every other error shows but I get nothing from this. Any ideas?

Oh and the commented out lines work, but not the "insert into customer" one...
Yes both tables are in the same db.

<?php
$user=wuser;
$pass=wpass;
$host='localhost';
$dbase='test';
echo "Before connecting to MySQL<br>";
$sql = mysql_connect($host, $user, $pass) or die (mysql_error());
echo "Connected to MySQL via PHP<br>";
mysql_select_db($dbase, $sql) or die (mysql_error());

$sql_query = mysql_query("INSERT INTO customer (cid,uname,upass,fname,lname,email,custaddress,custphone,zipcode) VALUES ("2","u2","u2pass","u2fn","u2ln","u2email","u2addy","u2phone","93307"[smilestopper])"[smilestopper]) or die (mysql_error());

# $sql_query = mysql_query("INSERT INTO t1(t1data) VALUES ('row1')"[smilestopper]) or die (mysql_error());

# $result = mysql_query("select * from t1"[smilestopper]);
# $row = mysql_fetch_array($result);
# echo "Return value = ".$row[0]."<br>";

mysql_close($sql);
echo "Goodbye!";

?>

=====================
Info on table:
mysql> describe customer;
+-------------+-----------------------+------+-----+---------+----------------+
¦ Field ¦ Type ¦ Null ¦ Key ¦ Default ¦ Extra ¦
+-------------+-----------------------+------+-----+---------+----------------+
¦ cid ¦ mediumint(8) unsigned ¦ NO ¦ PRI ¦ NULL ¦ auto_increment ¦

¦ uname ¦ varchar(12) ¦ NO ¦ ¦ ¦ ¦

¦ upass ¦ varchar(32) ¦ NO ¦ ¦ ¦ ¦

¦ fname ¦ varchar(10) ¦ NO ¦ ¦ ¦ ¦

¦ lname ¦ varchar(10) ¦ NO ¦ ¦ ¦ ¦

¦ email ¦ varchar(45) ¦ NO ¦ ¦ ¦ ¦

¦ custaddress ¦ varchar(45) ¦ NO ¦ ¦ ¦ ¦

¦ custphone ¦ varchar(14) ¦ NO ¦ ¦ ¦ ¦

¦ zipcode ¦ varchar(5) ¦ NO ¦ ¦ ¦ ¦

+-------------+-----------------------+------+-----+---------+----------------+
9 rows in set (0.00 sec)

mysql> select * from customer;
+-----+-------+--------+-------+-------+---------+-------------+-----------+----
-----+
¦ cid ¦ uname ¦ upass ¦ fname ¦ lname ¦ email ¦ custaddress ¦ custphone ¦ zipcode ¦
+-----+-------+--------+-------+-------+---------+-------------+-----------+----
-----+
¦ 1 ¦ u1 ¦ u1pass ¦ u1fn ¦ u1ln ¦ u1email ¦ u1addy ¦ u1phone ¦ 93306 ¦
+-----+-------+--------+-------+-------+---------+-------------+-----------+----
-----+
1 row in set (0.00 sec)

============
Going insane and cannot figure this out, same permissions on commented "t1" table as "customer" table, AYUDA ME!

Yes, I get output if I don't do the "customer" query.

And the worste part, if I paste the INSERT in console, it works...

txbakers

10:06 pm on Apr 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's the double quotes in your query string.

The double quotes effectively end the string.

Use single quotes around your VALUES instead and it should work.

PickleHead

10:11 pm on Apr 11, 2007 (gmt 0)

10+ Year Member



:) emotes the nubic author!

Thanks