|
Posted by Tom on 02/07/07 18:17
On 7 Feb 2007 09:54:53 -0800, tomhughes_86@hotmail.com wrote...
>
>Hi,
>I'm basically creating a system which add records to a pre made SQL
>database built in SQLyog.
>So far i'va had no problems actually connecting to the database and
>displaying resulst but I just cannot make it add records. I know its
>connected to the database as a I made a mistake with connection
>details on purpose to see if it recognised it.
>I just add data into a text field, click submit and the page goes to
>a
>new, blank page with no changes to the table when I check in SQLyog.
>Any help would be much appreciated, as I am very new to PHP.
>Thanks Tom.
>
>Here is the code I have tried (simple add before I code the proper
>system):
>
>
>HTML page
><form action="script.php" method="post">
>Test: <input type="text" name="test2"><br>
><input type="Submit">
></form>
>
>
>and the PHP script to add data:
><?
>$host="localhost"
>$username="root";
>$database="test";
>
>
>$test2=$_POST['test2'];
>
>
>mysql_pconnect($host,$username);
>@mysql_select_db($database) or die( "Unable to select database");
>
>
>$query = "INSERT INTO test2 VALUES ('','$test2')";
>mysql_query($query);
>
>
>mysql_close();
>?>
>
Might be worth using the "mysql_error()" function to capture any potential
errors in your SQL statement.
The syntax of your insert command looks a little off. Might need something
closer to...
$query = "INSERT INTO table1 (col_name) VALUES ('$test2')";
It didn't look like you had the column defined where you wanted to insert the
value.
Tom
--
Help a Community by Participating in Ours
We donate your subscription fees to the charity you choose
100% of your first month, 10% thereafter.
http://newsguy.com/charity.asp
Navigation:
[Reply to this message]
|