Solved

PHP Insert Post Data into MySQL

Posted on 2008-06-20
10
823 Views
Last Modified: 2013-12-12
For some reason this query does not insert. The connection is there. Does anyone see a syntax error or something? I cannot figure out why it will not insert.

$registration_query = "INSERT INTO event_users (first_name,last_name,company,phone,email,passwrd,is_active,last_login,super_admin,address,address2,city,state,zip,phone,URL) values ('$firstname','$lastname','$organization','$telephone','$email','$password1',1,GetDate(),0,'$address','$address2','$city','$state','$zip','$telephone','$URL')";
0
Comment
Question by:kallestie
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 17

Expert Comment

by:nplib
ID: 21831646
lets see the whole code.
0
 
LVL 17

Expert Comment

by:nplib
ID: 21831668
what you should do is echo the query, copy and paste the outputted query into a query agent and run it and see what errors it produces

one of your variables might contain a ' in it, which will break said query

you could always mysql_real_escape_string() each variable to be sure.
0
 
LVL 28

Expert Comment

by:gamebits
ID: 21831741
I suppose you have after what you show

$result = mysql_query($registration_query)
0
 
LVL 16

Expert Comment

by:DrNikon224
ID: 21831998
Replace GetDate() with NOW(). GetDate is used in MS SQL, and Now() is the MySQL equivalent to GetDate(), and will get the current timestamp.
0
 
LVL 17

Expert Comment

by:nplib
ID: 21832051
Curdate() will give you just the date if your field type is date
now() will give you date and time if your field type is datetime
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:kallestie
ID: 21832151
$registration_query = "INSERT INTO event_users (first_name,last_name,company,phone,email,passwrd,is_active,last_login,super_admin,address,address2,city,state,zip,phone,URL) values ('$firstname','$lastname','$organization','$telephone','$email','$password1',1,Curdate() ,0,'$address','$address2','$city','$state','$zip','$telephone','$URL')";
      
$result = mysql_query($registration_query);

This returns nothing.
0
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 500 total points
ID: 21832175
try
$result = mysql_query($registration_query) or die("Error: ".mysql_error());

Open in new window

0
 
LVL 17

Expert Comment

by:nplib
ID: 21832222
what about what I initially said about mysql_real_escape_string

the ones I didn't escape where password, because you shouldn't allow ' in a password anyways
or if you do you should be encrypting the password and there is no ' in encrypted strings.

$zip should be numbers,
$phone shoud be numbers
$url can't have a ' in it anyways, so you should be testing for that before hand and make sure they type a proper url.
$registration_query = "INSERT INTO event_users (first_name,last_name,company,phone,email,passwrd,is_active,last_login,super_admin,address,address2,city,state,zip,phone,URL) values ('".mysql_real_escape_string($firstname)."','".mysql_real_escape_string($lastname)."','".mysql_real_escape_string($organization)."','".mysql_real_escape_string($telephone)."','".mysql_real_escape_string($email)."','$password1',1,Curdate() ,0,'".mysql_real_escape_string($address)."','".mysql_real_escape_string($address2)."','".mysql_real_escape_string($city)."','".mysql_real_escape_string($state)."','$zip','$telephone','$URL')";

      

$result = mysql_query($registration_query);

Open in new window

0
 
LVL 16

Expert Comment

by:DrNikon224
ID: 21832242
I notice your password field is named 'passwrd', while all your other field names are not abbreviated. Is this field name accurate? If the missing 'o' is a typo, and the field name is actually 'password', you'll need to wrap the field name in backticks (`password`) because "password" is a reserved term in MySQL. Always a good idea to wrap all table and field names in backticks to avoid problems like this - even better idea to avoid using reserved words as table/field names.

Just another possibility. 'logudotcom's suggestion of adding the or die() error output will tell you if you've got field naming issues.
0
 
LVL 2

Author Closing Comment

by:kallestie
ID: 31469170
Thank you, I had phone 2 times.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php call to a non-object 3 34
Preventing users manipulating URL strings 10 37
How to set a countdown by not using the PC time in PHP 36 45
hosting images 4 12
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now