I am trying to write a registration script, i need to make 2 separate sql inserts, the userID is the joining value that is a auto-increment number so iam trying to grab the number after the first insert and use it for the second.
Here is the code.
<?php
if(isset($_POST['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$logo = $_FILES['imagefile']['name'];
$conn = mysql_connect("localhost", "","");
mysql_select_db('Websites',$conn);
// here is the first insert the open '' is where the auto increment userID is.
$sql ="insert into users values('','$username','$password','$email','$logo',1);";
$result = mysql_query($sql,$conn)or die(mysql_error());
if (!$result)
return "<p class='text'>Could not register you in database - please try again later.</p>";
// here iam trying to select the userID that has just been inserted to insert into another table.
$sql2 = "SELECT UserID from users where UserName='$username'";
$result2 = mysql_query($sql, $conn);
$row = mysql_fetch_assoc($result2);
$userID = $row['UserID'];
$sql3 = "insert into pages values(1,$userID,'Website Under Construction','Home');";
$result = mysql_query($sql3, $conn);
if (!mkdir($username)) exit();
$fp=fopen($username."/Index.php","w");
$text='<?php ';
$text=$text.'$UserId=';
$text=$text.$username;
$text=$text.';';
$text=$text.' include("../Index.php");';
$text=$text.' ?>';
$numbytes=fwrite($fp,$text);
fclose($fp);
if($_FILES['imagefile']['type'] == "image/gif") {
copy ($_FILES['imagefile']['tmp_name'], "$username/".$_FILES['imagefile']['name'])
or die ("Could not copy");
}
else {
echo "<br><br>";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
}
echo'<center>';
echo "<img src='".$username."/".$_FILES['imagefile']['name']."'><br />";
echo 'Your account has successfully been created<br />';
echo '<b>username:</b>'.$username.'<br>';
echo '<b>Password:</b>'.$password.'<br>';
?>
<b>URL: </b><a href="http://www.theglobalarts.com/<?php echo $username; ?>">www.theglobalarts.com/<?php echo $username; ?></a><br>
<b>Admin: </b><a href="admin/index.php">Login to build your webiste</a>
</center>
<?php
}
else
{
?>
<html><body><div align="center"><h1>Register</h1><br>
<form action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data" method="post">
<table>
<tr><td align="right"> Username: </td<td> <input type="text" name="username"></td></tr>
<tr><td align="right"> Password: </td<td> <input type="password" name="password"></td></tr>
<tr><td align="right"> Email Address: </td<td> <input type="text" name="email"></td></tr>
<tr><td align="right"> Logo: </td<td> <input type="hidden" name="MAX_FILE_SIZE" value="25000"><input type="file" name="imagefile"></td></tr>
<tr><td colspan="2" align="center"> <input type="submit" name="submit"> </td></tr>
</table>
</form>
</div></body></html>
<?php
}
?>