insejn Posted April 12, 2008 Share Posted April 12, 2008 I cant see what Im doing wrong here, I thought it would work but something simple must be wrong.. I'm trying to create a simple script that creates a new folder that has the same name as the latest id from my database table. I thought this code should do it but it doesn't, I guess the problem is when the folder is supposed to be created with the code: if (file_exists("images/$row['article_id']")) This is the existing code now, is there a right way to do this? <? $host="localhost"; // Host name $username="..."; // Mysql username $password="..."; // Mysql password $db_name="..."; // Database name $tbl_name="articles_table"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Query to get the latest ID (article_id) $result = mysql_query("SELECT * FROM articles_table ORDER BY article_id DESC LIMIT 1") or die(mysql_error()); //Make a while loop and display the right id number.. while($row = mysql_fetch_array( $result )) { echo "Latest id is: ".$row['article_id']."<br>"; } // Create a new folder with the latest id number... if (file_exists("images/$row['article_id']")) { print("Folder already exists!!\n"); } else { mkdir("images/$row['article_id']"); //If Success then print out this.. echo ("The new folder has been created for you!\n"); } ?> ..thanks in advance! Link to comment https://forums.phpfreaks.com/topic/100775-problem-creating-folder-with-id-number/ Share on other sites More sharing options...
marklarah Posted April 12, 2008 Share Posted April 12, 2008 after mkdir, do something like " or die ("Could not make directory"); " Lets see if its that bit and go from there Link to comment https://forums.phpfreaks.com/topic/100775-problem-creating-folder-with-id-number/#findComment-515427 Share on other sites More sharing options...
insejn Posted April 12, 2008 Author Share Posted April 12, 2008 ..sorry its not that either. Is there a way to make a new variable containing the $row['article_id'] ? Like for example: $new_folder_name = $row['article_id']; ..but I dont seem to get that to work either. Or am I writing the code wrong? should I for example write: $new_folder_name = "$row['article_id']"; or $new_folder_name = ("$row['article_id']"); ..I think as I said the problem is when I try to write the code if (file_exists("images/$row['article_id']")) { I think that way of integrating $row['article_id'] is wrong somehow.. Link to comment https://forums.phpfreaks.com/topic/100775-problem-creating-folder-with-id-number/#findComment-515440 Share on other sites More sharing options...
marklarah Posted April 12, 2008 Share Posted April 12, 2008 "$tbl_name="articles_table"; // Table name" Where else do you use that variable? And are you sure it isn't like "yourhostname_articles" ? Link to comment https://forums.phpfreaks.com/topic/100775-problem-creating-folder-with-id-number/#findComment-515688 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.