PHP SQL insert not working properly -


i'm having serious difficulty trying php sql insert work. i'm trying display user data echoes, "insert customer (cust_last, cust_first) values ('user','data') done. "

obviously sql statement, copied directly w3schools' example php insert, i'm unsure why doesn't work. not supposed use "" or something?

thanks help!

<?php $db = odbc_connect('database1', '', ''); $sql="insert customer (cust_last, cust_first)  values ('$_post[cust_last]','$_post[cust_first]')"; $rs=odbc_num_rows($conn); odbc_close($conn); echo "1 record added.";  ?> 

the html form page is:

<html> <body>  <form action="insert.php" method="post"> last name: <input type="text" name="cust_last"> first name: <input type="text" name="cust_first"> <input type="submit"> </form>  </body> </html>  

php associative arrays need single quotes around keys, $_post['cust_last'] valid key, whereas $_post[cust_last] isn't. when inserting php variables strings between quotes, should place curly braces around them.

so appropriate statement (assuming cust_last , cust_first names of columns in customer table):

$sql="insert customer (cust_last, cust_first) values ('{$_post['cust_last']}','{$_post['cust_first']}')"; 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -