Jump to content

Needing help with script.


dkick111

Recommended Posts

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!

 

Link to comment
Share on other sites

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 ??

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.