Welcome to Dream.In.Code
Getting PHP Help is Easy!

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




Cannot insert

 
Reply to this topicStart new topic

Cannot insert, cannot insert

jlhon
3 Oct, 2008 - 05:11 PM
Post #1

New D.I.C Head
*

Joined: 2 Oct, 2008
Posts: 8

java script:emoticon(':)', 'smid_1')
CODE

:)
<?
$reserve = $_POST['reserve'];
if($reserve){
$fname= $_POST['firstname'];
$lname= $_POST['lastname'];
$mname= $_POST['middlename'];
$add= $_POST['address'];
$con= $_POST['contact'];
$type= $_POST['type'];
$room= $_POST['room'];
$guest= $_POST['guest'];
$inn= $_POST['in'];
$out= $_POST['out'];
$dep= $_POST['deposit'];
$date= $_POST['date'];
mysql_connect("localhost","root","")or die ("cannot connect");
mysql_select_db("hoteldb");
$sql="INSERT INTO reservation (fname,lname,mname,address,contact,type,guest,room,inn,out,date,deposits) VALUES('$fname','$lname','$mname','$add','$con','$type','$guest','$room','$in','$out','$date','$dep')";
$result = mysql_query($sql) or die("cannnot insert");
    if($result){
    echo "success";
    }else{
    echo"error";
    }
}
?> :)  :)

User is offlineProfile CardPM
+Quote Post

JackOfAllTrades
RE: Cannot Insert
3 Oct, 2008 - 05:18 PM
Post #2

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 580



Thanked: 59 times
Dream Kudos: 50
My Contributions
First, please search this forum for SQL injection.

Next, Change this line:
php
$result = mysql_query($sql) or die("cannnot insert");

to
php
$result = mysql_query($sql) or die("Unable to insert data using query $sql: " . mysql_error());


and post what the message says.
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Cannot Insert
3 Oct, 2008 - 05:22 PM
Post #3

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 3,995



Thanked: 16 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
QUOTE
?> smile.gif smile.gif

The smiley faces aren't really in your code are they?

could you show us the table description? It can be done from the command prompt in mysql using: describe table_name

Just to make sure the table holds the columns you think it does.


User is offlineProfile CardPM
+Quote Post

engale
RE: Cannot Insert
3 Oct, 2008 - 05:47 PM
Post #4

D.I.C Addict
Group Icon

Joined: 30 Sep, 2008
Posts: 549



Thanked: 2 times
Dream Kudos: 50
My Contributions
Can you humor me and change
CODE

$sql="INSERT INTO reservation (fname,lname,mname,address,contact,type,guest,room,inn,out,date,deposits) VALUES('$fname','$lname','$mname','$add','$con','$type','$guest','$room','$in','$out','$date','$dep')";

so it ends up like
CODE

"INSERT INTO reservation (fname,lname,mname,address,contact,type,guest,room,inn,out,date,deposits) VALUES ('" . $fname . "','" . $lname . "','" . $mname . "','" . $add . "','" . $con . "','" . $type . "','" . $guest . "','" . $room . "','" . $in . "','" . $out . "','" . $date . "','" . $dep . "')";


This post has been edited by engale: 3 Oct, 2008 - 05:51 PM
User is offlineProfile CardPM
+Quote Post

JackOfAllTrades
RE: Cannot Insert
3 Oct, 2008 - 05:53 PM
Post #5

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 580



Thanked: 59 times
Dream Kudos: 50
My Contributions
OUT is a reserved MySQL word, that may be the problem. Try
php
$sql="INSERT INTO reservation (`fname`,`lname`,`mname`,`address`,`contact`,`type`,`guest`,`room`,`inn`,`out`,`date`,`deposits`) VALUES('$fname','$lname','$mname','$add','$con','$type','$guest','$room','$in','$out','$date','$dep')";

User is offlineProfile CardPM
+Quote Post

jlhon
RE: Cannot Insert
3 Oct, 2008 - 10:43 PM
Post #6

New D.I.C Head
*

Joined: 2 Oct, 2008
Posts: 8

biggrin.gif
thankz a lot....it works!!!
User is offlineProfile CardPM
+Quote Post

tkulev
RE: Cannot Insert
3 Oct, 2008 - 11:00 PM
Post #7

New D.I.C Head
*

Joined: 3 Oct, 2008
Posts: 13


My Contributions
QUOTE(engale @ 3 Oct, 2008 - 06:47 PM) *

Can you humor me and change
CODE

$sql="INSERT INTO reservation (fname,lname,mname,address,contact,type,guest,room,inn,out,date,deposits) VALUES('$fname','$lname','$mname','$add','$con','$type','$guest','$room','$in','$out','$date','$dep')";

so it ends up like
CODE

"INSERT INTO reservation (fname,lname,mname,address,contact,type,guest,room,inn,out,date,deposits) VALUES ('" . $fname . "','" . $lname . "','" . $mname . "','" . $add . "','" . $con . "','" . $type . "','" . $guest . "','" . $room . "','" . $in . "','" . $out . "','" . $date . "','" . $dep . "')";


Why to do this ? When one variable is in "", he has replaced by his value.
User is offlineProfile CardPM
+Quote Post

engale
RE: Cannot Insert
4 Oct, 2008 - 05:29 AM
Post #8

D.I.C Addict
Group Icon

Joined: 30 Sep, 2008
Posts: 549



Thanked: 2 times
Dream Kudos: 50
My Contributions
It's the way I've done it. That is all. I just started recently and that is the way I do it. I was unsure if it was the answer as i tryed to point out by the word humor.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:14AM

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