PDA

View Full Version : Insert data into My Sql



mburt
08-28-2006, 02:49 PM
Hi.

How do I insert info from a textbox to a text file on my MySql database?

I know how to connect to my database using PHP, so all I need now is to be able to add data to it, then retrieve it on the following page.

Here's what I'm trying to do:
A page where user's can put their name and message, and it pops out on the other page. Basically like a comments page.

DimX
08-28-2006, 03:07 PM
How do I insert info from a textbox to a text file on my MySql database?
To a text file on your MySQL database???
Perhaps you mean just into the database? Use mysql_query function (see php.net).

mburt
08-28-2006, 03:08 PM
Yes, sorry I just meant into the database :)

DimX
08-28-2006, 03:12 PM
Just check out the mysql_query function on php.net and you may also want to read that (http://dev.mysql.com/doc/refman/4.1/en/sql-syntax.html).

mburt
08-28-2006, 03:16 PM
Err... I don't know what to look for. Could you help me?

DimX
08-28-2006, 03:19 PM
Look at the samples: http://php.net/mysql_query



<?php
/* Connecting, selecting database
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');
*/

// !!! Performing SQL query, that's how you GET the data OUT of the database. !!!
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

/* Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
*/
?>

blm126
08-28-2006, 04:29 PM
To access a database you need to understand SQL. Here (http://www.freewebmasterhelp.com/tutorials/phpmysql) is a good SQL tutorial.

kaali
09-01-2006, 06:41 PM
To access a database you need to understand SQL. Here (http://www.freewebmasterhelp.com/tutorials/phpmysql) is a good SQL tutorial.

Link doesn't works:
http://www.freewebmasterhelp.com/tutorials/phpmysql

mburt
09-01-2006, 08:23 PM
Oh crap... That page must have been taken down recently. I had used that link and found it quite handy. I have to look for another one I guess.

eukhost.com
09-12-2006, 04:33 PM
Hello,

Please try to use this link may be it will help

http://www.eukhost.com/support/phpmyadmin.php