MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 8th, 2000, 04:40 PM
carl carl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 6 carl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0

Hi everyone
I’m completely new to this game. I have tried a couple of tutorials in Devshed and I seem to
have the same problem with inserting into the MySQL database. In this example the script
index.php3 shows the database in a table as expected. However, the add.php3 does not add
to the database. I have already tested whether I have installed MySQL properly and it seems ok.
Could someone please explain how to solve this?

index.php3:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<html>
<head><title>Web Database Sample Index</title>
</head>

<body bgcolor=#ffffff>
<h1>Data from mytable</h1>
<?
mysql_connect("localhost","username","password");


$query = "SELECT name, phone FROM mytable";
$result = mysql_db_query("test2", $query);

if ($result) {
echo "Found these entries in the database:<ul>";
while ($r = mysql_fetch_array($result)) {
$name = $r["name"];
$phone = $r["phone"];
echo "<li>$name, $phone";
}
echo "</ul>" ;
} else {
echo "No data.";
}
mysql_free_result($result);
?>

<p><a href="add.php3">Add new entry </a>
</body>
</html>
[/code]
add.php3:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<html>
<head><title>Web Database Sample inserting </title>
</head>

<body bgcolor=#ffffff>
<?
if (isset($name) && isset ($phone)) {
mysql_connect ("localhost", "username", "password");
$query = "INSERT INTO mytable VALUES ('$name', '$phone')";
$result = mysql_db_query("test2", "$query") ;

if ($result) {
echo "<p>$name was added to the database</p>" ;
}
}
?>

<h1>Add an entry</h1>
<form>
Name: <input type=text name='name'><br>
phone: <input type=text name='phone'><br
<input type=submit>
</form>
<p><a href="index.php3">Back to index</a>
</body>
</html>
[/code]



Reply With Quote
  #2  
Old August 9th, 2000, 04:06 AM
kurtz kurtz is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 2 kurtz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You need indicate in the <form> tag the action program must to do, ex:
<form enctype="multipart/data-form" method="post" action="add.php">
and then add a button like this:
<input type=submit size=30 value='Send it'>
It's work!

Reply With Quote
  #3  
Old August 10th, 2000, 09:18 PM
zorgon zorgon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 1 zorgon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It looks like your problem lies with your insert statement.

INSERT INTO my_table VALUES ('$phone','$name');

You need to specify the table columns within your insert statement.

For example:

If you had a table called PERSON with the columns NAME VARCHAR(32)
AGE INTEGER

An insert statement would look like this:

INSERT INTO person (NAME,AGE) VALUES ('$name','$age');

Reply With Quote
  #4  
Old August 11th, 2000, 04:01 AM
christucker2 christucker2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 81 christucker2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
You don't. :-) So long as you specify values for all of the columns in the table (null or otherwise) in the order in which they were added to the table, you don't have to specify what the columns are. So, this code will work (barring any typos I'm about to make):
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
create table EMP (
first_name VARCHAR(30),
surname VARCHAR(30),
email_id VARCHAR(10),
PRIMARY KEY( email_id ) );

insert into EMP values ('Chris', 'Tucker', 'christuc' );
[/code]

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > insert into MySQL database with php not working!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway