pmorales Posted August 4, 2013 Share Posted August 4, 2013 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> Quote Link to comment Share on other sites More sharing options...
adoado Posted August 5, 2013 Share Posted August 5, 2013 A bit more information would help.. have you got errors on, or a tail log open? Quote Link to comment Share on other sites More sharing options...
pmorales Posted August 5, 2013 Author Share Posted August 5, 2013 http://localhost/PhpP/show_user.php?user_id=0 I GET THIS ERROR ABOVE... IT NEVER INCREMENTS OR GETS THE "USER_ID" FROM DATABASE NOR DOES IT POPULATE THAT SHOW_USER.PHP ON SCREEN Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted August 5, 2013 Share Posted August 5, 2013 You are setting the id's but if a page is reloaded and the user does not have a cookie or a session it will not remember which user is logged in Quote Link to comment Share on other sites More sharing options...
pmorales Posted August 6, 2013 Author Share Posted August 6, 2013 Thanks chrisloyd, I got to start inputting the session. I will give a shot see what happens. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.