Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,926 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,797 people online right now. Registration is fast and FREE... Join Now!




slight trouble with insert statment

 
Reply to this topicStart new topic

slight trouble with insert statment

didgy58
19 Mar, 2008 - 04:16 PM
Post #1

D.I.C Head
**

Joined: 23 Oct, 2007
Posts: 170



Thanked: 1 times
My Contributions
hi all, im having trouble with the insert statment i have. ive printed out the sql its making and its as below
CODE

insert into student & #40;enrolnumb,fname,lname,pass,email,telno,courseid,mod1id,mod2id,mod3id,mod4id,
dob) values ('00070165','daniel','newns',SHA('overmars1'),'didgy58@googlemail.com','07708755622','1','1','2','3','4','04/08/1982')


when i run that into phpmyadmin it inserts fine but when i try to do it with my php page it goes to the or die error message and shows the sql like i wanted it to

CODE

if (isset($_POST['submitted'])){
$fname=$_POST['fname'];
$sname=$_POST['lname'];
$enumb=$_POST['enumb'];
$pass=$_POST['pass'];
$email=$_POST['email'];
$telno=$_POST['telno'];
$dob=$_POST['dob'];
$courseid=$_POST['courseid'];
$mod1="1";
$mod2="2";//$_POST['mod2t'];
$mod3="3";//$_POST['mod3t'];
$mod4="4";//$_POST['mod4t'];

$sql="insert into student & #40;enrolnumb,fname,lname,pass,email,telno,courseid,mod1id,mod2id,mod3id,mod4id,
dob) values ('$enumb','$fname','$sname',SHA('$pass'),'$email','$telno','$courseid','$mod1','$mod2','$mod3','$mod4','$dob')";
mysql_query($sql) or die($sql);


not sure why is seems to run in the phpmyadmin but not in the actual php. if anybody has anyideas what have i missed out i bet its something really really stupid..

thanks for the help guys

dan.

for some unknow reason the cut and paste hasnt come across ok the opening bracket doesnt seem to have appeared but it is there on the print out for some strange reason there is a & #40 there instead, im using textedit to write the code then uploading to my site.
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Slight Trouble With Insert Statment
19 Mar, 2008 - 06:42 PM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 477



Thanked: 22 times
Dream Kudos: 350
My Contributions
the only thing I can really notice is that the #40 should be a ( instead...

that, and there's a random & sign....

This post has been edited by JBrace1990: 19 Mar, 2008 - 06:43 PM
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Slight Trouble With Insert Statment
19 Mar, 2008 - 06:46 PM
Post #3

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,495



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(didgy58 @ 19 Mar, 2008 - 05:16 PM) *


CODE

if (isset($_POST['submitted'])){
$fname=$_POST['fname'];
$sname=$_POST['lname'];
$enumb=$_POST['enumb'];
$pass=$_POST['pass'];
$email=$_POST['email'];
$telno=$_POST['telno'];
$dob=$_POST['dob'];
$courseid=$_POST['courseid'];
$mod1="1";
$mod2="2";//$_POST['mod2t'];
$mod3="3";//$_POST['mod3t'];
$mod4="4";//$_POST['mod4t'];

$sql="insert into student & #40;enrolnumb,fname,lname,pass,email,telno,courseid,mod1id,mod2id,mod3id,mod4id,
dob) values ('$enumb','$fname','$sname',SHA('$pass'),'$email','$telno','$courseid','$mod1','$mod2','$mod3','$mod4','$dob')";
mysql_query($sql) or die($sql);


Are you positive that you are connected to the DB? The code in your 1st snippet, I would assume that you are running from the MySql command line. So therefor, you already are connected to the Database, with the table selected. What about the PHP code? I don't see anything that guarantees you have a connection with the Database, or that checks for the table to be chosen.

User is online!Profile CardPM
+Quote Post

didgy58
RE: Slight Trouble With Insert Statment
20 Mar, 2008 - 01:03 AM
Post #4

D.I.C Head
**

Joined: 23 Oct, 2007
Posts: 170



Thanked: 1 times
My Contributions
thanks guys and no2pencil, i made 2 school boy errors when i made this one. i used a previously created mysqlconnection script i made a while back, nothing wrong with that but i forgot to check it and i needed to pass the POST data to a function i had created within it to for stripping etc. and lastly and more school boy i had the include for that file way way way below where i needed it to actually be!!! im so ashamed of my school boyishness!!! please forgive me!!! lol

thanks again
works a treat now (prob spent to long infront of the screen yesterday writing up final year report)

dan.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 10:22PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month