Jump to content


Photo

Nothing will print..


  • Please log in to reply
1 reply to this topic

#1 Inverno

Inverno
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 24 October 2006 - 07:15 AM

I'm new to php (and coding in general), as my code should make apparent. However I'm pretty sure at least the code outside of my <?php tag should be working, but it's not. Also, the php isn't doing anything either; no die messages display, no changes to the database are made. Can someone tell me where I've messed up?
<head>
<title>Movie Added</title>
</head>
<body>
<p> 
test
</p>
<?php

//define variables
$mdesc = $_POST['mdescription'];
$mname = $_POST['mname'];
$genre = $_POST['genre'];
$rating = $_POST['rating'];
$dlast = $_POST['dlastname'];
$dfirst = $_POST['dfirstname'];
$alast = $_POST['alastname'];
$afirst = $_POST['afirstname'];


//connect to server
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

//open database
mysql_select_db("dbname", $con) or die("no db found");

//the movie script

//add movie info to table
$query="INSERT INTO movie (name, genre, description) VALUES ("$mname", "$genre", "$mdesc")"
or die('Error!' . mysql_error());
mysql_query($query);

//the director script

//add director info to table
$query1="INSERT INTO director (lastname, firstname) VALUES ("$dlast", "$dfirst")" or die("Error!");

mysql_query($query1);

//the actor script

//add actor info to table
$check= if (mysql_query("SELECT actor.firstname, actor.lastname 
						FROM actor 
						WHERE actor.lastname="$alast" 
						AND  actor.firstname="$afirst"");
		else mysql_query("INSERT INTO actor (lastname, firstname) 
							VALUES ("$alast", "$afirst")");

/* possibly improved on?
 $query="INSERT INTO actor (lastname, firstname) VALUES (\"$_POST[alastname]\",\"$_POST[afirstname]\")"
*/

mysql_query($check);

//the rating script

//define movieid
$result = mysql_query("SELECT movies.movieid FROM movies WHERE movies.name = "$mname"") or die('Error!' . mysql_error());

//add rating info to table
$query2= mysql_query("INSERT INTO rating (rating, movieid) VALUES ("$rating", "$result")") or die('Error!' . mysql_error());

mysql_query($result);
mysql_query($query2);

//tie director to the movie

//find movieid
$mid = mysql_query("SELECT movies.movieid 
					FROM movies 
					WHERE movies.name = "$mname"") or die('Error!' . mysql_error());

//find dirid
$did = mysql_query("SELECT director.dirid 
					FROM director 
					WHERE director.lastname = "$dlast" 
					AND WHERE director.firstname = "$dfirst")" or die('Error!' . mysql_error());
//combine results
$add = mysql_query("INSERT INTO directormovie (directorid, movieid) VALUES ("$did", "$mid")") or die('Error!' . mysql_error());

mysql_query($mid);
mysql_query($did);
mysql_query($add);

//modify actor table


//find actor id
$aid = mysql_query("SELECT actor.actorid
					FROM actor
					WHERE actor.lastname = "$alast"
					AND WHERE actor.firstname = "$afirst"") or die('Error!' . mysql_error());
					

//tie actor and movie together
$add1 = mysql_query("INSERT INTO actormovie (actorid, movieid) VALUES ("$aid", "$mid")") or die('Error!' . mysql_error());

mysql_query($aid);
mysql_query($add1);
mysql_close($con);
?>



<p>
test 2.
</p>
</body>
</html>



#2 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 24 October 2006 - 07:23 AM

Well for one
it's supposed to be
$query="INSERT INTO movie (name, genre, description) VALUES ('$mname', '$genre', '$mdesc')";
$result = mysql_query($query)or die('Error!' . mysql_error());
not

$query ="INSERT INTO movie (name, genre, description) VALUES ("$mname", "$genre", "$mdesc")"
or die('Error!' . mysql_error());
mysql_query($query);


btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users