Jump to content


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


Problem with Data insert into DB!

Recommended Posts

Hi I am a newbie at PHP and MySQL.
I have this function that is suppose to insert the values into the temp database.
I am sure the values are being passed and splited from file(CSV) into the correct variables.
But when it must write to database the Data is not writen.
Is there something wrong with my syntax?
I do get the Last echo, that means all fields has been processed...but still no data in DB.
function breakname($fullnamein)
    $fullnamebreak = explode(" ",$fullnamein);
    //inticate that these variables are the gobal ones not local ones
    global $title,$initials,$surname;
case 0 :$title = $fullnamebreak[$p];break;
case 1 :$initials = $fullnamebreak[$p];break;
case 2 :$surname = $fullnamebreak[$p];break;
//$link = "/EclipseWorkspace/LPCL101/files/*.php";
//Test File  /EclipseWorkspace/LPCL101/files/eov321_2006.csv

//add the refix http to the link to use abolute access
$link = "http://localhost/".$link;
$parts = explode(" ",$format); //break the input format into parts

$db = mysql_connect("localhost","root","password1");//connect to database

//open file or catch error
$file =  fopen($link, "r")
or exit("Unable to open file!<br><br>" .
"<a href='extract_data_file.php'>Back</a>");

//create a temp password for student = 12345
$password = 12345;
$x=1; //Type holder
//Read a line of the file until the end is reached
$line= fgets($file);//read line
$linebreak = explode(",",$line );//break up the line
case "%name"  : breakname($linebreak[$i]);
case "%num"  : $lnumber = $linebreak[$i];
case "%course": $course = $linebreak[$i];
//Write line data to database  
  $sql = "INSERT INTO Students (S_StudentNum,S_Password,S_Surname,S_Title,S_Initials)
VALUES ('$lnumber','$password','$surname','$title','$initials')";
$result = mysql_query($sql);

//Write line data into Course links
$sql = "INSERT INTO CourseLinks (CL_Type,CL_Person,CL_Course)
VALUES ('$x','$lnumber','$course')";
$result = mysql_query($sql);
echo "Thank you! Information updated.<br>";

Share this post

Link to post
Share on other sites
You don't check for errors returned after executing queries.

$result = mysql_query($sql) or die('Query: "'.$sql.'" failed, MySQL returned: "'.mysql_error().'"');

It IS [url=http://www.phpfreaks.com/forums/index.php/topic,95443.0.html]in the FAQ[/url] you know...

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.