Jump to content

inserting into databse not working


jaxdevil

Recommended Posts

I am trying to insert values into a database table..the script runs but nothing ever is inserted into the database. Here is the code, any ideas? The data being passed to this script is being passed via POST. Any help would be appreciated.

 

Thanks!

SK

 

<?
$link = mysql_connect(localhost,xxx_xxx,xxxxxx);
mysql_select_db(xxx_xxx);
{
$sql="INSERT INTO checkout (bidnum,deposit_amount,deposit_storage,deposit_type,deposit_code) 
VALUES ('$_POST[bidnumx]', '$_POST[xdeposit_amount]', '1', '$_POST[xdeposit_type]', '$_POST[xdeposit_code]')";
}
$result = mysql_query($sql);
mysql_close($link);

?>

Link to comment
https://forums.phpfreaks.com/topic/75874-inserting-into-databse-not-working/
Share on other sites

<?php
$link = mysql_connect(localhost,xxx_xxx,xxxxxx);
mysql_select_db(xxx_xxx);
{
$sql='INSERT INTO checkout (bidnum,deposit_amount,deposit_storage,deposit_type,deposit_code) 
VALUES ('.$_POST[bidnumx].', 
'.$_POST[xdeposit_amount].', '1', '.$_POST[xdeposit_type].', '.$_POST[xdeposit_code].')';
}
$result = mysql_query($sql);
mysql_close($link);

?>

<?php
$link = mysql_connect(localhost,xxx_xxx,xxxxxx);
mysql_select_db(xxx_xxx);
{
$sql='INSERT INTO checkout (bidnum,deposit_amount,deposit_storage,deposit_type,deposit_code) 
VALUES ('.$_POST[bidnumx].', '.$_POST[xdeposit_amount].', '1', '.$_POST[xdeposit_type].', '.$_POST[xdeposit_code].')';
}
$result = mysql_query($sql);
mysql_close($link);

?>

 

Its the code you pasted above, i just copied it over my old on.

 

Thanks a billion for helping, I am pulling my hair out and I need to get this all done,

SK

<?php
$link = mysql_connect(localhost,xxx_xxx,xxxxxx);
mysql_select_db(xxx_xxx);
{
$sql='INSERT INTO checkout (bidnum,deposit_amount,deposit_storage,deposit_type,deposit_code) 
VALUES ("'.$_POST[bidnumx].'",
"'.$_POST[xdeposit_amount].'", '1', "'.$_POST[xdeposit_type].'", "'.$_POST[xdeposit_code].'")';
}
$result = mysql_query($sql);
mysql_close($link);

?>

can you try

 

<?php
$link = mysql_connect(localhost,xxx_xxx,xxxxxx);
mysql_select_db(xxx_xxx);
{
$sql='INSERT INTO checkout (bidnum,deposit_amount,deposit_storage,deposit_type,deposit_code) 
VALUES ("'.$_POST[bidnumx].'",
"'.$_POST[xdeposit_amount].'", '1', "'.$_POST[xdeposit_type].'", "'.$_POST[xdeposit_code].'")';
}
$result = mysql_query($sql) or die "there was an error".mysql_error();
mysql_close($link);

?>

<?php
$link = mysql_connect(localhost,xxx_xxx,xxxxxx);
mysql_select_db(xxx_xxx);
{
$sql="INSERT INTO checkout (bidnum,deposit_amount,deposit_storage,deposit_type,deposit_code) 
VALUES (".$_POST['bidnumx'].",
".$_POST['xdeposit_amount'].", "1", ".$_POST['xdeposit_type'].", ".$_POST['xdeposit_code'].")";
}
$result = mysql_query($sql) or die "there was an error".mysql_error();
mysql_close($link);

?>

you do not need to specify a link.. but you can... try it like this:

 

<?php
$link = mysql_connect(localhost,xxx_xxx,xxxxxx);
mysql_select_db(xxx_xxx);
{ //whats this? can you remove it?

$sql = "INSERT INTO `checkout` (`bidnum`,`deposit_amount`,`deposit_storage`,`deposit_type`,`deposit_code`) VALUES ('{$_POST['bidnumx']','{$_POST['xdeposit_amount']}','1','{$_POST['xdeposit_type']}','{$_POST['xdeposit_code']}')";
} //and this? part of an if statement?

$result = mysql_query($sql) or die("there was an error").mysql_error();
mysql_close($link);

?>

 

i have some comments in there... about the curly brackets.. what are they for? and i just fixed up your query...

Most of the changes are cosmetic, but I'm sure it will work if your database is configured correctly.  If it doesn't work, I'm very much inclined to believe that your problems lie elsewhere.

 

 

<?php
mysql_connect(localhost,xxx_xxx,xxxxxx);
mysql_select_db(xxx_xxx);

$bidnumx=$_POST['bidnumx'];
$xdeposit_amount=$_POST['xdeposit_amount'];
$xdeposit_type=$_POST['xdeposit_type'];
$xdeposit_code=$_POST['xdeposit_code'];

mysql_query("INSERT INTO `checkout` VALUES ('$bidnumx', '$xdeposit_amount' , '1', '$xdeposit_type', '$xdeposit_code')") or die(mysql_error());
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.