Jump to content

No error, but not INSERTing a new record


scott.stephan

Recommended Posts

//Send off the Rec to be written
$qry_new_rec = "INSERT INTO scores(grade,section,group,group_name,year,semester,u_id)
VALUES($grade,$section,$g_num,$g_name,$year,$semester,$u_id)";
$result = @mysql_query($qry_new_rec);
echo "Rec written?";

 

Assuming that all of those variables are named correctly and have values, why won't this write a record? I feel like I'm overlooking something major and I just cant see it. This runs fine without any errors, but it doesn't create a new record. Here;s the rest of the (sloppy sloppy) code:

 

require_once('config.php'); //DB settings
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
/* Open DB Connect */
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
if($link){
    echo "Successful DB connect";
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
/*END DB CONNECT */

/*Nab the POST data. Yes, I know this is sloppy, but it'll do for Alpha */
$semester=ucfirst($_POST['semester']); //Move to ALLCAPS to ascertain u_id predicatbility.
$grade=$_POST['grade'];
$section=$_POST['section'];
$g_num=$_POST['g_num'];
$g_name=$_POST['g_name'];
$year=date('y');
//Compile a unique ID for a group: GradeSectionNumberSemesterYear, i.e 612F09 for Grade 6 Section 1 Group 2 Fall of 2009
$u_id=$grade.$section.$g_num.$semester[0].date('y');
echo "Semester: $semester <br/>
Grade: $grade <br/>
Section: $section <br/>
Group Num: $g_num <br/>
Group Name: $g_name
Unique ID: $u_id";
//Send off the Rec to be written
$qry_new_rec = "INSERT INTO scores(grade,section,group,group_name,year,semester,u_id)
VALUES($grade,$section,$g_num,$g_name,$year,$semester,$u_id)";
$result = @mysql_query($qry_new_rec);
echo "Rec written?";

Link to comment
https://forums.phpfreaks.com/topic/175777-no-error-but-not-inserting-a-new-record/
Share on other sites

Archived

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

×
×
  • Create New...

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.