INSERT Into Tables Not Working Correctly

Problems with the Windows version of XAMPP, questions, comments, and anything related.

INSERT Into Tables Not Working Correctly

Postby ScriptHam » 10. June 2005 15:33

Hi :?

I have tried for several days to debug my code but cannot. I would certainly be grateful for some help.

I have some very simple code to INSERT data into the cdcol database that comes with xampp. when I collect the data from a form it doesn't work but when I write the data into the SQL and run the query it does work.

In more detail the code doesn't appear to produce any effect when the data is collected from the form. When the data is written directly into the query and submitted via the form submit button it is executed twice and a duplicate row in the table is produced.

I have tried another script which has a similar effect, this is more complicated using include files and a function library in its infancy. I have noticed that this other script introduces blank records except for the year which is 0 and the key field which is set to auto increment.

The code is as follows.

Code: Select all
<form action="AddNewLocal3.php" method="post">    <!--form calls itself-->
Title:        <input type="text" name="Title"><br>
Interpret: <input type="text" name="Interpret"><br>
Year:       <input type="text" name="Year"><br>
               <input type="Submit">
</form>
<?

$username ="root";
$password  ="";
$database  ="cdcol";

$titel        = $_POST['Title'];
$interpret = $_POST['Interpret'];
$jahr        = $_POST['Year'];

mysql_connect(localhost,$username,$password);
@mysql_select_db(cdcol) or die( "Unable to select database");


$qry = "INSERT INTO cds VALUES ('$interpret', '$titel', '$jahr')";  // This does not work 10/06/05
//$qry  = ("INSERT INTO cds VALUES ( 'Joan Baez', 'Diamonds and Rust', '1970', '0')   "); //This works twice??
         
mysql_query($qry);

mysql_close();
?>



Can you help please?
I certainly look forward to hearing from anyone.
Many thanks
ScriptHam
ScriptHam
 
Posts: 10
Joined: 06. February 2005 01:03

Postby ScriptHam » 10. June 2005 15:51

Hi

I have a part solution. I changed the query string as follows:

From
$qry = "INSERT INTO cds VALUES ('$interpret', '$jahr', '$titel')";


To
$qry = "INSERT INTO cds (interpret, jahr, titel) VALUES ('$interpret', '$jahr', '$titel')";


Now the second query INSERTS. However it also INSERTS a blank field before the data.

I tried this query style before but it hasn't worked until now.

Any ideas please.
I look forward to hearing from you.
Many thanks

ScriptHam
ScriptHam
 
Posts: 10
Joined: 06. February 2005 01:03


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 123 guests