I have a web application that I am building where a user is able to create a new project.
I have been dealing with this for a couple days and I am totally stumped!
I have a "New Project" button and when you click it, it calls a newProject function (and passes through the id for the folder the new project will be in. But that does not matter.)
This is what that javascript function looks like.
function newProject(parentFolder) {
//this is here because the data type stored in the database is varchar and if the value is 'none' then there the project being created will bi in no folder.
if(parentFolder != 'none') { //convert to nonstring
var PF = parentFolder;
}else {
var PF = 'none';
}
//create the new project
$.post('../../php/new_project.php', { parentFolder: PF, name: 'New Project' }, function(data) {
alert(data);
});
}
The connection to the new_project.php file is fine and all the variables pass through.
Here is the new_project.php file
session_start();
if(isset($_SESSION['username'])){
$username = $_SESSION['username'];
if(isset($_SESSION['name'])){
$name = $_SESSION['name'];
}
}
if(isset($_POST['name'])) {
$parentFolder = $_POST['parentFolder'];
$name = $_POST['name'];
$date = date('Y/m/d');
$openId;
for ($i=0;$i<10;++$i)
$openId.= ($r=mt_rand(0,35))<26?chr(ord('a')+$r):chr(ord('0')+$r-26);
$conn = new PDO('mysql:host=localhost;dbname=projects', "******", "*******");
$sql = "INSERT INTO projects (id, ProjectName, creatorOfProject, public, lastEdited, openId, deleted, parentfolder, favorite) VALUES (:id, :ProjectName, :creatorOfProject, :public, :lastEdited, :openId, :deleted, :parentfolder, :favorite)";
$query = $conn -> prepare($sql);
$query -> execute(array(
":id" => '',
":ProjectName" => $name,
":creatorOfProject" => $username,
":puclic" => '',
":lastEdited" => $date,
":openId" => $openId,
":deleted" => '',
":parentfolder" => $parentFolder,
":favorite" => ''
));
}else {
echo 'something went wront';
}
Because I am alerting the data passed from this file it just pops up a blank alert box. There are no javascript error either.