nielsonp Posted June 4, 2008 Share Posted June 4, 2008 hi. ive copied some data from another php page which enters cd information into a cd database. i have modified the copied page so that it will post to a movie database. with the movie database when i post in, its posting the title in the ID section which is supposed to be automatcially entered, however i cannot see differences within the code. here is the code from the movie database page: <?php if ($_POST['submit']){ //set $_POST variables here $reqTitle = $_POST[ReqTitle]; $reqRating = $_POST[ReqRating]; $reqRuntime = $_POST[ReqRuntime]; $reqYear = $_POST[ReqYear]; $reqRegion = $_POST[ReqRegion]; $reqPlatform = $_POST[ReqPlatform]; $reqPrice = $_POST[ReqPrice]; //connect to mysql $con = mysql_connect("localhost","root"); //if the connection doesn't work then die with message if (!$con) { die('Could Not Connect:' . mysql_error()); } //select the database or die with message mysql_select_db('cdcat',$con) or die('Could not find database' . mysql_error()); //set the variable $num to equal the number or rows returned $num = mysql_num_rows; if($reqTitle == NULL || $reqRating == NULL || $reqRuntime == NULL || $reqYear == NULL || $reqRegion == NULL || $reqPlatform == NULL || $reqPrice ==NULL) { echo 'you need to fill in all fields'; } elseif($num == 1) { echo 'sorry that is already in the database'; } elseif($num == 0) { $query2 = "INSERT INTO videocat (Title, Rating, Runtime, Year, Region, Platform, Price) VALUES ('$reqTitle', '$reqRating', '$reqRuntime', '$reqYear', '$reqRegion', '$reqPlatform', '$reqPrice')"; $result2 = mysql_query($query2) or die ("Error in query" . mysql_error()); } if($result2) { header("Location: dbenterfinish.php"); } } ?> <!DOCTYPE html PUBLIC "-//W3c//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhrml-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="Nielson Plug" /> <title>Untitled 1</title> </head> <body> <h1>Please enter details:</h1> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <p>ID automatically added</p> <p>Title: <input type="text" name="ReqTitle" size="30" maxlength="80" /></p> <p>Rating: <input type="text" name="ReqRating" size="30" maxlength="30" /></p> <p>Runtime: <input type="text" name="ReqRuntime" size="30" maxlength="30" /></p> <p>Year: <input type="text" name="ReqYear" size="30" maxlength="30" /></p> <p>Region: <input tpe="text" name="ReqRegion" size="30" maxlength="30" /></p> <p>Platform: <input type="text" name="ReqPlatform" size="30" maxlength="30" /></p> <p>Price: <input type="text" name="ReqPrice" size="30" maxlength="30" /></p> <p><input type="submit" name="submit" value="submit" /></p> </form> </body> </html> here is the data from the cd database page which automatically enters the id in. <?php if ($_POST['submit']){ //set $_POST variables here $reqTitle = $_POST[ReqTitle]; $reqArtist = $_POST[ReqArtist]; $reqGenre = $_POST[ReqGenre]; $reqPrice = $_POST[ReqPrice]; //connect to mysql $con = mysql_connect("localhost","root"); //if the connection doesn't work then die with message if (!$con) { die('Could Not Connect:' . mysql_error()); } //select the database or die with message mysql_select_db(cdcat,$con) or die('Could not find database' . mysql_error()); //set the variable $num to equal the number or rows returned $num = mysql_num_rows; if($reqTitle == NULL || $reqArtist == NULL || $reqGenre == NULL || $reqPrice == NULL) { echo 'you need to fill in all fields'; } elseif($num == 1) { echo 'sorry that is already in the database'; } elseif($num == 0) { $query2 = "INSERT INTO cdcat (Title, Artist, Genre, Price) VALUES ('$reqTitle', '$reqArtist', '$reqGenre', '$reqPrice')"; $result2 = mysql_query($query2) or die ("Error in query" . mysql_error()); } if($result2) { header("Location: dbenterfinish.php"); } } ?> <!DOCTYPE html PUBLIC "-//W3c//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhrml-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="Nielson Plug" /> <title>Untitled 1</title> </head> <body> <h1>Please Register</h1> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <p>ID automatically added</p> <p>CD Title: <input type="text" name="ReqTitle" size="30" maxlength="80" /></p> <p>Artist: <input type="text" name="ReqArtist" size="30" maxlength="30" /></p> <p>Genre: <input type="text" name="ReqGenre" size="30" maxlength="30" /></p> <p>Price: <input type="text" name="ReqPrice" size="30" maxlength="30" /></p> <p><input type="submit" name="submit" value="submit" /></p> </form> </body> </html> thanks a lot people!!! Link to comment https://forums.phpfreaks.com/topic/108648-why-is-my-php-entering-data-in-funny/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.