Sponsored Links
No booking fees on all published flights!


Post Reply 
 
Thread Rating:
  • 1 Votes - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MYSQL Insert Record - This Works!
06-06-2009, 10:19 AM (This post was last modified: 06-06-2009 10:19 AM by admin.)
Post: #1
MYSQL Insert Record - This Works!
Hello World!
http://www.phpeasystep.com/mysql/5.html


Create MYSQL Table

CREATE TABLE `test_mysql` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`lastname` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=0 ;


HTML FORM



<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="insert_ac.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
</tr>
<tr>
<td width="71">Name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><input name="lastname" type="text" id="lastname"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>


PHP CODE

<?php

$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}

else {
echo "ERROR";
}

// close connection
mysql_close();
?>
Find all posts by this user
Quote this message in a reply
10-09-2009, 10:01 PM
Post: #2
RE: MYSQL Insert Record - This Works!
Hello World!
I did it! Thanks to your complete code. I was able to insert mysql record to my project after bumping to your post. Most of the codes i searched earlier have bugs on it and I do not have the time to check them, but your's worked on first trial. Thanks!




___________________________________
Multivariate Testing
Quote this message in a reply
10-09-2009, 10:55 PM
Post: #3
RE: MYSQL Insert Record - This Works!
Hello World!
(10-09-2009 10:01 PM)welllyn07 Wrote:  I just want to say thank you for sharing with us the codes that we must have in MySql in inserting a record.



No problem..

Let me know if you need anymore help.
Find all posts by this user
Quote this message in a reply
12-02-2011, 12:33 AM
Post: #4
RE: MYSQL Insert Record - This Works!
Hello World!
wetwet
Find all posts by this user
Quote this message in a reply
12-02-2011, 12:33 AM
Post: #5
RE: MYSQL Insert Record - This Works!
Hello World!
(12-02-2011 12:33 AM)admin Wrote:  wetwet

wtwewetwetwe
Find all posts by this user
Quote this message in a reply
12-02-2011, 12:33 AM
Post: #6
RE: MYSQL Insert Record - This Works!
Hello World!
(12-02-2011 12:33 AM)admin Wrote:  
(12-02-2011 12:33 AM)admin Wrote:  wetwet

wtwewetwetwe

tweewwet
Find all posts by this user
Quote this message in a reply
12-02-2011, 12:34 AM
Post: #7
RE: MYSQL Insert Record - This Works!
Hello World!
ewrwerwrerwe
Find all posts by this user
Quote this message in a reply
12-02-2011, 12:34 AM
Post: #8
RE: MYSQL Insert Record - This Works!
Hello World!
(12-02-2011 12:33 AM)admin Wrote:  
(12-02-2011 12:33 AM)admin Wrote:  
(12-02-2011 12:33 AM)admin Wrote:  wetwet

wtwewetwetwe

tweewwet

werwerwer
Find all posts by this user
Quote this message in a reply
12-02-2011, 12:34 AM
Post: #9
RE: MYSQL Insert Record - This Works!
Hello World!
ewrwewe
Find all posts by this user
Quote this message in a reply
12-02-2011, 12:34 AM
Post: #10
RE: MYSQL Insert Record - This Works!
Hello World!
wrwrwerwerwer
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 5 Guest(s)