PDA

View Full Version : php sql insert


jakepeg
06-29-2005, 06:24 PM
I'm new to php and I have an easy 1 for you - I think

is this right and how to execute it as the execute function is giving error....

<?php
mysql_connect("localhost","user_me","pass_me");
mysql_select_db("my_contacts");

$first_name = $_POST['first_name'];
$last_name = $_POST['first_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];

$insertSQL = "insert into contacts values (NULL, '".$last_name."', '".$first_name."', '".$phone."', '".$email."', '''', '''')";
Execute($insertSQL);
?>

snapple
06-29-2005, 06:49 PM
Can you please format your code using the [.php][/php] (omitting the period).

Might be helpful to supply the error message too.

jakepeg
06-29-2005, 07:07 PM
Fatal error: Call to undefined function: execute() in /home/jakepeg/public_html/flashmx_dbInsert.php on line 11


<?php
mysql_connect("localhost","user_me","pass_me");
mysql_select_db("my_contacts");

$first_name = $_POST['first_name'];
$last_name = $_POST['first_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];

$insertSQL = "insert into contacts values (NULL, '".$last_name."', '".$first_name."', '".$phone."', '".$email."', '''', '''')";
Execute($insertSQL);
?>

splict
06-29-2005, 07:23 PM
there is no function in php called execute. you need to use mysql_query() also you should close your connection when you are through with it. Here is a page with an example. Not sure how great it is - it was the first one that came up in google, but it should get you started. http://www.createafreewebsite.net/phpmysql/insert.html