Jump to content

Archived

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

supanoob

Inserting

Recommended Posts

well, i have the following code and for some reason it doesnt insert into the DB nothing happens nothing gets inserted

[code]session_start();
require_once('dbconnect2.php');

$ip=($_SERVER['REMOTE_ADDR']);
$T1=$_POST['T1'];
$D1=$_POST['D1'];
$D2=$_POST['D2'];
$D3=$_POST['D3'];
$D4=$_POST['D4'];
$D5=$_POST['D5'];
$D6=$_POST['D6'];
$D7=$_POST['D7'];
$D8=$_POST['D8'];
$D9=$_POST['D9'];
$D10=$_POST['D10'];

$T1=trim($T1);
$D1=trim($D1);
$D2=trim($D2);
$D3=trim($D3);
$D4=trim($D4);
$D5=trim($D5);
$D6=trim($D6);
$D7=trim($D7);
$D8=trim($D8);
$D9=trim($D9);
$D10=trim($D10);



$query="insert into `match` (name, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) values ('$T1', '$D1', '$D2', '$D3', '$D4', '$D5', '$D6', '$D7', '$D8', '$D9', '$D10')";
$result=mysql_query($query);

echo "You have added your name and answers to our Database. We will be in touch within the week.";[/code]

Share this post


Link to post
Share on other sites
Try changing:

$result=mysql_query($query);

to:

$result=mysql_query($query) or die(mysql_error());

to see what the error is.

Share this post


Link to post
Share on other sites
Have you checked mysql_affected_rows to see if it thinks a record has been inserted? If there is no error then it probably does. Which I'd suggest might mean the record is being inserted. I assume you've checked the number of records to ensure it isn't actually going in.

If all of that is fruitless then you have a ponderer in my opinion.

Sam.

Share this post


Link to post
Share on other sites
session_start();
require_once('dbconnect2.php');

$ip=($_SERVER['REMOTE_ADDR']);
$T1=$_POST['T1'];
$D1=$_POST['D1'];
$D2=$_POST['D2'];
$D3=$_POST['D3'];
$D4=$_POST['D4'];
$D5=$_POST['D5'];
$D6=$_POST['D6'];
$D7=$_POST['D7'];
$D8=$_POST['D8'];
$D9=$_POST['D9'];
$D10=$_POST['D10'];

$T1=trim($T1);
$D1=trim($D1);
$D2=trim($D2);
$D3=trim($D3);
$D4=trim($D4);
$D5=trim($D5);
$D6=trim($D6);
$D7=trim($D7);
$D8=trim($D8);
$D9=trim($D9);
$D10=trim($D10);


if($_POST['submit']){
$query="insert into `match` (name, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) values ('$T1', '$D1', '$D2', '$D3', '$D4', '$D5', '$D6', '$D7', '$D8', '$D9', '$D10')";
$result=mysql_query($query);

echo "You have added your name and answers to our Database. We will be in touch within the week.";

}

Share this post


Link to post
Share on other sites
I can't see what the previous post is on about (maybe it isn't finished) but I also should have mentioned that it is always worth echoing the SQL statement to yourself if it doesn't work, and then try applying it directly to the database rather than through PHP. Might get you some more clues.

Sam.

Share this post


Link to post
Share on other sites
give the insert a condition

what ever you have named the form ok.

if($POST['submit']){

insert

}

Share this post


Link to post
Share on other sites
Post your database information so we can have a proper look ok.

Share this post


Link to post
Share on other sites

×

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.