PHP Code:
<?
//connect to db
$link = mysql_connect("cmvthungry.gictools.net","USER","PW");
//select which database
mysql_select_db("cmvthungry");
//convert all the posts to variables:
$name = $_POST['name'];
$building = $_POST['building'];
$order = $_POST['order'];
$comments = $_POST['comments'];
//Insert the values into the correct database with the right fields
$sql = 'INSERT INTO 'orders' ('name', 'building', 'order', 'comments') VALUES ($name, $building, $order, $comments)';
$result = mysql_query($sql);
if(!$result) echo mysql_error();
?>
Change that to:
PHP Code:
<?
//connect to db
$link = mysql_connect("cmvthungry.gictools.net","USER","PW");
//select which database
mysql_select_db("cmvthungry");
//convert all the posts to variables:
$name = $_POST['name'];
$building = $_POST['building'];
$order = $_POST['order'];
$comments = $_POST['comments'];
//Insert the values into the correct database with the right fields
$sql = "INSERT INTO orders (name, building, order, comments) VALUES '".$name."', '".$building."', '".$order."', '".$comments."'";
$result = mysql_query($sql)or die(mysql_error());
?>
Can I ask, Are you running this code on the same server as where your database is?
Then...
Change this:
PHP Code:
if(isset($_POST)) {
$nome_prodotto = $_POST['nome_prodotto'];
$prezzo = $_POST['prezzo'];
$descr_breve = $_POST['descr_breve'];
$descr_lunga = $_POST['descr_lunga'];
$sql = 'INSERT INTO prodotti (nome_prodotto, prezzo, descr_breve, descr_lunga) VALUES ('$nome_prodotto', '$prezzo', '$descr_breve', '$descr_lunga');';
if (@mysql_query($sql)) {
echo '<p>Your product has been added.</p>';
} else {
echo '<p>Error adding submitted product: ' .
mysql_error() . '</p>';
}
}
To this...
PHP Code:
$nome_prodotto = $_POST['nome_prodotto'];
$prezzo = $_POST['prezzo'];
$descr_breve = $_POST['descr_breve'];
$descr_lunga = $_POST['descr_lunga'];
$sql = "INSERT INTO prodotti (nome_prodotto, prezzo, descr_breve, descr_lunga) VALUES '".$nome_prodotto."', '".$prezzo."', '".$descr_breve."', '".$descr_lunga."'";
$result = mysql_query($sql)or die(mysql_error());
if( $result ) {
echo 'Your product has been added.';
} else {
echo 'Error adding submitted product.';
}
In the above i removed if (isset($_POST) ) because it's not valid. It needs an attribute like $_POST['name'] for example.
Tip:
You need to learn the syntax - Where ; should go, how to use single and double quotes correctly in your queries, and so on.
Bookmarks