Jump to content

Adding data...


2old2learn?

Recommended Posts

This is what I recommend also, I prefer to store date information as a Unix timestamp (which also stores time information), and then if the display requirements ever change you should be able to use the data you have to display it how you want. Today you might only display a date, but later you could also display the time if you want to. So I prefer to use an int column for my dates, and I use PHP's various date functions to get the timestamp I want to store in that field. The timestamp is just an integer, the number of seconds since 1/1/70.The time function gets the current timestamp:http://www.php.net/manual/en/function.time.phpThe mktime function gets the timestamp for a specific date/time:http://www.php.net/manual/en/function.mktime.phpAnd the date function lets you format that date/time information however you want to display it:http://www.php.net/manual/en/function.date.phpNote that if you're storing the entire date/time, you can also let the user choose a preference about how those get displayed. They might want UK format, for example, or they might be looking for something a bit more modern. The key is to just store the integer timestamps in the database, and use the date function to format it for display. When working with integers it's also easy to add or subtract days or time, get database records between specific dates, etc, everything is just regular integer math.
$now = time();$sql = 'INSERT INTO invoices(..., invoice_date) VALUES (..., ' . $now . ')';

Okay will absorb this at a later time..been at this all day..hey "justsomeguy" I keep getting an error when information is entered..Like " Error Please check data entry...I've entered all fields..even though it give me an error message the data is stored into the database..isn't that strange giving an error message yet storing the data...????This is the error message: " Error: Please check Your data entry "This is the insert code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>insert_data.php</title></head><body><?php $con = mysql_connect("localhost","xxxxxxx","xxxxxxxxxxx"); if (!$con)   {   die('Could not connect: ' . mysql_error());   } mysql_select_db("xxxxxxxxxxx", $con); $sql="INSERT INTO twal ( srnumber, tenant, floor, tower, job_description, employee, labour_cost, material_cost, date_twa_sent_to_tenant, date_twa_approved, date_parts_ordered, supplier, date_job_completed, date_billing_given_to_accounting, employee_comments, managers_comments) VALUES ('$_POST[srnumber]','$_POST[tenant]','$_POST[floor]','$_POST[tower]','$_POST[job_description]','$_POST[employee]','$_POST[labour_cost]','$_POST[material_cost]','$_POST[date_twa_sent_to_tenant]','$_POST[date_twa_approved]','$_POST[date_parts_ordered]','$_POST[supplier]','$_POST[date_job_completed]','$_POST[date_billing_given_to_accounting]','$_POST[employee_comments]','$_POST[managers_comments]')";if (!mysql_query($sql,$con))   {   die('Error: Please check Your data entry ' . mysql_error());   } echo "1 record added"; mysql_close($con); ?> </body></html>

thanks...

Link to comment
Share on other sites

  • Replies 251
  • Created
  • Last Reply

Instead of this:

if (!mysql_query($sql,$con))   {   die('Error: Please check Your data entry ' . mysql_error());   }

Try this:

$result = mysql_query($sql,$con);echo 'result = ';var_dump($result);if ($result === false)   {   die('Error: Please check Your data entry ' . mysql_error());   }

Link to comment
Share on other sites

Instead of this:
if (!mysql_query($sql,$con))   {   die('Error: Please check Your data entry ' . mysql_error());   }

Try this:

$result = mysql_query($sql,$con);echo 'result = ';var_dump($result);if ($result === false)   {   die('Error: Please check Your data entry ' . mysql_error());   }

Okay works..message displayed " result = bool(true) 1 record added "but the form does not re-appear..I would like to form to re-appear as the message is displayed...thanks..
Link to comment
Share on other sites

Right, after the "1 record added" message there isn't any code telling it to display the form again, it just ends the HTML page. So instead of writing "1 record added", you could output the HTML for the form.

Link to comment
Share on other sites

Right, after the "1 record added" message there isn't any code telling it to display the form again, it just ends the HTML page. So instead of writing "1 record added", you could output the HTML for the form.
Output the form???Can you give an example..I am doing several things right now...sorry I know I have should figure this out on my own...as I am fixing a banner..I will pull out my HTML book to see what it has to offer..thanks...
Link to comment
Share on other sites

Yeah, output the form. Right now you're outputting the text "1 record added". You could output "<form action=..." instead.
Would it be like this:
<form action="index_sr.php" method="post">

