Jump to content

[SOLVED] Can't get data into MySQL database!!!


GOLDfish_74

Recommended Posts

To view the full story: Click Here.

 

Anywho, a summary of the story goes, I am trying to run a really simple script that would place users in my database when they registered:

<?php 
// Connects to your Database 
mysql_connect("localhost", "goldfish_root", "password") or die(mysql_error()); 
mysql_select_db("goldfish_retaildefault") or die(mysql_error()); 

//This code runs if the form has been submitted
if (isset($_POST['submit'])) { 

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
die('You did not complete all of the required fields');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT user_name FROM users WHERE user_name = '$usercheck'") 
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, '.$_POST['username'].', you are already registered.');
}

// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match.');
}

// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

// now we insert it into the database
$insert = "INSERT INTO users (user_id, user_name, user_pass, user_sec)
VALUES ('".$_POST['userid']."', '".$_POST['username']."', '".$_POST['pass']."', '".$_POST['security']."')";
mysql_query($insert);
?>


<h1>Registered</h1>
<p>Thank you, you have registered - you may now login</a>.</p>
<p><? echo ($_POST['pass']); echo ($_POST['security']); echo ($_POST['username']); echo ($_POST['userid']) ?></p>

<?php 
} 
else 
{ 
?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td>Your User ID is:</td><td>
<? $userid = rand(1000, 9999); echo($userid); ?>
<input type="hidden" name="userid" value="<? echo($userid); ?>">
</td></tr>
<tr><td>Full Name:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="10">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="10">
</td></tr>
<tr><td>Security Level</td><td>
<input type="radio" name="security" value="2">Supervisor<br><input type="radio" name="security" value="1">Employee</td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
</form>

<?php
}
?> 

 

This did not report any errors but also failed to put any data in the database.

As this failed to work I figured I'd just try a simple alternative:

<?
error_reporting(E_ALL);  
mysql_connect("localhost", "goldfish_root", "password") or die(mysql_error()); 
mysql_select_db("goldfish_retaildefault") or die(mysql_error()); 
$insert = "INSERT INTO users (user_id, user_name, user_pass, user_sec)
VALUES ('1234, Josh, 3883, 1')";
$add_member = mysql_query($insert);
?>

This also failed to work with no errors, and now I have no idea what is going wrong.

 

These questions all came about when I tried to use EasyPHP to test my script while I was on public transport and away from home. When it seemed they did not like Vista, I got a free web host (qupis.com) and the problems are still the same. I am sure there is nothing wrong with my code, so what could be going wrong?

 

Regards,

 

THEfish.

Link to comment
Share on other sites

Here is how I insert things to a database...

 

$insert = "INSERT INTO users SET

user_id = '',

user_name = 'Josh',

user_pass = '3883',

user_sec = '1'";

 

you can also use this to update. by changing the syntax from insert to update.. such as..

 

$update = "UPDATE users SET

user_id = '',

user_name = "Jump",

user_pass = '3434324',

user_sec = '2' WHERE user_id = '$user_id'";

 

hope it helps..

 

 

Link to comment
Share on other sites

Just to let you know, I have done a fair bit of PHP and MySQL before. And I know what auto_increment is... AND ITS NOT SET TO THAT. If you had cared to look, the id is set by a random number generator, not by the database.

 

If you have any more suggestions that could work, please post.

 

Regards,

 

THEfish!

 

PS: I tried using SET instead of VALUES with no difference in result.

Link to comment
Share on other sites

Turns out it was the most obvious thing in the world!!! user_pass, was meant to be user_pin. and I had error display off. That and I agree EasyPHP is not what I should be using... lol, THANKS for all your patience to find such a pointless flaw.

 

Ciao,

 

THEfish!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.