Forum Moderators: coopster

Message Too Old, No Replies

INSERT INTO doesnt work

         

naiquevin

6:37 am on Apr 5, 2009 (gmt 0)

10+ Year Member



I had posted this question here [webmasterworld.com...]
but it probably got hidden behind an inappropriate title.
no intention to spam..need some help badly as I have spend enough time breaking my head on this !

I am developing a signup system. The problem is that...
no new entry gets created in the table..
no error shown, and it shows 'Success' msg instead while nothing is stored in the table actually

Here is the code
if($password == $password2) {

$query1 = "SELECT * FROM login WHERE username = '$username'";
$result1 = mysqli_query($con,$query1);

if(mysqli_num_rows($result1) == 0) {

//the new username chosen is unique so proceed

$query2 = "INSERT INTO login (username,password,join_date,email,day,month,year,gender,location) VALUES" .
"(\"$username\" , SHA('$password'), NOW(), \"$email\", \"$day\", \"$month\", \"$year\", \"$gender\", \"$location\")";

$result2 = mysqli_query($con,$query2);

//Confirm success with the user

echo '<p> Welcome <span style="color:green; font-size:150%"> '. $username .'</span>, <br/> your new account has been succesfully created. You are now ready to <a href="login.php">log in</a> </p>';

---------------------------------------
so I put this code after $result2
if(!$result2) {
die ('error:' . mysqli_error());
}

it gives a warning this way..

Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\xampp\htdocs\project\signup.php on line 69
error:

-------------------
any problem with the code ? and what is the warning all about?
Thanks!

PS> in the table login,
username,password,,email,,gender,location are VARCHAR
join_date is DATE
day,month, year are INT

tomhumf

3:28 pm on Apr 5, 2009 (gmt 0)

10+ Year Member



Maybe try posting in databases forum.
Try doing doing this and seeing if you get an error?

$result1 = mysqli_query($con,$query1) or die(mysql_error());

LifeinAsia

3:38 pm on Apr 6, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\xampp\htdocs\project\signup.php on line 69

So what exactly is the code at line 69? That will help narrow your problem down quite a bit.

naiquevin

6:19 pm on Apr 7, 2009 (gmt 0)

10+ Year Member



Thanks to all .....got rid of the problem finally ..

but just out of curiosity.. when I check for error with a statement like 'if($result)', what I could make out is that it checks if $result carries a value which is NULL if an error occurs thats why the warning 'mysqli_error() expects exactly 1 parameter, 0 given in..'
(is this so ?)

but when its if(!$result) {... and if something goes wrong then this should be true .. so why this error again?..
Pls correct me.. is my understanding correct?