ec Posted March 26, 2008 Share Posted March 26, 2008 I'm trying to save the result of this query into the table members but it wont do anything...It works when I type the qry directly into phpmyadmin but wouldn't with mysql... anyone know what's wrong with it?? $qry = "SELECT accesslevel.level FROM accesslevel, teacher WHERE accesslevel.position= teacher.position AND teacher.teacherid='teacherid'"; $result=mysql_query($qry); $result = mysql_fetch_array($result); //Create INSERT query $qry = "INSERT INTO members(firstname, lastname, level, teacherid, passwd) VALUES('$fname','$lname','$result','$teacherid','".md5($_POST['password'])."')"; $result = mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query failed"); } Link to comment https://forums.phpfreaks.com/topic/98054-inserting/ Share on other sites More sharing options...
aschk Posted March 27, 2008 Share Posted March 27, 2008 Your first $result is an array, NOT a string. So your INSERT statement fails because it can't use $result. Below $result = mysql_fetch_array($result); Put $result = $result[0]; Link to comment https://forums.phpfreaks.com/topic/98054-inserting/#findComment-502029 Share on other sites More sharing options...
ec Posted March 27, 2008 Author Share Posted March 27, 2008 no it still doesn't work Link to comment https://forums.phpfreaks.com/topic/98054-inserting/#findComment-502136 Share on other sites More sharing options...
ec Posted March 27, 2008 Author Share Posted March 27, 2008 no worries, it's working now the code is <code> //userlevel $qry = "SELECT accesslevel.level as level FROM accesslevel, teacher WHERE accesslevel.position= teacher.position AND teacher.teacherid= '$teacherid' "; $result=mysql_query($qry); $result = mysql_fetch_array($result); $level = $result[0]; //Create INSERT query $qry = "INSERT INTO members(firstname, lastname, level, teacherid, passwd) VALUES('$fname','$lname','$level','$teacherid','".md5($_POST['password'])."')"; $result = mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query failed"); } </code> Link to comment https://forums.phpfreaks.com/topic/98054-inserting/#findComment-502148 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.