hi everyone, i'm very new with PHP. i use asp in my job but for my site i want to use php (with wamp server 2.0). i don'to know how to insert some records into mysql database. it's so simply for me in asp but i have no idea in php. can any from you convert this code for me? this is my asp script: <% addEmail=request.Form("addEmail") company=request.Form("company") subject=request.Form("subject") remarks=request.Form("remarks") Set Con = Server.CreateObject( "ADODB.Connection" ) Con.Open "storeDSN","username","password" %> <% if addEmail = "1" then %> <%sqlString = "INSERT INTO emails (name,subject,remarks) VALUES ( '"&name&"','"&subject&"','"&remarks&"')" Con.Execute sqlString response.Write("record ok!") %> <% Con.Close %><% else %>error<% end if %> HTML: username of mysql database is "root" and password is blank (by default). thanks in advance.
<?php if( $_POST["do"] == 1 ) { // Database configuration $host = "localhost"; $user = "root"; $pass = ""; $database = "database"; $table = "emails"; // Connect! $connection = mysql_connect( $host, $user, $pass ); // Select the database mysql_select_db( $database, $connection ); // Catch the form values and assign them variables $name = $_POST["name"]; $subject = $_POST["subject"]; $remark = $_POST["remark"]; // Insert the database mysql_query( "INSERT INTO $table (name, subject, remark) VALUES ($name, $subject, $remark)" ); // All done! echo "Done!"; } ?> <form method="post" action=""> <input type="hidden" name="do" value="1"> Name: <input type="text" name="name" /> Subject: <input type="text" name="subject" /> Remark: <input type="text" name="remark" /> <input type="submit" value="Submit" /> </form> PHP: Hope that helps