Index_sr.php is the form page!Is this right...and where do I put it in front of the 1 record added...

Link to comment
Share on other sites

Would it be like this:
<form action="index_sr.php" method="post">

Index_sr.php is the form page!Is this right...and where do I put it in front of the 1 record added...

I put this above the 1 record added..and commented it out..
<meta http-equiv="Refresh" content="5;url=http:www.xxxxxxxxxxxxxx.com/xxxxxxx/index_sr.php" /><h1>Sorry! We have moved!</h1> <h2>The new URL is: <a href="http://www.xxxxxxxxxxxxxx.com/xxxxx/index_sr.php">http://Inventory Control System</a></h2> <p>You will be redirected to the new address in five seconds.</p> <p>If you see this message for more than 5 seconds, please click on the link above!</p>

is this okay to do ..???

Link to comment
Share on other sites

If you want to show the form on the same page you need to echo it out the whole form. If you want to redirect instantly then you can use header("location:somepage.php"); if there is some output before redirection as i can see in your code you need to use output buffering otherwise it wont redirect and will throw a error. meta tag dont work in body tag.meta tag place is inside head tag

Link to comment
Share on other sites

If you want to show the form on the same page you need to echo it out the whole form. If you want to redirect instantly then you can use header("location:somepage.php"); if there is some output before redirection as i can see in your code you need to use output buffering otherwise it wont redirect and will throw a error. meta tag dont work in body tag.meta tag place is inside head tag
Yes, I realised the Meta tag is a no go..I think on the last script I did a If statement for the re-direct I will have to look for the file and check it ...thanks...
Link to comment
Share on other sites

Hey sorry for hashing this over an over...I remember I had the form return after form was submitted..and after making many changes I think I may have removed this script excution..but I think this maybe it ...Will this have the form return after submit button click..showing the form file again...???

<?phpforeach ($_POST as $value){ if( $value == "" ) {  echo "You have not filled in all the fields<br>\n";  display the form;  exit(); }}echo "Welcome"; ?>

thanks..for your patience..

Link to comment
Share on other sites

Hey sorry for hashing this over an over...I remember I had the form return after form was submitted..and after making many changes I think I may have removed this script excution..but I think this maybe it ...Will this have the form return after submit button click..showing the form file again...???
<?phpforeach ($_POST as $value){ if( $value == "" ) {  echo "You have not filled in all the fields<br>\n";  display the form;  exit(); }}echo "Welcome"; ?>

thanks..for your patience..

LOL never mind...my brain just woke up and solved this myself..I just remember something...LOLhere is what I did to solve it...
if (isset($_POST['srnumber'])) {  	include('index_sr.php'); } echo "1 record added"; mysql_close($con);}else{echo ' Sorry, there was a problem with the form.  Please check all data entries, try again';}; ?> </body></html>

this was added at the end of script..and works...fine..

Link to comment
Share on other sites

Now to continue this story...How to block user's to links/viewing pages unless they are signed in..In other words if someone clicks a link it tells them " Sorry, must Log In First to View! "Edited 9:25amwould this sort of help found this on a google search... " Drupal.org "

<?php  if (Login) //<---I've added the word Login for this example? {    return TRUE;  // block will be shown  }  return FALSE;   echo " Please Login In to View ";?>

is this closeEdited 9:34amWell I tested the above code out by adding it to my index page and it works..a blank page only appears..but not my message???Edited 10:19am Well wanting to learn as much as possible..I again found this code which works..

<?phpglobal $user;if ($user->uid) {    return "This block is only visible for logged-in users."; <<<< but this doesn't display I will tinker with this..something is missing..I believe} else {   echo 'Please Login In!';  <<< I added this line and it displays...Yaaa..getting close I believe... return;}?>

Link to comment
Share on other sites

Can this be done..in this section of the code I have my form return after submit button is click and along with the form showing up the message " 1 Record Added "...but what I would like to happen is along with the form returning after submit ..I would like a separate window to pop up to show " " 1 Record Added "

if (isset($_POST['srnumber'])) {  	include('index_sr.php'); } echo "1 record added";<<< Would like this to be a popup window mysql_close($con);}else{echo ' Sorry, there was a problem with the form.  Please check all data entries, try again';}; ?> </body></html>

Link to comment
Share on other sites

