Jump to content

can't INSERT into mysql database


laron

Recommended Posts

I am having a problem INSERTing into mysql database(online) I am able to make the connection, and my php looks like it works, but when i check the database nothing is there

 

my main form:

<?php
$db_name = 'goaustindata';
$mysql_user = 'austin';
$mysql_password = 'sow5453had';
$db = mysql_connect('localhost',$mysql_user,$mysql_password);
/*if problem w/ database, comment*/
if(!$db){
echo 'Error connecting to the database, mesage returned: '.
mysql_error();
die;
}
$link = mysql_select_db($db_name);
if(!$link){
echo 'error selecting the database, message returned: '.
mysql_error();
die;
}
?>

<form action="inputdata.php" method="post">
<table border="0" cellpadding="0" cellspacing="2">
<tr><td>
E-mail</td><td><input type="text" name="email" /></td></tr>
<tr><td>
Username:</td><td><input type="text" name="username"  /></td></tr>
<tr><td>
Password:</td><td><input type="password" name="password" /></td></tr>
<tr><td> </td><td>
<input type="submit" name="submit" value="Register" /></td></tr>
</table>
</form>

and the page it is sent to on submit

<?php
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$server = 'localhost';
$user = '*******';
$pass = '********';
$database = '********';
$ip = $_SERVER['HTTP_USER_AGENT'];

// connect to the sql database using the variables set inn 'config.php'
$link = mysql_connect($server, $user, $pass);
$db = mysql_select_db($database, $link);

// the 'insert' that will er, insert the data as a new row into the table under the respective columns.
$query = "INSERT INTO user (username, password, email, ip) VALUES ('$username', '$password', '$emali', '$ip', '$email',)";
$result = mysql_query($query, $link);

echo 'Thank you for registering.';
?>

 

it is sloppy code at the moment, but I am just trying to get it to work before i move on....

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/43432-cant-insert-into-mysql-database/
Share on other sites

I just made a topic about this.

My problem was that at my control panel, I forget to give my database the permissions.

 

Make sure your database has ALL the permissions needed to be written in.

Since I trust myself (obviously), I just give my database ALL permissions, instead of a select few.

 

Considering you have database, I almost 100% assume you have a control panel to set your database permissions.

<?php
$query = "INSERT INTO user (username, password, email, ip) VALUES ('$username', '$password', '$emali', '$ip', '$email')";
?>

 

Emali? If your database has 4 slots and you are trying to input 5 pieces of data, its not going to like you very much. Try this instead.

 

<?php
$query = "INSERT INTO user (username, password, email, ip) VALUES ('".$username."', '".$password."', '".$ip."', '".$email."')";
?>

 

If that doesn't work try to see if $result is even executing properly.

 

<?php
$result = mysql_query($query, $link);

if($result){
echo 'Thank you for registering.';
}else{
echo 'There has been a database error.';
}
?> 

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.