Jump to content

Recommended Posts

Hey guys,

just a simple probelm. I can't figured out whats wrong with my insert into statement. i tried everything but it doesn't want to work.

$query ="INSERT INTO `students` ('ID' , 'Date' , `FirstName` , `Surname` , `Phone` , `Mobile` , `UniversityEmail` , `Email` , `Nationality` , `Nationality2` , `Region` , `University` , `SubjectStudied` , `Specialisation` , `PresentYear` , `TotalYear` , `PlacementNI` , 'StudyLevel') VALUES ('','',`$FirstName`,`$Surname` ,`$Phone`,`$MobilePhone`,`$UniversityEmail` , `$Email' , `$Nationality`,'$Nationality2',`$Region`,`$University`,`$SubjectStudied`,`$Specialisation`,`$PresentYear`,`$TotalYears`,`$PlacementNI`,`$StudyLevel`)";
$result = mysql_query($query) or die(mysql_error());

echo ($query);

Are fields are complete and also databasase should accept all data.

cheers
Link to comment
https://forums.phpfreaks.com/topic/16128-php-mysql-insert/
Share on other sites

pixy, backticks are for column and table names, and they're not required, but nice to have around columns if they're keywords or special characters. quotes are for values, especially strings.

Ferenc, the query will execute if $result is there.. it's the backticks in the VALUES part that's causing the problem.
Link to comment
https://forums.phpfreaks.com/topic/16128-php-mysql-insert/#findComment-66529
Share on other sites

The backticks where addressed in posts previous to mine.

Since the query was placed in the variable it cannot execute until called.
[code]if (!$result) {
  die('Invalid query: ' . mysql_error());
}[/code]

My question to Grega, does the page display an error?

If it does, the query is executed, and the backticks cause the problem.
Link to comment
https://forums.phpfreaks.com/topic/16128-php-mysql-insert/#findComment-66537
Share on other sites

[code]$result = mysql_query($query) or die(mysql_error());[/code]

This WILL execute :). when mysql_query returns false, the die part will be called. "or" is evaluated after "=". if mysql_query is true, die won't be processed because it satisfy the "or" condition.

however you do it, the problem lies in the query. fix the backticks first, and report any problems.
Link to comment
https://forums.phpfreaks.com/topic/16128-php-mysql-insert/#findComment-66542
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.