Hi everyone!
Could anyone help me please?
As u can see by my username, I'm a newbie in PHP.
Now to the question:
I have made a site that extracts data (in my case movies) that logs in a user and shows all data that the user has entered as a table. I've written some titles in MySQL manually to see if it works and it did. The problem starts when I try to add a new title. It doesn't add the title I submitted and the page doesn't show neither the table nor the submit buttons. It doesn't show any errors either.
What's wrong with my code?
totalnoob 0 Light Poster
<html>
<body style="background-color:powderblue;">
<head><title> 90s nostalgia </title> </head>
<h1 style="text-align:center">"90's club "</h1> </br></br>
<?php
# error_reporting(E_ALL ^ E_NOTICE);
include("c:/wamp/www/conf.php");
# $login= $_POST['user'];
# $password= $_POST['pass'];
if (isset($_POST['user'] ,$_POST['pass']))
{
$login= $_POST['user'];
$password= $_POST['pass'];
$connection=@mysql_connect($host, $user, $pass)or die("Unable to connect!");
mysql_select_db($db, $connection) or die ('Unable to select database!');
$query="select id from user where username='$login' and password='$password'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num>0)
{
setcookie('username', $login, mktime()+300, '/');
?>
<p style="text-align:center;font-size:30px"> Welcome <?php echo $login ?>! </p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="POST" style="text-align:center" >
Give your proposal here:
</br> </br> </br>
Title:<input type="text" name="title">
<input type="submit" value="add" style=" height:35;width:70">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="POST" style="text-align:center" >
Category:<input type="text" name="category">
<input type="submit" value="add" style=" height:35;width:70">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="POST" style="text-align:center" >
Year:<input type="text" name="year">
<input type="submit" value="add" style=" height:35;width:70">
<?php
$query2= "select title, category, year from movie where user='$login'";
$result2=mysql_query($query2);
?>
</br> </br> </br> </br> </br>
<p style"text-align:center;font-size:23">Your titles:</p>
<div style="text-align:center">
<table width="800" border="1">
<th>Title</th><th>Category</th><th>Year</th>
<?php
while ($row = mysql_fetch_assoc($result2))
{
echo '<tr>'.
'<td>'.$row['title'].'</td>'.'<td>'.$row['category'].'</td>'.'<td>'.$row['year'].'</td>'.
'</tr>';
}
isset($_POST['title'])?$title = $_POST['title']:$title = "";
isset($_POST['category'])?$category= $_POST['category']:$category = "";
isset($_POST['year'])?$year = $_POST['year']:$year = "";
while ($title )
{
$query3= "insert into movie (title,user) values ('$title','$login')";
mysql_query($query3);
}
?>
</table> </div>
<?php
}
else
{
echo "Invalid username!" ;
}
}
?>
</body>
</html>
ribbles 0 Newbie Poster
You need to move the head tag to between the html and the body tag, i.e.:
<html>
<body style="background-color:powderblue;">
<head><title> 90´s nostalgia </title> </head>
<h1 style="text-align:center">"90's club "</h1> </br></br>
SHOULD BE:
<html>
<head><title> 90´s nostalgia </title> </head>
<body style="background-color:powderblue;">
<h1 style="text-align:center">"90's club "</h1> </br></br>
totalnoob 0 Light Poster
You need to move the head tag to between the html and the body tag, i.e.:
<html>
<body style="background-color:powderblue;">
<head><title> 90´s nostalgia </title> </head>
<h1 style="text-align:center">"90's club "</h1> </br></br>SHOULD BE:
<html>
<head><title> 90´s nostalgia </title> </head>
<body style="background-color:powderblue;">
<h1 style="text-align:center">"90's club "</h1> </br></br>
Thanks for your reply!
I'm sorry but I forgot to mention that the only thing appearing on screen is 90´s nostalgia and 90's club. The rest is blank.
rm_daniweb 3 Junior Poster
in your submitted code the HEADER AND TITLE is inside the BODY.
please arrange it properly.
<html>
<body style="background-color:powderblue;">
<head><title> 90´s nostalgia </title> </head>
<h1 style="text-align:center">"90's club "</h1> </br></br>
body should be after head and title....hope it helps...
BzzBee 5 Posting Whiz
correct the above mentioned error, and check your query and mysql function, some times due to that any error comes.
totalnoob 0 Light Poster
I solved the inserting problem by moving it to a separate file.
Thanks to all of you who tried to correct my problems!
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.