feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Ok I am having a problem, I am trying to do an insert into two different tables. No matter what I've tried it doesn't work.
Hopefully i've formatted this right, so I dont get in trouble with the format police.
but what happens i add a user for a form.
there are check boxes that i have assigned. i can insert the user's info name, etc. but when it gets to the second insert, it will go through the loop and echo out everything to the screen, but it will not insert. what am i doing wrong. the loop does work, i get the out put, with the correct values.
Code: Select all
< ? php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="password"; // Mysql password
$db_name="user"; // Database name
$tbl_name="user"; // Table name
$tbl_name1="access";
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$lname=$_POST['lname'];
$fname=$_POST['fname'];
$uname=$_POST['uname'];
$pword=$_POST['pword'];
$email=$_POST['email'];
$level=$_POST['level'];
$jobtitle=$_POST['jtitle'];
$time=$_POST['time'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(username, password, level, email,fname,lname,jobTitle,time)VALUES('$uname', '$pword', '$level','$email','$fname','$lname','$jobtitle','$time')";
$result=mysql_query($sql);
? >
second insert
i requery the DB to get the matching criteria. that works the insert doesnt. it will out put the correct id, and the correct values for my array, it just will not insert help.
Code: Select all
< ? php
echo "time $time <br>";
$username="root";
$password="password";
$database="user";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM user where time='$time'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
$a=0;
while ($a < $num) {
$uid=mysql_result($result,$i,"id");
print " User that was just inserted $uid <br>";
++$a;
}
if(isset($_POST["test"])) {$test = $_POST["test"];} else {$test=array();}
for ($i="0"; $i<count($test); $i++)
{
if(!is_numeric($test[$i])) {$test[$i]="";}
if(empty($test[$i])) {unset($test[$i]);}
$query="INSERT INTO access (userid, page_id)VALUES('$uid','$test[$i]')";
echo "<br>first insert $uid $test[$i] <br>";
}
? >
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]