hello there,
this is my simple php code which inserts a row into the db.
the problem is that it doesnt work 'nothing happens no row is being insert and i dont get any error.
I have no idea whats wrong.
hope to get any solution.
thanks.


db structure:
Id int(11) auto_increment
Mail varchar(256) utf8_general_ci
Pass varchar(256) utf8_general_ci
Name varchar(256) utf8_general_ci
LName varchar(256) utf8_general_ci
Details text utf8_general_ci

$mysql_link=mysql_connect('localhost','root','123456') or die("ERROR: cannot connect to MySQL server.");
  echo "connected successfully to MySQL server.";
mysql_select_db('gwars',$mysql_link);

$query="INSERT INTO user VALUES('','sdfsdsfdf','sdf','wer','m4n','asa4sd')";  

mysql_query($query,$mysql_link);
if (mysql_affected_rows()==1)
echo "effected<br>";
else
echo "no effect";

try using the query:

$query = "INSERT INTO `user` (`Mail`,`Pass`,`Name`,`LName`,`Details`) VALUES ('sdfsdsfdf','sdf','wer','m4n','asa4sd')";

and if that doesn't work...

add

or die( 'Error: ' . mysql_error() );

to the end of the mysql_query() call and run the script again. let us know if there are any errors.

Member Avatar for Rhyan

Well, one more thing - your procedure to check if there is any result will normally return nothing...

1. Store your insert query into a variable like this:

$insret = mysql_query($query,$mysql_link);

2. Now you can check it like this

if ($insert)
 {
  echo "Your new record is".mysql_insert_id($mysql_link);
 }
else {echo mysql_error();}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.