Jump to content


Photo

Database partially filled :S


  • Please log in to reply
8 replies to this topic

#1 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 09 August 2006 - 07:27 PM

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.

$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))

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

#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 09 August 2006 - 07:38 PM

Which are the fields that do not get inserted?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#3 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 09 August 2006 - 07:41 PM

echo $sql;


Let us see what your SQL query is after vars have been passed.
Make a donation to phpfreaks. They need your help![br][br]

#4 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 09 August 2006 - 08:14 PM

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.

#5 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 09 August 2006 - 08:17 PM

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.

#6 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 09 August 2006 - 08:24 PM

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.

$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'];

^Obvious what this does

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;
	}
^showform() prints the html form

if($_POST['busname'] = "")
	{
		print('Please fill in business name');
showform();
die;
	}
^This carries on for all the $_POST

#7 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 09 August 2006 - 08:38 PM

variables are case sensitive:

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

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".

#8 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 09 August 2006 - 08:42 PM

Thanks a lot man, I wrote that script after a looong party the night before, so long, I went straight to work from a friend's house, so you'll have to forgive me if my code is a little sloppy after about 30 hours without sleep  :D.

#9 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 10 August 2006 - 08:12 AM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users