Jump to content

josuenerd

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by josuenerd

  1. I tried to add the pagination for several hours (about 5) but I was not able to do it If anyone can please help me add pagination I would greatly appreciate it. Below is the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Weight Log</title> <style type="text/css"> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } body { background-color: #EEEEEE; } </style> </head> <body> <?php $con = mysql_connect("localhost","trend_learnu","asdfasdf"); if (!$con) { die('Could not connect: ' . mysql_error()); } // START OF VALIDATION $errors = array(); // set the errors array to empty, by default $fields = array(); // stores the field values $success_message = "This is a success"; if (isset($_POST['submit'])) { // import the validation library require("validation.php"); $rules = array(); // stores the validation rules // standard form fields $rules[] = "required,Weight,Please enter your weight."; $errors = validateFields($_POST, $rules); // if there were errors, re-populate the form fields if (!empty($errors)) { $fields = $_POST; } // no errors! redirect the user to the thankyou page (or whatever) else { $message = "All fields have been validated successfully!"; // START OF VALIDATION mysql_select_db("trend_learningdb", $con); $sql="INSERT INTO Peoples (Firstname, Lastname, Weight, Date) VALUES ('$_POST[Firstname]','$_POST[Lastname]','$_POST[Weight]','$_POST[Date]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; // END OF VALIDATION // To redirect to a "thankyou" page, you'd just do this: // header("Location: thanks.php"); } } // END OF VALIDATION $db = mysql_connect("localhost","trend_learnu","asdfasdf"); mysql_select_db("trend_learningdb",$db); $result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC"); $table = '<table width="608" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td style="color:#fff;" width="207" bgcolor="#425d74"><strong>Firstname</strong></td> <td style="color:#fff;" width="204" bgcolor="#425d74"><strong>Lastname</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Date</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Weight</strong></td> </tr>'; while($row=mysql_fetch_array($result)) { $firstname = $row['Firstname']; $lastname = $row['Lastname']; $weight = $row['Weight']; $date = $row['Date']; $table.= '<tr>'; $table.= '<td bgcolor="#e8f4ff">'.$firstname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$lastname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$date.'</td>'; $table.= '<td bgcolor="#e0ffe6"><strong>'.$weight.'</strong></td>'; $table.= '</tr>'; } $table .= '</table>'; echo $table; mysql_close($con) ?> <?php $today = date("F j, Y"); ?> <?php $goalweight = 140; $losepounds = $weight - $goalweight; //we multiply varaible a and b and store the value in c echo $tablegoal; echo '<table width="500" border="0" align="center" cellpadding="15" cellspacing="0"> <tr> <td align="center">You need to lose <strong>'; echo $losepounds; echo '</strong> pounds to reach your Goal Weight of <strong>'; echo $goalweight; echo '</strong>.</td> </tr> </table>'; ?> <style type="text/css"> <!-- body,p,table,td,input,select { font-family: verdana, tahoma; font-size: 8pt; line-height: 14pt; } .demoTable { background-color: #efefef; width: 100%; } .title { font-family: arial; font-size: 16pt; } .section { font-size: 11pt; color: #3366cc; } .error { border: 1px solid red; background-color: #ffffee; color: #660000; width: 400px; padding: 5px; } .notify { border: 1px solid #336699; background-color: #ffffee; color: #336699; width: 400px; padding: 5px; } --> </style> <table cellspacing="0" width="600" align="center"> <tr> <td> <form action="" method="post"> <input name="Date" type="hidden" value="<?php PRINT "$today"; ?>" /> <?php // if $errors is not empty, the form must have failed one or more validation // tests. Loop through each and display them on the page for the user if (!empty($errors)) { echo "<div class='error' style='width:100%;'>Please fix the following errors:\n<ul>"; foreach ($errors as $error) echo "<li>$error</li>\n"; echo "</ul></div>"; } if (!empty($message)) { echo "<div class='notify' style='width:100%;'>$success_message</div>"; } ?> <table class="demoTable"> <tr> <td>Required field:</td> <td><input type="text" name="Weight" value="<?=$fields['Weight']?>" /></td> </tr> </table> <p><input type="submit" name="submit" value="SUBMIT" /></p> </form> <br /> </td> </tr> </table> </body> </html>
  2. Below is the part of my code that creates the html table. How do I add pagination every 30 entries? $db = mysql_connect("localhost","trend_learnu","asdfasdf"); mysql_select_db("trend_learningdb",$db); $result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC"); $table = '<table width="608" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td style="color:#fff;" width="207" bgcolor="#425d74"><strong>Firstname</strong></td> <td style="color:#fff;" width="204" bgcolor="#425d74"><strong>Lastname</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Date</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Weight</strong></td> </tr>'; while($row=mysql_fetch_array($result)) { $firstname = $row['Firstname']; $lastname = $row['Lastname']; $weight = $row['Weight']; $date = $row['Date']; $table.= '<tr>'; $table.= '<td bgcolor="#e8f4ff">'.$firstname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$lastname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$date.'</td>'; $table.= '<td bgcolor="#e0ffe6"><strong>'.$weight.'</strong></td>'; $table.= '</tr>'; } $table .= '</table>'; echo $table; mysql_close($con)
  3. I figured it out on a different thread Thanks to everyone here also for helping me get to where I am on my script.
  4. This looks great but I don't have any idea how to implement this into my script. Looks like alot of code on the demo.php Can you help me implement this validation script to my form?
  5. I don't know where to add that code Below is the script: insert.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Weight Log</title><style type="text/css">body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 12px;}body { background-color: #EEEEEE;}</style></head><body><?php$con = mysql_connect("localhost","learnu","asdfasdf");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("learning", $con);$sql="INSERT INTO Peoples (Firstname, Lastname, Weight, Date)VALUES('$_POST[Firstname]','$_POST[Lastname]','$_POST[Weight]','$_POST[Date]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";$db = mysql_connect("localhost","learnu","asdfasdf");mysql_select_db("learning",$db);$result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC");$table = '<table width="608" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td style="color:#fff;" width="207" bgcolor="#425d74"><strong>Firstname</strong></td> <td style="color:#fff;" width="204" bgcolor="#425d74"><strong>Lastname</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Date</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Weight</strong></td> </tr>';while($row=mysql_fetch_array($result)){ $firstname = $row['Firstname']; $lastname = $row['Lastname']; $weight = $row['Weight']; $date = $row['Date']; $table.= '<tr>'; $table.= '<td bgcolor="#e8f4ff">'.$firstname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$lastname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$date.'</td>'; $table.= '<td bgcolor="#e0ffe6"><strong>'.$weight.'</strong></td>'; $table.= '</tr>';}$table .= '</table>';echo $table;mysql_close($con)?> <?php$today = date("F j, Y");?> <?php$goalweight = 140; $losepounds = $weight - $goalweight; //we multiply varaible a and b and store the value in cecho $tablegoal;echo '<table width="500" border="0" align="center" cellpadding="15" cellspacing="0"> <tr> <td align="center">You need to lose <strong>'; echo $losepounds;echo '</strong> pounds to reach your Goal Weight of <strong>';echo $goalweight;echo '</strong>.</td> </tr></table>';?> <form action="" method="post"><input name="Date" type="hidden" value="<?php PRINT "$today"; ?>" /><table width="312" align="center"> <tr> <td width="141"> My weight is:</td> <td width="42"><input type="text" name="Weight" size="7" maxlength="3" /></td> <td width="113"><input type="submit" value="Change Weight" /></td> </tr></table></form></body></html>
  6. How do I stop the below form from submitting if any field or atleast if field Weight is blank? also an error echo would be great. I have been trying to figure this out but cant do it. <table width="500" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td> <form action="insert.php" method="post"> <input name="Date" type="hidden" value="<?php PRINT "$today"; ?>" /> First Name: <input type="text" name="Firstname" /><br><br> Last Name: <input type="text" name="Lastname" /><br><br> Weight: <input type="text" name="Weight" /><br><br> <input type="submit" value="Submit Profile" /> </form> </td> </tr> </table>
  7. Below is the code I am using. The forum is under the tables how i wanted. All I want to do now is make it so that the form does not submit if (Weight) is left blank. Maybe showing a error message. This should stop some spam. insert.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Weight Log</title> </head> <body> <?php $con = mysql_connect("localhost","learnu","asdfasdf"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("learning", $con); $sql="INSERT INTO Peoples (Firstname, Lastname, Weight, Date) VALUES ('$_POST[Firstname]','$_POST[Lastname]','$_POST[Weight]','$_POST[Date]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; $db = mysql_connect("localhost","learnu","asdfasdf"); mysql_select_db("learning",$db); $result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC"); $table = '<table width="608" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td width="207" bgcolor="#CCCCCC">Firstname</td> <td width="204" bgcolor="#CCCCCC">Lastname</td> <td width="197" bgcolor="#CCCCCC">Weight</td> <td width="197" bgcolor="#CCCCCC">Date</td> </tr>'; while($row=mysql_fetch_array($result)) { $firstname = $row['Firstname']; $lastname = $row['Lastname']; $weight = $row['Weight']; $date = $row['Date']; $table.= '<tr>'; $table.= '<td>'.$firstname.'</td>'; $table.= '<td>'.$lastname.'</td>'; $table.= '<td>'.$weight.'</td>'; $table.= '<td>'.$date.'</td>'; $table.= '</tr>'; } $table .= '</table>'; echo $table; mysql_close($con) ?> <?php $today = date("F j, Y"); ?> <table width="500" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td> <form action="insert.php" method="post"> <input name="Date" type="hidden" value="<?php PRINT "$today"; ?>" /> First Name: <input type="text" name="Firstname" /><br><br> Last Name: <input type="text" name="Lastname" /><br><br> Weight: <input type="text" name="Weight" /><br><br> <input type="submit" value="Submit Profile" /> </form> </td> </tr> </table> </body> </html>
  8. Tried it but it just shows this: Error: Query was empty
  9. I think I did something wrong. I tried to follow instructions but now it just shows this submit form and redirects back to the submit form. submit.php <?php if(isset($_POST['submit_button'])) { $con = mysql_connect("localhost","trend_learnu","asdfasdf"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("trend_learningdb", $con); $sql="INSERT INTO Peoples (Firstname, Lastname, Weight, Date) VALUES ('$_POST[Firstname]','$_POST[Lastname]','$_POST[Weight]','$_POST[Date]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; $db = mysql_connect("localhost","trend_learnu","asdfasdf"); mysql_select_db("trend_learningdb",$db); $result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC"); $table = '<table width="608" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td width="207" bgcolor="#CCCCCC">Firstname</td> <td width="204" bgcolor="#CCCCCC">Lastname</td> <td width="197" bgcolor="#CCCCCC">Weight</td> <td width="197" bgcolor="#CCCCCC">Date</td> </tr>'; while($row=mysql_fetch_array($result)) { $firstname = $row['Firstname']; $lastname = $row['Lastname']; $weight = $row['Weight']; $date = $row['Date']; $table.= '<tr>'; $table.= '<td>'.$firstname.'</td>'; $table.= '<td>'.$lastname.'</td>'; $table.= '<td>'.$weight.'</td>'; $table.= '<td>'.$date.'</td>'; $table.= '</tr>'; } $table .= '</table>'; echo $table; mysql_close($con) ?> <html> <body> <?php $today = date("F j, Y"); } ?> <form action="" method="post"> <input name="Date" type="hidden" value="<?php PRINT "$today"; ?>" /> First Name: <input type="text" name="Firstname" /><br><br> Last Name: <input type="text" name="Lastname" /><br><br> Weight: <input type="text" name="Weight" /><br><br> <input name="button" type="submit" value="Submit Profile" /> </form> </body> </html>
  10. I tried it but it would just redirect insert.php to submit.php. Also after I submit from submit.php it would just look the same at insert.php. Is it possible to just have 1 php file that shows the html table and at the bottom It has the input fields and submit buttons? After this maybe updating the html form. Or somehow refreshing the page or data.
  11. I tried and it was going to the top $result = mysql_query("SELECT * FROM Peoples ORDER BY number DESC"); I tried and it now goes to the bottom $result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC"); Does this mean there is something wrong with my script? I also see a bug. If someone goes straight to insert.php it would enter blank fields to the database. What is my best solution for this? I just want a customer to enter their weight and right after they submit they see their results. OR better yet always showing the results and on the bottom having the weight submit button. When submitted the html table updates and shows the new weight.
  12. I will start reading about all of this. Can you post here everything that would be important to learn for php programming? I want to learn
  13. All together I think I have about 3 hours of learning php. I don't know about primary and foreign keys. I went to phpmyadmin and did this: Step 1: Step 2: Did I do this correctly and now am I able to make my script submit and show latest "number" or field in the bottom of my html table?
  14. Thanks How do I add a auto id autoincrement to the first column of my db?
  15. Sometimes it does add it to the bottom. What do I need to do to the scripts above so that it always strictly goes to the bottom of the html table? Am I supposed to put the mysql table with maybe a number so it goes like 1, 2, 3, 4, 5...if so how do I do this?
  16. Can someone please check the two php files below: submit.php <html> <body> <?php $today = date("F j, Y"); ?> <form action="insert.php" method="post"> <input name="Date" type="hidden" value="<?php PRINT "$today"; ?>" /> First Name: <input type="text" name="Firstname" /><br><br> Last Name: <input type="text" name="Lastname" /><br><br> Weight: <input type="text" name="Weight" /><br><br> <input type="submit" value="Submit Profile" /> </form> </body> </html> insert.php <?php $con = mysql_connect("localhost","trend_learnu","asdfasdf"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("trend_learningdb", $con); $sql="INSERT INTO Peoples (Firstname, Lastname, Weight, Date) VALUES ('$_POST[Firstname]','$_POST[Lastname]','$_POST[Weight]','$_POST[Date]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; $db = mysql_connect("localhost","trend_learnu","12345"); mysql_select_db("trend_learningdb",$db); $result = mysql_query("SELECT * FROM Peoples"); $table = '<table width="608" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td width="207" bgcolor="#CCCCCC">Firstname</td> <td width="204" bgcolor="#CCCCCC">Lastname</td> <td width="197" bgcolor="#CCCCCC">Weight</td> <td width="197" bgcolor="#CCCCCC">Date</td> </tr>'; while($row=mysql_fetch_array($result)) { $firstname = $row['Firstname']; $lastname = $row['Lastname']; $weight = $row['Weight']; $date = $row['Date']; $table.= '<tr>'; $table.= '<td>'.$firstname.'</td>'; $table.= '<td>'.$lastname.'</td>'; $table.= '<td>'.$weight.'</td>'; $table.= '<td>'.$date.'</td>'; $table.= '</tr>'; } $table .= '</table>'; echo $table; mysql_close($con) ?> If you go to the script live and submit: http://trendsavers.com/cutlog/submit.php You can see that what gets submitted goes to the top row. How do I make it go to the bottom row?
  17. Right now I am just using firstname, lastname and age as a test. My mail goal is to make it show the date and weight. (Current date and persons weight) I want a user to sign up and register. They will then have access to enter the date and weight just for logging reasons. Will it be very complicated to allow each user their own area to do this?
  18. It worked thanks I have to start planning out the script I am trying to make. I will post more info later.
  19. It worked thanks http://trendsavers.com/josuenerd/learning10.php <?php$db = mysql_connect("localhost","trend_learnu","asdfasdf");mysql_select_db("trend_learningdb",$db);$result = mysql_query("SELECT * FROM Peoples");while($row=mysql_fetch_array($result)){ $firstname = $row['Firstname']; $lastname = $row['Lastname']; $age = $row['Age']; $table = '<table width="608" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td width="207" bgcolor="#CCCCCC">Firstname</td> <td width="204" bgcolor="#CCCCCC">Lastname</td> <td width="197" bgcolor="#CCCCCC">Age</td> </tr>'; $table.= '<tr>'; $table.= '<td>'.$firstname.'</td>'; $table.= '<td>'.$lastname.'</td>'; $table.= '<td>'.$age.'</td>'; $table.= '</tr>'; $table.= '</table>';}echo $table;?> One thing I notice is that it only shows the last one. These are all the ones I have in phpmyadmin: Peter Griffin 35 Glenn Quagmire 33 Joshua Sandoval 27 Tom Cruise 40 Lolers Sanders 27 Henry Bullworth 57 Test last 22 Is it possible to show each one in a row? Thanks alot guys I am loving php
  20. submitform.html <html> <body> <form action="insert.php" method="post"> Firstname: <input type="text" name="Firstname" /><br> Lastname: <input type="text" name="Lastname" /><br> Age: <input type="text" name="Age" /><br><br> <input type="submit" value="Submit Profile" /> </form> </body> </html> insert.php <?php $con = mysql_connect("localhost","trend_learnu","xxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("trend_learningdb", $con); $sql="INSERT INTO Peoples (FirstName, LastName, Age) VALUES ('$_POST[Firstname]','$_POST[Lastname]','$_POST[Age]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Those are the 2 files I have for now. I would like to show the table on insert.php.
  21. I know html. The problem I have is making the above database information show up in rows in my html. I made a quick html table example: http://trendsavers.com/josuenerd/table.html
  22. Thanks I did it hear and learned how to do it in less than 1 hour. http://trendsavers.com/josuenerd/submitform.html I really think I am going to love php. - How can I make the 3 inputs show on a html table row after I submit? for example a table like this: First Name Last Name Age James Smith 25 Henry Smith 24
  23. There is only one thing I want to know. How to I fill out a text box, click submit and make that information go to a msql database? This is very simple but I am very new to php. This is all I want to learn. Also showing the value on a table after I submitted would be great. Thanks and I hope someone can help.
×
×
  • 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.