aosmith Posted December 31, 2007 Share Posted December 31, 2007 [code=php:0]if ($_POST) { $sub=$_POST['sub']; $num=$_POST['num']; $ins=$_POST['ins']; // first of all load the tables require_once("db.inc.php"); //connect to mysql db or kick out an error code $connect=mysql_connect('localhost', $user, $pass) or die(mysql_error); //connect to notpanda database or error code mysql_select_db('notepand_') or die(mysql_error); //query to select password $sql = 'SELECT * from `login_users` WHERE `email`="'.$email.'" LIMIT 1'; $result=mysql_query($sql) or die(mysql_error); if (!$result) { die ("Database Failure: Hang in there we're working on it"); } while ($login_users = mysql_fetch_assoc($result)) { // Grab classes $sql='SELECT * FROM `courses` where `sub`="'.$sub.'" AND `num`="'.$num.'" AND `ins`="'.$ins.'" AND `sid`="'.$sid.'"'; $result=mysql_query($sql) or die(mysql_error); if (!$result) { die ("Database Failure: Hang in there we're working on it"); } while ($courses = mysql_fetch_assoc($result)) { if (mysql_num_rows($result) == 0) { $sid=$_SESSION['sid']; $sql='INSERT INTO `courses` ("sid","sub","num","ins") VALUES ("'.$sid.'","'.$sub.'","'.$num.'","'.$ins.'")'; $insert=mysql_query($sql) or die(mysql_error()); //grab the cid now $sql='SELECT * FROM `courses; ` where `sub`="'.$sub.'" AND `num`="'.$num.'" AND `ins`="'.$ins.'" AND `sid`="'.$sid.'" LIMIT 1'; $result=mysql_query($sql) or die($_SESSION['error']=mysql_error()." Error Code: 2.3"); while ($courses2=mysql_fetch_assoc($result)) { $cid=$courses2['cid']; } } if (mysql_num_rows($result) > 0) { $cid=$courses['cid']; } $cid1= $_SESSION['courses']; // combine old and new courses $cid2= $cid1.",".$courses['cid']; // update db entry $sql='UPDATE `login_users` SET cid = "'.$cid2.'" WHERE `email` = "'.email.'" LIMIT 1'; mysql_query($sql) or die(mysql_error()); //update session vars $_SESSION['courses']=$cid2; //now we should be all set so send them to their backpack mysql_free_result($result); header("Location: /backpack.php") or die("couldnt forward"); } } } [/code] I can't figure it out for the life of me... it returns a blank Link to comment https://forums.phpfreaks.com/topic/83832-can-somebody-point-out-whats-wrong-with-this-code/ Share on other sites More sharing options...
Dane Posted December 31, 2007 Share Posted December 31, 2007 Can you put your code in the [code] tags please. Have you tried echoing out the querys? To see what is going wrong and where?[/code] Link to comment https://forums.phpfreaks.com/topic/83832-can-somebody-point-out-whats-wrong-with-this-code/#findComment-426659 Share on other sites More sharing options...
eyalrosen123rulezz Posted December 31, 2007 Share Posted December 31, 2007 did you wrote session_start(); in the beginning of the page? Link to comment https://forums.phpfreaks.com/topic/83832-can-somebody-point-out-whats-wrong-with-this-code/#findComment-426663 Share on other sites More sharing options...
GingerRobot Posted December 31, 2007 Share Posted December 31, 2007 When you say 'it returns a blank' What do you actually mean? Do you recieve a page with nothing on it? If so, i would imagine there is an error somewhere, but you have the setting display_errors off. Try adding these two lines at the top of your script: <?php ini_set('display_errors','On'); error_reporting(E_ALL); ?> And show us the errors. If thats not what you mean, then please expain in some more detail. Link to comment https://forums.phpfreaks.com/topic/83832-can-somebody-point-out-whats-wrong-with-this-code/#findComment-426669 Share on other sites More sharing options...
aosmith Posted December 31, 2007 Author Share Posted December 31, 2007 i stop getting echos following this line of code. I have no errors or warnings even with errors turned on. and yes i started the session. [code=php:0]echo $login_users['email']."<br />"; // Grab classes $sql='SELECT * FROM `courses` where `sub`="'.$sub.'" AND `num`="'.$num.'" AND `ins`="'.$ins.'" AND `sid`="'.$sid.'"'; $result=mysql_query($sql) or die(mysql_error); if (!$result) { die ("Database Failure: Hang in there we're working on it"); } while ($courses = mysql_fetch_assoc($result)) { if (mysql_num_rows($result) == 0) { $sid=$_SESSION['sid']; $sql='INSERT INTO `courses` ("sid","sub","num","ins") VALUES ("'.$sid.'","'.$sub.'","'.$num.'","'.$ins.'")'; $insert=mysql_query($sql) or die(mysql_error()); //grab the cid now $sql='SELECT * FROM `courses` ` where `sub`="'.$sub.'" AND `num`="'.$num.'" AND `ins`="'.$ins.'" AND `sid`="'.$sid.'" LIMIT 1'; $result=mysql_query($sql) or die($_SESSION['error']=mysql_error()." Error Code: 2.3"); while ($courses2=mysql_fetch_assoc($result)) { echo $courses2['cid']."<br />"; $cid=$courses2['cid']; } } if (mysql_num_rows($result) > 0) { $cid=$courses['cid']; } $cid1= $_SESSION['courses']; // combine old and new courses $cid2= $cid1.",".$courses['cid']; // update db entry echo $cid2; $sql='UPDATE `login_users` SET cid = "'.$cid2.'" WHERE `email` = "'.email.'" LIMIT 1'; mysql_query($sql) or die(mysql_error()); //update session vars $_SESSION['courses']=$cid2; //now we should be all set so send them to their backpack mysql_free_result($result); header("Location: /backpack.php") or die("couldnt forward"); } } } [/code] Link to comment https://forums.phpfreaks.com/topic/83832-can-somebody-point-out-whats-wrong-with-this-code/#findComment-426673 Share on other sites More sharing options...
GingerRobot Posted December 31, 2007 Share Posted December 31, 2007 You made a mistake with your or die statement on the 4th line of the above code. Change it from: $result=mysql_query($sql) or die(mysql_error); To: $result=mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/83832-can-somebody-point-out-whats-wrong-with-this-code/#findComment-426689 Share on other sites More sharing options...
aosmith Posted December 31, 2007 Author Share Posted December 31, 2007 a little update to the cod and i have finally managed to get an error out of it: [code=php:0] <?php ini_set('display_errors','On'); error_reporting(E_ALL); session_start(); $email=$_SESSION['email']; $sid=$_SESSION['sid']; $valid=$_SESSION['valid']; ////////////////////////////////// // handler for adding classes // ////////////////////////////////// echo "<html><body>"; if ($_POST) { $sub=$_POST['sub']; $num=$_POST['num']; $ins=$_POST['ins']; echo $sub.$num.$ins."<br />"; // first of all load the tables require_once("db.inc.php"); //connect to mysql db or kick out an error code $connect=mysql_connect('localhost', $user, $pass) or die(mysql_error); //connect to notpanda database or error code mysql_select_db('notepand_') or die(mysql_error); //query to select password $sql = 'SELECT * from `login_users` WHERE `email`="'.$email.'" LIMIT 1'; $result=mysql_query($sql) or die(mysql_error); if (!$result) { die ("Database Failure: Hang in there we're working on it"); } while ($login_users = mysql_fetch_assoc($result)) { echo $login_users['email']."<br />"; // Grab classes $sql='SELECT * FROM `courses` where `sub`="'.$sub.'" AND `num`="'.$num.'" AND `ins`="'.$ins.'" AND `sid`="'.$sid.'"'; $result=mysql_query($sql) or die(mysql_error); if (!$result) { die ("Database Failure: Hang in there we're working on it"); } $rows=mysql_num_rows($result); echo $rows."<br />"; if ($rows=="0") { $sid=$_SESSION['sid']; $sql="INSERT INTO courses ('cid','sid','sub','num','ins') VALUES ('1',".$sid."','".$sub."','".$num."','".$ins."')"; $insert=mysql_query($sql) or die(mysql_error()); //grab the cid now $sql='SELECT * FROM `courses` WHERE `sub`="'.$sub.'" AND `num`="'.$num.'" AND `ins`="'.$ins.'" AND `sid`="'.$sid.'" LIMIT 1'; $result2=mysql_query($sql) or die($_SESSION['error']=mysql_error()." Error Code: 2.3"); echo mysql_num_rows($result2)."<br />"; if (!$result2) {die ("sorry");} while ($courses2=mysql_fetch_assoc($result2)) { echo $courses2['cid']."<br />"; $cid=$courses2['cid']; } } while ($courses = mysql_fetch_assoc($result)) { if (mysql_num_rows($result) > 0) { $cid=$courses['cid']; } $cid1= $_SESSION['courses']; // combine old and new courses $cid2= $cid1.",".$courses['cid']; // update db entry echo $cid2; $sql='UPDATE `login_users` SET cid = "'.$cid2.'" WHERE `email` = "'.email.'" LIMIT 1'; mysql_query($sql) or die(mysql_error()); //update session vars $_SESSION['courses']=$cid2; //now we should be all set so send them to their backpack mysql_free_result($result); header("Location: /backpack.php") or die("couldnt forward"); } } } [/code] and the error i get is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''cid','sid','sub','num','ins') VALUES ('1',','a','b','c')' at line 1 Link to comment https://forums.phpfreaks.com/topic/83832-can-somebody-point-out-whats-wrong-with-this-code/#findComment-426692 Share on other sites More sharing options...
GingerRobot Posted December 31, 2007 Share Posted December 31, 2007 You are missing a single quote in this line: $sql="INSERT INTO courses ('cid','sid','sub','num','ins') VALUES ('1',".$sid."','".$sub."','".$num."','".$ins."')"; Change it to: $sql="INSERT INTO courses ('cid','sid','sub','num','ins') VALUES ('1','".$sid."','".$sub."','".$num."','".$ins."')"; Edit: You should also place column names inside backticks (if you use anything) not single quotes: $sql="INSERT INTO courses (`cid`,`sid`,`sub`,`num`,`ins`) VALUES ('1','".$sid."','".$sub."','".$num."','".$ins."')"; And for goodness sake, put your code inside the tags! You should also note that $sid appears to be empty. Link to comment https://forums.phpfreaks.com/topic/83832-can-somebody-point-out-whats-wrong-with-this-code/#findComment-426694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.