Current location: Hot Scripts Forums » Programming Languages » PHP » inserting data to mysql with php


inserting data to mysql with php

Reply
  #1 (permalink)  
Old 04-15-04, 07:25 PM
mathieu67 mathieu67 is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
inserting data to mysql with php

can anyone tell me why this script is not inserting the data to my mysql table...

post.php

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$title=$_POST['title'];
$author=$_POST['author'];
$isbn=$_POST['isbn'];
$university=$_POST['university'];
$condition=$_POST['condition'];
$price=$_POST['price'];

$location="localhost";
$username="your_db_username";
$password="your_db_password";
$database="database_name";
$conn = mysql_connect("$location","$username","$password") ;
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");
$query = "INSERT INTO table_name(name,email,phone,title,author,isbn,univ ersity,condition,price VALUES('','$name','$email','
phone','title','author','isbn','university','condi tion','price',())";

$result=mysql_query($query);
mysql_close();

</body>
</html>
?>
Reply With Quote
  #2 (permalink)  
Old 04-15-04, 11:51 PM
the_mole001's Avatar
the_mole001 the_mole001 is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Australia
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
hello mathieu67,

I think your errors lie in the INSERT INTO function. Perhaps if u changed ur code to:

$result = mysql_query("INSERT INTO table_name(name, email, phone, title, author, isbn, university, condition, price) VALUES ('','$name','$email','
phone', 'title', 'author', 'isbn', 'university',' condition', 'price')");

if($result){
echo "entered successfully";
} else {
echo "an error has occured";
}

mysql_close();

just looks a little neater and will show if there was an error entereing information.

Peter
Reply With Quote
  #3 (permalink)  
Old 04-16-04, 08:42 AM
x3m x3m is offline
New Member
 
Join Date: Apr 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL configuration

This can be wrong mysql configuration.
Try to use
$location="DB_SERVER_IP";
or
$location="127.0.0.1";

---
Ecommerce solutions
http://x3mdev.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
Error when trying to select data off MySQL in PHP HasansWeb PHP 7 01-07-04 02:06 PM
help plz: format retrieved Mysql data in HTML with PHP paulj000 PHP 2 10-19-03 08:03 PM
Pulling data from MySQl Database w/ PHP? dayzeday PHP 6 10-07-03 07:01 AM


All times are GMT -5. The time now is 10:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.