josuenerd
Members-
Posts
25 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
josuenerd's Achievements
Newbie (1/5)
0
Reputation
-
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>
-
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)
-
I am trying to create a simple php project. (need help)
josuenerd replied to josuenerd's topic in PHP Coding Help
I figured it out on a different thread Thanks to everyone here also for helping me get to where I am on my script. -
How do i stop this simple form from submitting if a field is blank?
josuenerd replied to josuenerd's topic in PHP Coding Help
I figured out how to use this Thanks! -
How do i stop this simple form from submitting if a field is blank?
josuenerd replied to josuenerd's topic in PHP Coding Help
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? -
How do i stop this simple form from submitting if a field is blank?
josuenerd replied to josuenerd's topic in PHP Coding Help
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> -
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>
-
I am trying to create a simple php project. (need help)
josuenerd replied to josuenerd's topic in PHP Coding Help
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> -
I am trying to create a simple php project. (need help)
josuenerd replied to josuenerd's topic in PHP Coding Help
I got the same error. Not sure what's happening -
I am trying to create a simple php project. (need help)
josuenerd replied to josuenerd's topic in PHP Coding Help
Tried it but it just shows this: Error: Query was empty -
I am trying to create a simple php project. (need help)
josuenerd replied to josuenerd's topic in PHP Coding Help
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> -
I am trying to create a simple php project. (need help)
josuenerd replied to josuenerd's topic in PHP Coding Help
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. -
I am trying to create a simple php project. (need help)
josuenerd replied to josuenerd's topic in PHP Coding Help
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. -
I am trying to create a simple php project. (need help)
josuenerd replied to josuenerd's topic in PHP Coding Help
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 -
I am trying to create a simple php project. (need help)
josuenerd replied to josuenerd's topic in PHP Coding Help
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?