INSERT INTO.....help

Hi Guys

Im just starting out learning php and im trying to INSERT into a database, i have watched tutorials and such but nothing is working. Its probs something really simple but i just cannot suss it, so any help would be great and thankyou in advance. heres my code so far

[php]<?php

if (isset($_POST[‘submitted’])) {

include('Fault_Report_Script.php');

}

$pcid = $_POST['pcid'];
$roomno = $_POST['roomno'];
$studentid = $_POST['studentid'];
$email = $_POST['email'];
$faulttype = $_POST['faulttype'];
$report = $_POST['report'];
$sqlinsert = "INSERT INTO faults (pcid, roomno, studentid, email, faulttype, report) VALUES ('$pcid', '$roomno', '$studentid', '$email', '$faulttype', '$report')";

?>[/php]

This Script calls up another called ‘Fault_Report_Script.php’ which connects to server and database. Thanks for any help.

Karl

Hi Karl,

looks like you built a fair query there, but you don’t do anything with it.
If you have successfully connected to a MySQL database the following would send your query to it.

[php]
mysql_query( $sqlinsert );
if ( mysql_error() )
{ echo “An error occurred in executing the SQL [$sqlinsert] :
”. mysql_error();
}
[/php]
( you wrote the letter but you never sent it )

This code will also tell you something if the database-interaction went wrong. ( it can be helpful )

Anyway, hope this helps.
Good luck!

O.

Thankyou Ojoshiro

For your help, it worked a treat many thanks.

Regards Karl

Sponsor our Newsletter | Privacy Policy | Terms of Service