Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i'm having a little bit of trouble inserting data into my mysql database i have attached the full script at the bottom but i have left out the $link value witch is used as mysqli_connect for security reasons any help would be appreciated the section that i'm having problems with is

else if (mysqli_num_rows($result) == 0)
{
	echo("create");
	mysqli_query($link,"INSERT INTO website (`uuid`, `name`, `pass`, `email`) VALUES ($uuid, $user, 556, $email)") or mysqli_error($link);
}

i get the message create but it don't insert the data into the table.





full script:

$uuid = $_REQUEST['uuid'];
$user = $_REQUEST['user'];
$email = $_REQUEST['email'];
//mysqli_query($link, "SELECT * FROM website WHERE user = '$usr'");
$result = mysqli_query($link, "SELECT * FROM website WHERE uuid = '$uuid'");
if (mysqli_num_rows($result) > 0)
{
    // output data of each row
    while($row = mysqli_fetch_assoc($result))
{
	if($uuid != $row["uuid"])
	{
		echo("Can not create 2 accounts!");
		//user already registered
	}
	}
	}
else if (mysqli_num_rows($result) == 0)
{
	echo("create");
	mysqli_query($link,"INSERT INTO website (`uuid`, `name`, `pass`, `email`) VALUES ($uuid, $user, 556, $email)") or mysqli_error($link);
}



thank you in advance :)
Posted

1 solution

The best way to figure out your own error is echoing the query and run it on mysql

example:
PHP
echo
$Query="INSERT INTO website (`uuid`, `name`, `pass`, `email`) VALUES ($uuid, $user, 556, $email)";
mysqli_query($link,$Query) or mysqli_error($link);



And if you look at the top of your code, you would see that you did it right once. Then you screwed up. You must have to use quotes around your variable
example : your code line 5

Your code is highly risky. Almost any naive programmer will be able to destroy your database or steal information from your system.

have a take a look at this website link[^]. Let us know your progress.
 
Share this answer
 
v2
Comments
Member 11472678 24-Feb-15 4:59am    
Hi, thanks for your concern about security i'm just getting a running model up and going before i implement security and i have made the changes you suggested and im still just getting my "create" message no errors what so ever so im stumped i dont understand how it can work when it dose the check to see if the user already exists and then just refuse to work for the input of a new user.

please note this is not going to be used by the website this is to input data from additional palatforms i dont know if your fumilliure with LSL but its coming in from a virtual world so i will be implementing security on both sides with encryption once i can get it to function correctly.

i assume you ment for this to be be changed to what you said

echo("create");
//mysqli_query($link,"INSERT INTO website (uuid, name, pass, email) VALUES ('$uuid', '$user', '556', '$email')");
$Query="INSERT INTO website (`uuid`, `name`, `pass`, `email`) VALUES ('$uuid', '$user', '556', '$email')";
mysqli_query($link,$Query) or (mysqli_error($link));
Member 11472678 24-Feb-15 5:15am    
all is working now turns out due to my lack of sleep last night i lost the ability to spell when creating the database i wrote "name" instead of "user" haha now i can start messing around with md5 encryption :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900