dkick111 Posted September 7, 2011 Share Posted September 7, 2011 So ive created a script sometime back for entering movies into my database, i simply fill in the movie title, URL for it and then from a drop down menu i select what category from the catagories table that it fits in. eventually after time some of the movies need to be placed in a different category. currently the only way to do this is actually go into myphpadmin and edit within the tables. obviously way too time consuming. so im seeking to create a script that would allow me to select any given movie from my movies table (via dropdown maybe) and then change what category its assigned too, maybe also in a dropdown. heres the table structure. Movies Table ID - Title - Category - URL ---------------------------------------------------- 1 - Movie 1 - 18 www..com Categories Table ID - Category Name -------------------------------- 18 - Category 1 Note that the FK in movies table is Category. in my previous script from entering the movies i have it made so that when selecting the category it shows the category name instead of the ID. i hope that the same could be possible for this new script. If its not too much trouble i hope that someone could help me out on this. im totally clueless where too start. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/246612-needing-help-with-script/ Share on other sites More sharing options...
trq Posted September 7, 2011 Share Posted September 7, 2011 If your looking for a programmer, we have a freelance board. Otherwise, have you any code? We can walk you through some of the process, but were not exactly here to write code for people. Quote Link to comment https://forums.phpfreaks.com/topic/246612-needing-help-with-script/#findComment-1266364 Share on other sites More sharing options...
dkick111 Posted September 7, 2011 Author Share Posted September 7, 2011 I appoligize, i didnt mean to come off as a freeloader. So my first confusion is does it have to be like the script I used to enter the information in to the DB where I have 2 different files. Form.php and add.php, im sure any of you know what im referring to. Assuming that is the case, what I tried was using those except modifying form by taking out some fields and adding a dropdown and then in the add changing it from a INSERT into UPDATE, hence why it will look unfinished. Now, obviously as you will see nothing happens when i click the submit button. Actually it looks as if it works fine, no errors but as I said it changes nothing. So here is what i am using. Form <html> <form id="form1" name="Update" method="post" action="addtest.php"> <select name='dropdown' id='dropdown'> <?php $con = mysql_connect("localhost", "username", "password"); if (!$con) { die('Could not connect to DB: ' . mysql_error() ); } mysql_select_db ("dbname", $con); $query = "SELECT ID, Title from movies"; $result = mysql_query($query) OR DIE ("There was an error" .mysql_error()); while($row=mysql_fetch_array($result)) { echo " <option value=\"{$row['ID']}\">{$row['Title']}</option>"; } php?> </select> </select> <select name='dropdown' id='dropdown'> <?php $con = mysql_connect("localhost", "username", "password"); if (!$con) { die('Could not connect to DB: ' . mysql_error() ); } mysql_select_db ("dbname", $con); $query = "SELECT ID, Category from categories"; $result = mysql_query($query) OR DIE ("There was an error" .mysql_error()); while($row=mysql_fetch_array($result)) { echo " <option value=\"{$row['ID']}\">{$row['Category']}</option>"; } php?> </select> <input name="Submit" type="Submit" value="send" /> </form> </html> and the Add <?php $con = mysql_connect("localhost", "username", "password"); if (!$con) { die('Could not connect to DB: ' . mysql_error() ); } mysql_select_db ("dbname", $con); $sql="UPDATE movies SET Category VALUES ('$_POST[dropdown]')"; if (!mysql_query($sql,$con)) { die ('Error: ' . mysql_error()); } echo "<a href=\"form.php\">Record Updated. Click here for another</a>"; I know its not pretty. but i am hoping i am atlest kind of close ?? Quote Link to comment https://forums.phpfreaks.com/topic/246612-needing-help-with-script/#findComment-1266588 Share on other sites More sharing options...
murdocsvan Posted September 7, 2011 Share Posted September 7, 2011 In the second script, in the sql statment var, try changing '$_POST[dropdown]' to '$_POST["dropdown"]' Quote Link to comment https://forums.phpfreaks.com/topic/246612-needing-help-with-script/#findComment-1266599 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.