deansaddigh Posted May 13, 2008 Share Posted May 13, 2008 Hi all here is some code and i am just wondering why the sql for the Course table is not writing to the course table. I have higlighted it red so you can easily see what i mean. The sql code above it works very well , but for somereason it seems to be ignoring the code in red ??? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php include("includes/ico.html"); ?> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <?php include("db/connection.php"); //Connection string for db?> <link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" /> </head> <body> <div id="container"> <div id="header"> <?php include("includes/language.html"); ?> </div> <div id="sidebar"> <?php include("includes/navigation.html"); ?> </div> <div id="content"> <div align="center"> <?php // Variable for Student details part of form $title=mysql_real_escape_string($_POST['title']); $First_name=mysql_real_escape_string($_POST['First_name']); $username=mysql_real_escape_string($_POST['username']); $Second_name=mysql_real_escape_string($_POST['Second_name']); $password=mysql_real_escape_string($_POST['password']); $DOB=mysql_real_escape_string($_POST['DOB']); $Nationality=mysql_real_escape_string($_POST['Nationality']); $Tel=mysql_real_escape_string($_POST['Tel']); $emergency_tel=mysql_real_escape_string($_POST['emergency_tel']); $email=mysql_real_escape_string($_POST['email']); $address=mysql_real_escape_string($_POST['address']); $Proffesion=mysql_real_escape_string($_POST['Proffesion']); $faxnumber=mysql_real_escape_string($_POST['faxnumber']); $number_years=mysql_real_escape_string($_POST['years_of_study']); $smoke=mysql_real_escape_string($_POST['Smoke']); $Special_requirements=mysql_real_escape_string($_POST['Special_requirements']); // End of Variables for Student details // Sql Query sends all data from the form into the student table $student_details="INSERT INTO Student (Title, First_Name,Username,Surname,Password,Dob,Nationality,Telephone_number,Emergency_number,Email,Address,Proffesion,Years_of_english_already_studied,Smoker,Special_requirements,Fax_number) VALUES ('$title','$First_name','$username','$Second_name','$password','$DOB','$Nationality','$Tel','$emergency_tel','$email','$address','$Proffesion','$number_years','$smoke','$Special_requirements','$faxnumber')"; //end of query one [color=red][font=Verdana]// Variable for Course details part of form $Course_name=mysql_real_escape_string($_POST['Course_name']); $Course_start_date=mysql_real_escape_string($_POST['Course_start_date']); $Course_end_date=mysql_real_escape_string($_POST['Course_end_date']); $Number_of_weeks=mysql_real_escape_string($_POST['Number_of_weeks']); //end Variables $course_details="INSERT INTO Course (Course_Name,Course_start_date,Course_end_date,Number_of_weeks) VALUES ('$Course_name','$Course_start_date','$Course_end_date','$Number_of_weeks')";[/font][/color] if (!mysql_query($student_details,$conn)) { die('Error: ' . mysql_error()); } echo "<h2>Thanks For submittiing the data to the us, we will be in-touch shortly</h2><br />"; include("db/close_connection.php"); //close db connection ?> </div> </div> <div id="footer"> <?php include("includes/footer.html"); ?> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/105415-solved-sql-not-writing-to-db/ Share on other sites More sharing options...
rhodesa Posted May 13, 2008 Share Posted May 13, 2008 This line here: $course_details="INSERT INTO Course (Course_Name,Course_start_date,Course_end_date,Number_of_weeks) VALUES ('$Course_name','$Course_start_date','$Course_end_date','$Number_of_weeks')"; doesn't actually do any mysql work. It just sets the string into that variable. This is the line that actually sends the string to mysql: if (!mysql_query($student_details,$conn)) { die('Error: ' . mysql_error()); } echo "<h2>Thanks For submittiing the data to the us, we will be in-touch shortly</h2><br />"; as you can see, it sends the Student one, but not the course one. So, all you have to do is add some code directly after the above code. The final would look like: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php include("includes/ico.html"); ?> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <?php include("db/connection.php"); //Connection string for db?> <link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" /> </head> <body> <div id="container"> <div id="header"> <?php include("includes/language.html"); ?> </div> <div id="sidebar"> <?php include("includes/navigation.html"); ?> </div> <div id="content"> <div align="center"> <?php // Variable for Student details part of form $title=mysql_real_escape_string($_POST['title']); $First_name=mysql_real_escape_string($_POST['First_name']); $username=mysql_real_escape_string($_POST['username']); $Second_name=mysql_real_escape_string($_POST['Second_name']); $password=mysql_real_escape_string($_POST['password']); $DOB=mysql_real_escape_string($_POST['DOB']); $Nationality=mysql_real_escape_string($_POST['Nationality']); $Tel=mysql_real_escape_string($_POST['Tel']); $emergency_tel=mysql_real_escape_string($_POST['emergency_tel']); $email=mysql_real_escape_string($_POST['email']); $address=mysql_real_escape_string($_POST['address']); $Proffesion=mysql_real_escape_string($_POST['Proffesion']); $faxnumber=mysql_real_escape_string($_POST['faxnumber']); $number_years=mysql_real_escape_string($_POST['years_of_study']); $smoke=mysql_real_escape_string($_POST['Smoke']); $Special_requirements=mysql_real_escape_string($_POST['Special_requirements']); // End of Variables for Student details // Sql Query sends all data from the form into the student table $student_details="INSERT INTO Student (Title, First_Name,Username,Surname,Password,Dob,Nationality,Telephone_number,Emergency_number,Email,Address,Proffesion,Years_of_english_already_studied,Smoker,Special_requirements,Fax_number) VALUES ('$title','$First_name','$username','$Second_name','$password','$DOB','$Nationality','$Tel','$emergency_tel','$email','$address','$Proffesion','$number_years','$smoke','$Special_requirements','$faxnumber')"; //end of query one [color=red][font=Verdana]// Variable for Course details part of form $Course_name=mysql_real_escape_string($_POST['Course_name']); $Course_start_date=mysql_real_escape_string($_POST['Course_start_date']); $Course_end_date=mysql_real_escape_string($_POST['Course_end_date']); $Number_of_weeks=mysql_real_escape_string($_POST['Number_of_weeks']); //end Variables $course_details="INSERT INTO Course (Course_Name,Course_start_date,Course_end_date,Number_of_weeks) VALUES ('$Course_name','$Course_start_date','$Course_end_date','$Number_of_weeks')";[/font][/color] if (!mysql_query($student_details,$conn)) { die('Error: ' . mysql_error()); } if (!mysql_query($course_details,$conn)) { die('Error: ' . mysql_error()); } echo "<h2>Thanks For submittiing the data to the us, we will be in-touch shortly</h2><br />"; include("db/close_connection.php"); //close db connection ?> </div> </div> <div id="footer"> <?php include("includes/footer.html"); ?> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/105415-solved-sql-not-writing-to-db/#findComment-539858 Share on other sites More sharing options...
deansaddigh Posted May 13, 2008 Author Share Posted May 13, 2008 Thanks So much for that, problem solved.# Quote Link to comment https://forums.phpfreaks.com/topic/105415-solved-sql-not-writing-to-db/#findComment-539880 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.