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"); } Quote Link to comment 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]; Quote Link to comment Share on other sites More sharing options...
ec Posted March 27, 2008 Author Share Posted March 27, 2008 no it still doesn't work Quote Link to comment 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> Quote Link to comment 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.