Cannot insert data into MySql table

Associate
Joined
6 Mar 2009
Posts
495
Im having problem when i go to insert data from a table into MySql table.

Here is my php code:
Code:
<?php

$Date = $_POST['Date'];
$StartTime = $_POST['StartTime'];
$TestTime = $_POST['TestTime'];
$t1 = $_POST['t1'];
$t2 = $_POST['t2'];
$t3 = $_POST['t3'];
$t4 = $_POST['t4'];
$t5 = $_POST['t5'];
$t6 = $_POST['t6'];
$t7 = $_POST['t7'];
$t8 = $_POST['t8'];
$Initials = $_POST['Initials'];
$PassFail = $_POST['PassFail'];

mysql_connect("localhost","***","******");
mysql_select_db("*******");

$query="INSERT INTO testing (Date, StartTime, TestTime, t1, t2, t3, t4, t5, t6, t7, t8, Initials,PassFail)
VALUES
('NULL','".$Date."','".$StartTime."','".$TestTime."','".$t1."','".$t2."','".$t3."','".$t4."','".$t5."','".$t6."','".$t7."','".$t8."','".$Initials."','".$PassFail."')";

$result=mysql_query($query)or die('Error updating database');
?>

Im getting the 'error update database' message when i run that code and the data doesnt insert into mt table.

Any suggestions please??
 
I basically means that someone could pull or remove data or even delete your entire database by manipulating your $_post variables, which would change the database query submitted.
 
I have removed the 'NULL' and its still the same.
SQL Injection?? Could you explain please.

exploits_of_a_mom.png
 
Replace
Code:
$result=mysql_query($query)or die('Error updating database');
with
Code:
$result=mysql_query($query);
echo 'Sql query: ' . $query . '<br><br>Mysql error: ';
print_r(mysql_error());

Should give you a reasonable idea of what the problem it.
 
Ok thanks that helped me find some errors:)

If i run the php file on its own it inserts a blank row into the database as it should.

But if i enter the data into the form and hit submit nothing inserts into the database.

Must be something wrong with my submit button!

I have the form action pointing to the php file and the method=post.

Is that correct??
 
Back
Top Bottom