Jump to content

Database partially filled :S


ScottRiley

Recommended Posts

Hey guys, glad to be registered on such a helpful site, I've already learned a lto from just browsing the forums and there seems to be many experienced coders here, so that means I'll get loads of really good replies...right  :P.

Anyway, here's my situation:

I've been learning PHP, I have about a weeks experience at it, but with my knowledge of programming logic etc. I think I'm coming along nicely for a n00blet anyway.  Well, I've coded some pages that allow users to register as a site member, with 2 different options, Personal Membership or Business Membership, I've managed to get everything working, except when the values are entered into the MySQL database, almost half the fields aren't inserted  ???.  Now, I'm really stuck as to why this is, when I first created the site, I checked the data on a separate .php file, now I modified it so that the php is on teh same page as the form, and things started to go weird.  I had strange problems with my data validation, which I managed to fix, however, I'm at a loss as to how to combat the problem I'm currently experiencing.

Here is my SQL query, if anyone needs to see my entire php code, I'll supply it through PM or something, because its pretty long.

[code]$sql = "INSERT INTO southport_consumers(id, username, contactname, contactnumber, mobilenumber, email, pword, postcode, housename, road, town) VALUES(0,'$busname','$busname','$contactnumber','$mobilenumber','$email','$password1','$postcode','$housename','$road','$town')";
if(mysql_query($sql))[/code]

all variable names are correct, I've checked, I put the query into myAdmin thing that handles the databases and it found no errors, but that was after I'd changed the variable instances with "Data" (so every field contained the word "Data").

I'm really at a loss as to what's happening here, so any help would be greatly appreciated.
Thanks in advance
Link to comment
Share on other sites

Thanks man, I'll check that out when I get the chance next, I don't know the password for the FTP I use, the guy I work with just added it to my favourites, so I can't get to it yet.  But I'm aware of how that can help me out, just chek to see what variables are actually outputted, etc.
Link to comment
Share on other sites

my best guess is that you're using your data validation to assign the $_POST variables to local variables.  however, i imagine some of the validation isn't running (perhaps due to some logic conditions?) and as such your local variables are undefined.

if you're not running any functions on the form data itself (apart from validation), perhaps try replacing each of the local variables with their $_POST counterparts and see if the problem still arises.
Link to comment
Share on other sites

Well, when my php starts, I store all the information as local variables, then do the validation on some of these.  My PHP coding is all over the place though, I check for empty values using the $_POST['index'], but I validate passwords, e-mails and usernames with these local variables.  Like I said, I'm new to PHP, so the efficiency of my code etc is probably awful.

[code]$businessname = $_POST['busname'];
$username=$_POST['busname'];
$password1=$_POST['password1'];
$password2=$_POST['password2'];
$email=$_POST['email'];
$postcode=$_POST['PostCode'];
$contactname=$_POST['cont_name'];
$ContactNumber = $_POST['contactnumber'];
$HouseName = $_POST['HouseName'];
$Road = $_POST['Road'];
$Town = $Post['Town'];
$County = $_POST['County'];[/code]
^Obvious what this does

[code]if($password1 != $password2)
{
print('Please ensure passwords match');
                showform();
                die;
}
//check if passwords meet a minimum length
if(strlen($password1) < 6)
{
die('Password must be 6 characters or longer');
                showform();
                die;
}[/code]
^showform() prints the html form

[code]if($_POST['busname'] = "")
{
print('Please fill in business name');
showform();
die;
}[/code]
^This carries on for all the $_POST
Link to comment
Share on other sites

variables are case sensitive:

[code]$ContactNumber = $_POST['contactnumber'];
$HouseName = $_POST['HouseName'];
$Road = $_POST['Road'];
$Town = $Post['Town'];
$County = $_POST['County'];[/code]

you'll need to use them as you've called them.  array indeces are also case-sensitive (as far as i remember), so you'll want to make sure that the form input are actually name="Country" rather than name="country".
Link to comment
Share on other sites

Just a quick update, then this can be deleted/whatever.  For some reason, when I print($sql)'ed the code, it was all fine and dandy, I thought this was strange, but I checked phpmyAdmin, and where fields had been previously blank, they actually containted data, so myabe their was a problem with myAdmin?
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.