Friends., i want to run 2 files in my server, 1. a.php 2. insert.php in a.php i have: <form action="insert.php" method="post"> Value1: <input type="text" name="field1-name"><br> Value2: <input type="text" name="field2-name"><br> <input type="Submit"> </form> PHP: in insert.php i have: <?php $username="testforum123"; $password="utRHApEFr3xqrHPC"; $database="testforum"; $field1-name=$_POST['Value1']; $field2-name=$_POST['Value2']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO tablename VALUES ('','$field1-name','$field2-name'); mysql_query($query); mysql_close(); ?> PHP: When i click on submit button..... i am getting the error: Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\insert.php on line 6 Whats wrong
You can't use - within your $variables: Change: $field1-name=$_POST['Value1']; $field2-name=$_POST['Value2']; PHP: Too: $field1name=$_POST['Value1']; $field2name=$_POST['Value2']; PHP: and then call them accordingly.
You are also misplacing the " in the query statement. Change: $query = "INSERT INTO tablename VALUES ('','$field1-name','$field2-name'); PHP: to something like this... $query = "INSERT INTO tablename VALUES ('{$field1name}','{$field2name}')"; PHP: Regards, Steve
Thanksssssssssss friends, thanks a lot i got.. But friends...... will you tell me how to store them in my database.., i dont know how to create the database table..just neww. please tell. this is my final... question, how to create database table for above script ?
a.php: <form action="insert.php" method="post"> Value1: <input type="text" name="field1name"><br> Value2: <input type="text" name="field2name"><br> <input type="Submit"> </form> Code (markup): insert.php: <?php error_reporting(E_ALL); /* Read up on MySQL INSERT @ http://www.w3schools.com/PHP/php_mysql_insert.asp */ $username="testforum123"; $password="utRHApEFr3xqrHPC"; $database="testforum"; $field1name=$_REQUEST['field1name']; $field2name=$_REQUEST['field2name']; $con = mysql_connect("localhost",$username,$password); mysql_select_db($database, $con) or die(mysql_error()); mysql_query("INSERT INTO tablename (`columnname1`, `columnname2`) VALUES ($field1name,$field2name)"); mysql_close($con); ?> PHP: