Hey PHP coders,
Having trouble with a small application here. I copy/pasted 4 files below. My connect.php (Is the database connection with username, password, etc), index.html (file used to get user information for upload --- its a form that (redirects to create_user.php), create_user.php (my sql statements to upload the form into the database, show_user.php (redirected from create_user.php that should be populated with user information and should show up [however it does not].
WHAT AM I DOING WRONG HERE??????
PLEASE LET ME KNOW. THANKS IN ADVANCE.
I AM USING LOCALHOST..
__________________________________________________
CONNECT.PHP:
__________________________________________________________________
<?php
$database_host = "localhost";
$username = "php1";
$password = "jack";
$database_name = "user";
//require_once 'app_config.php';
mysql_connect($database_host, $username, $password)
or die ("<p>Error connecting to database: " .
mysql_error() . "</p>");
header("Location: show_user.php?user_id=" . mysql_insert_id());
// exit();
//echo "<p>Connected to MySql!!!!!</p>";
mysql_select_db($database_name)
or die("<p>Error selecting the database user: " .
mysql_error() . "</p>");
exit();
//echo "<p>Connected to Mysql, using database USER.</p>";
/*
$result = mysql_query("SHOW DATABASES;");
if (!$result) {
die("<p>Error in listing tables: ". mysql_error() . "</p>");
}
echo "<p>Table in database:</p>";
echo "<ul>";
while ($row = mysql_fetch_row($result)) {
echo "<li>Table: {$row[0]}<li>";
}
echo "</ul>"
*/
?>
____________________________________________________________________________
CREATE_USER.PHP
__________________________________________________________________________________________________
<?php
require_once 'connect.php';
$first_name = trim($_REQUEST['first_name']);
$last_name = trim($_REQUEST['last_name']);
$email = trim($_REQUEST['email']);
$facebook_handle = trim($_REQUEST['facebook_handle']);
$twitter_handle = trim($_REQUEST['twitter_handle']);
$bio= trim($_REQUEST['bio']);
$insert_sql = "INSERT INTO user (first_name, last_name, " .
"email, facebook_handle, twitter_handle, bio) " .
"VALUES ('{$first_name}', '{$last_name}', '{$email}', " .
"'{$facebook_handle}', '{$twitter_handle}', '{$bio}');";
mysql_query($insert_sql);
// $user_id = $_REQUEST['user_id'];
header('Location: show_user.php?user_id=' . mysql_insert_id());
// $user_id = $_REQUEST['user_id'];
// exit();
// or die(mysql_error());
?>
_______________________________________________
INDEX.HTML
_______________________________________________________________________
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="header"><h1>PHP & MYSQL: uuuuuuuuuuuu</h1> </div>
<div id="content">
<form action="create_user.php" method="POST"
enctype="multipart/form-data">
<fieldset>
<label for="first_name">First Name:</label>
<input type="text" name="first_name" size="20" /><br />
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" size="20" /><br />
<label for="email">Email Address:</label>
<input type="text" name="email" size="20" /><br />
<label for="facebook_handle">Facebook Handle:</label>
<input type="text" name="facebook_handle" size="20" /><br />
<label for="twitter_handle">Twitter Handle:</label>
<input type="text" name="twitter_handle" size="20" /><br />
<label for="user_pic">Upload a Picture:</label>
<input type="file" name="user_pic" /></br>
<label for="bio">Bio:</label>
<textarea name="bio" cols="40" rows="10"></textarea>
</fieldset>
<br/>
<fieldset class="center">
<input type="submit" value="Join the Club" />
<input type="reset" value="Clear and Restart" />
</fieldset>
</form>
</div>
</body>
</html>
_____________________________________
SHOW_USER.PHP
_________________________________________________________________
//require_once 'create_user.php';
require_once 'connect.php';
$user_id = $_REQUEST['user_id'];
$select_query = "SELECT * FROM user WHERE user_id = " . $user_id;
$result = mysql_query($select_query);
if ($result) {
//get the query result rows using $ result
$row = mysql_fetch_array($result);
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$bio = $row['bio'];
// $email = $row['email'];
// $facebook_handle = $row['facebook_handle'];
// $twitter_handle = $row['twitter_handle'];
} else {
die ("Error locating user with ID {$user_id}");
}
?>
<html
<head>
// user end up here by using the create_user.html and create_user.php.
//also my loggin in and clicking "my profile".
//selecting a particular user from a list.
</head>
<body>
<div id="header"><h1>The first creatative site phil morales</h1></div>
<div id="example">User Profile</div>
<div id="contect">
<div class="user_profile">
<h1><?php echo "{$first_name} {$last_name}"; ?></h1>
<p><img src="<?php echo $user_image; ?>" class="user_pic" />
<?php echo $bio; ?></p>
<p class ="contact_info">Get in touch with $first_name:</p>
</div>
</div>
</body>
</html>