You'll have to use JavaScript to make a separate popup. Either with window.open or by using a custom popup (ie, a styled div tag that gets display/visibility toggled)If you don't want JavaScripti, you might be able to just generate a separate portion of the page, say a formatted div, that only appears after a successful submission.

Link to comment
Share on other sites

You'll have to use JavaScript to make a separate popup. Either with window.open or by using a custom popup (ie, a styled div tag that gets display/visibility toggled)If you don't want JavaScripti, you might be able to just generate a separate portion of the page, say a formatted div, that only appears after a successful submission.
You mean something like this...
<script language="javascript" type="text/javascript"><!--function popitup(url) {	newwindow=window.open(url,'name','height=200,width=150');	if (window.focus) {newwindow.focus()}	return false;}// --></script>

then add this...

<a href="popupex.html" onclick="return popitup('popupex.html')"	>Link to popup</a>

Am I correct!And the last script I add here..

if (isset($_POST['srnumber'])) {  	include('index_sr.php'); }    <a href="popupex.html" onclick="return popitup('popupex.html')"	>Link to popup</a> echo "1 record added";<<< Would like this to be a popup window mysql_close($con);}else{echo ' Sorry, there was a problem with the form.  Please check all data entries, try again';}; ?> </body></html>

Correct?

Link to comment
Share on other sites

why make it a link and a pop-up? Why not just use a <span> to act as the anchor, and then just give it the onclick handler. I think making it a link to the page might conflict with the fact that you're trying to make it a pop-up.

Link to comment
Share on other sites

why make it a link and a pop-up? Why not just use a <span> to act as the anchor, and then just give it the onclick handler. I think making it a link to the page might conflict with the fact that you're trying to make it a pop-up.
okay link please to refer to <span> infomation
Link to comment
Share on other sites

LOL okay..I did this already..if I am right all this does is just make it bigger...but with the size of my form ..user still has to scroll the page down abit to see the message..hence the popup window..effect..no scrolling needed just close the new popup window and continue..
Link to comment
Share on other sites

Ok, I guess from the example you posted it seemed like you were going with onclick event. So just a straight up auto pop up then?

if (isset($_POST['srnumber'])){  	include('index_sr.php');}  echo '<script type="text/javascript"> popitup("popupex.html"); </script>';//echo "1 record added";<<< Would like this to be a popup windowmysql_close($con);}else{echo ' Sorry, there was a problem with the form.  Please check all data entries, try again';};?>

Link to comment
Share on other sites

Actually would an alert work? It would be simpler:Replace this line:echo "1 record added";with this:echo "<script type='text/javascript'>alert('1 Record added');</script>";
cool thanks ..you guys are great...the reason is as being an old ###### tomorrow (61) years old..I sort of have AD..and get frustrated quickly..and you guys push me to the limit where I continue to plug away at this..there have been many a projects started and never completed..I thank you all for this...
Link to comment
Share on other sites

Actually would an alert work? It would be simpler:Replace this line:echo "1 record added";with this:echo "<script type='text/javascript'>alert('1 Record added');</script>";
Wow the alert box was exactly what I was looking for..tested and worked..had to make another change the form didn't re-appear after clicking ok on the alert box..but added the script further down and now it appears...
 if (!mysql_query($sql,$con)){      die('Error: ' . mysql_error());   }  echo "<script type='text/javascript'>alert('1 Record added');</script>";  mysql_close($con);}else{echo "<script type='text/javascript'>alert('Sorry, there was a problem with the form.  Please check all data entries, try again');</script>"; if (isset($_POST['srnumber'])) {  	include('index_sr.php'); }}; ?>

You guys are the best...

Link to comment
Share on other sites

Now my next step is to make a login I followed a tutorial and created a login script as follows and get this error: " Fatal error: Call to undefined function nt_rand() in C:\xampp\htdocs\testsite\login.php on line 4 "Here is the code example:

<?session_start();$token = $_SESSION["token"] = md5(uniqid(nt_rand(),true));  <--Error called here??><form method="POST" action "<?=$_SERVER('PHP_SELF');?>">;<table><tr><td>Username:</td></tr><input type "text" name="username"/></td></tr><tr><td>Password:</td></tr><input type "password" name="password"/></td></tr></table><input type="hidden" name="token" value="<?=$token;?>" /><input type="submit" name="login" value="Log In" /></form>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...