Jump to content

chemicaluser

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

chemicaluser's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. also, sometimes when I echo it out (same page but on a different server) i see -0001-11-30 0:00 1969-12-31 19:00
  2. thanks, that did it ... but i have one more qustion if ($time_added == 0) echo 'Date Added - n/a <br/>'; if ($time_added != 0) echo 'Date Added - ' . date("Y-m-d G:i ", strtotime($row['time_added'])).'<br/>'; the second part does not work, if the time not equal to 0 - any ideas? and in my reading around i did find that Western Hemisphere = 31 Dec 1969 Eastern Hemisphere = 1 Jan 1970
  3. Some of the dates (timestamp) in my database have a value of 0000-00-00 00:00:00 when I echo out the date - I see 1969-12-31 19:00 echo 'Date Added - ' . date("Y-m-d G:i ", strtotime($row['time_added'])).'<br/>'; anyone know why ...is it because 0000-00-00 is not a valid date? any way to make it display the words "n/a" instead of the 1969-12-31
  4. it does not display anything, just a blank field.
  5. I have a table in which I am storing a date/time value. It is stored as timestamp. When I try to echo the value, it does not return anything, just a blank field. this is my code (which works for the rest of my form - with non date values) anyone know why it is not working? $arrival_time = $_GET['arrival_time']; <tr> <td align="right" >Arrival Time</td> <td align="left"><input type="text" id="arrival_time_e" name="arrival_time_e" class="input" value="<?php if (!empty($arrival_time)) echo $arrival_time;?>" /></td> </tr> i hava also tried ... which returns the value of 1969-12-31 19:00 (but the dates stored in my database are the right timestamp format, 2011-04-26 22:43:11) <tr> <td align="right" >Arrival Time </td> <td align="left"><input type="text" id="arrival_time_e" name="arrival_time_e" class="input" value="<?php echo date("Y-m-d H:i ", strtotime($row['arrival_time']));?>" /> </td> </tr hope someone can help
  6. Thanks DavidAM, i was just missing the log number on my form
  7. Sorry but I did not give you the proper structure of my database.... I do have a third+fourth field in my database (log_number and date_added) ... log_number its my p.key however the only two fields that i would like up update are the first_name and last_name ...i still get the same results even when completely removing the check for GET .. actually what ends up happening then, in my form when i view the record, the data already in my database field does not show up in the input box .... its just two empty input boxes could it have something to do with not mentioning the date_added in my query? murli800 ... thanks for the files, i will try playing around with your code later (ill let you know how it goes)
  8. I would like to edit a record that I already have in my database but my query is not working for some reason. Hope someone can help. The errors i get are Notice: Undefined variable: first_name in C:\chemicaluser\www\editinfo.php on line 40 Notice: Undefined variable: last_name in C:\chemicaluser\www\editinfo.php on line 40 Notice: Undefined variable: log_number in C:\chemicaluser\www\editinfo.php on line 40 .... line 40 = my query $query = "UPDATE table1 SET first_name = '$first_name', last_name = '$last_name' WHERE log_number = '$log_number' "; Very simple database, 1 table w/ 2 fields table name = table1 fields = first_name, last_name my php file <?php require ('/menu.php'); require_once('sqlconnect.php'); if (isset($_GET['log_number']) && isset($_GET['first_name']) && isset($_GET['last_name']) ) { $log_number = $_GET['log_number']; $first_name = $_GET['first_name']; $last_name = $_GET['last_name']; } else if (isset($_POST['log_number']) && isset($_POST['first_name']) && isset($_POST['last_name']) ) { $log_number = $_POST['log_number']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; } if (isset($_POST['submit'])) { $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "UPDATE table1 SET first_name = '$first_name', last_name = '$last_name' WHERE log_number = '$log_number' "; $result = mysqli_query($dbc, $query) or die ('Error querying database'); mysqli_close($dbc); } ?> my form <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="first_name">First name</label> <input type="text" id="first_name" name="first_name" value="<?php if (!empty($first_name)) echo $first_name; ?>"/> <label for="last_name">Last Name</label> <input type="text" id="last_name" name="last_name" value="<?php if (!empty($last_name)) echo $last_name; ?>" /> <input type="submit" value="Edit Information" name="submit" /> </form>
  9. So i have figured out what the problem was with my query ... i was not searching for the log number my original query code $query = "SELECT * FROM table1, table2 WHERE table1.log_number = table2.log_number"; should have been $query = "SELECT * FROM table1, table2 WHERE table1.log_number = table2.log_number and table1.log_number like '$search'";
  10. I have a database with two tables, they are designed like this Table1 has two fields (log_number, name) Table2 has two fields (log_number, city) I would like to do a search for a specific log number and display only one result for that matching log number (that we searched for) and display something like this Log Number: 59 Name: Mark City: Chicago this is my code so far my search form <form method="get" action="search.php" /> Log Number <input type="text" id="log_number" name="log_number" /> <input type="submit" name="submit" value="Search" /> the search.php file <?php require ('/sqlconnect.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $log_number = $_GET['log_number']; $name = $_GET['name']; $city = $_GET['city']; $query = "SELECT * FROM table1, table2 WHERE table1.log_number = table2.log_number"; $result = mysqli_query ($dbc, $query); while ($row = mysqli_fetch_array($result)) { echo '<b>Log Number:</b> '.$row['log_number'].'</td>'; echo '<br/>'; echo '<b>Name:</b> '.$row['name'].'</td>'; echo '<br/>'; echo '<b>City:</b> '.$row['city'].'</td>'; } mysqli_close($dbc); ?> the problem I am having with my current code is that it does not display the results of the log number i searched for, but instead returns information for all the entries (two in my case) that have matching log numbers in both table1 and table2 when i search for log number 59, i get the following result Log Number: 59 Name: Mark City: Chicago Log Number: 77 Transport Company: Doug Customer Number: San Francisco the result that I want is when i search for log number 59 ... i want it to only display that one record Log Number: 59 Name: Mark City: Chicago hope someone can help
  11. I tried the parentheses but it is still not working.. once i add this part its the only part of the query that returns results ... dateadd >= '$start_date' AND dateadd <= '$end_date' and once i delete it ... the rest of the query works without problems ...i know that i am saving and uploading the right file because when i change the code i get different results
  12. Hope someone can help. i am trying to search between two date ranges but am not sure how to add it to the rest of my query. this is my original query which works fine .. it does not have the start and end date part $query = "SELECT * FROM table WHERE hdt1 like '%$hdt1_search%' and hdt2 like '%$hdt2_search%' and hdt3 like '%$hdt3_search%' and dateadd like '$dateadd_search'"; this is the start date to end date search, ...it works ok when it is the only thing in the query $query = "SELECT * FROM table WHERE dateadd >= '$start_date' AND dateadd <= '$end_date'"; BUT, when i try to put it all together the only two fields that get search are the start date to end date search. ... $query = "SELECT * FROM table WHERE hdt1 like '%$hdt1_search%' and hdt2 like '%$hdt2_search%' and hdt3 like '%$hdt3_search%' and dateadd like '$dateadd_search' and dateadd >= '$start_date' AND dateadd <= '$end_date' "; what am i doing wrong????
  13. Hi, I am working on a simple registration form. What I am trying to do is make sure that the same email is not used to sign up. This is what my code looks like now - it still lets me sign up with the same email. Any suggestions? <?php $page_title = 'Register'; include ('./includes/header.html'); // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('./includes/mysql_connect.php'); // Connect to the db. // function for escaping the data. function escape_data ($data) { global $dbc; // Need the connection. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string(trim($data), $dbc); } // End of function. $errors = array(); // Initialize error array. // Check for a first name. if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = escape_data($_POST['first_name']); } // Check for a last name. if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = escape_data($_POST['last_name']); } // Check for an email address. if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = escape_data($_POST['email']); } // Check for a password and match against the confirmed password. if (!empty($_POST['password1'])) { if ($_POST['password1'] != $_POST['password2']) { $errors[] = 'Your password did not match the confirmed password.'; } else { $p = escape_data($_POST['password1']); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { // If everything's okay. // Check for previous registration. $query = "SELECT user_id FROM users WHERE email='$e'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { // Make the query. $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )"; $result = @mysql_query ($query); // Run the query. if ($result) { // If it ran OK. // Print a message. echo '<h1 id="mainhead">Thank you!</h1> <p>You are now registered.</p><p><br /></p>'; // Include the footer and quit the script (to not show the form). include ('./includes/footer.html'); exit(); } else { // If it did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. include ('./includes/footer.html'); exit(); } } else { // Already registered. echo '<h1 id="mainhead">Error!</h1> <p class="error">The email address has already been registered.</p>'; } } else { // Report the errors. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. mysql_close(); // Close the database connection. } // End of the main Submit conditional. ?> <h2>Register</h2> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Confirm Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('./includes/footer.html'); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.