-
Posts
58 -
Joined
-
Last visited
Everything posted by Grok 🤖
-
This is what I am trying to do. I am trying to create a menu for updating information per person. The first page list all the people. The 2nd page is the menu of areas that can be edited. The 3rd page will have the information that was previously entered so the user can update the information. When the user updates the information on the 3rd page, the user goes back to the 2nd page. This all works fine with passing the correct user ID from the 1st page to the 2nd page to the 3rd page. The problem occurs when the user submits the update and goes back to the 2nd page. I can not figure out how to get the variable for the user ID to pass back to the 2nd page. To get the user ID from the list on the first page, I use the following code: Page 2 if ($_GET) { if (isset($_GET['user_ID']) && is_numeric($_GET['user_ID'])) { $user_ID = $_GET['user_ID']; } else { $user_ID = NULL; } } I have tried setting a session variable for the 3rd page and a hidden field to pass the user ID back to the 2nd page using the $_POST option. What I am trying to do is like this Start on Page 1 Go to Page 2 Go to Page 3 When user submits Page 3 to update the fields, go back to Page 2 so they can edit other options on the menu What is the best way to pass the variable I need back to page 2 once the form is submitted on page 3? Thanks for your time.
-
Did you add the results from the sql query in between the () you are trying to count? $sql = "Select * FROM usertable'"; $result = mysql_query($sql) or die(mysql_error()); $NumberOfRows = mysql_num_rows($result);
-
I think the what you need to do is use the $_GET option on the second page. You may want to look up the difference between POST and GET when you submit a form. The $_GET option will take the value you are passing in your URL and you will be able to use it on the second page. Here is an example of a code I used to do this if ($_GET) { if (isset($_GET['user_ID']) && is_numeric($_GET['user_ID'])) { $user_ID = $_GET['user_ID']; } else { $user_ID = NULL; } }
-
Give something like this a try, I broke your code down so it's easier to read. I took out a bunch of the echos and prints and just used HTML code instead. <?php if(mysql_num_rows($sql) > 0){ // Loop through the results while($row = mysql_fetch_array($sql)){ $username = $row['username']; $password = $row['password']; $email = $row['email']; if ($username == lady1) { ?> click, click > <a href='crew2.php'>here</a> < <?php } else { } ?> <b>Admin name</b>:<b><font face='Tahoma' size='3'> $username</font></b> <hr size=1> <br>Adm Pass: $password <br>Adm email: $email <?php if($i % $tblWidth ){ ?> <td align='center' valign='top' bgcolor='#F2F2F2'><?php echo $all_stuff; ?></td> <?php }else{ //else then print column number 2 etc for the next loop. ?> </tr><tr> <td align='center' cellpadding='10' valign='top' bgcolor='#F2F2F2'><?php echo $all_stuff; ?></td> <?php } //add only 1 for the loop ($i). $i++; ?> I don't know how you have your table set up, I'm assuming that you have omitted some of that code.
-
You may want to use mysql_num_rows() to count your rows with. http://us.php.net/manual/en/function.mysql-num-rows.php
-
I am still pretty new to php, but maybe this will help. On a from I created, I have a drop down box that a user can select the month for a birth date. When the form loads, the month is automatically set to the current month. Maybe you can edit the code I used to do this to work for what you are trying to do. The current month is being set by the $thisMonth = date('n') line. <?php $birthmonth = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); ini_set('date.timezone', 'America/Detroit'); $thisMonth = date('n'); for ($i=1;$i<=12;$i++) { ?> <option value="<?php echo $i < 10 ? '0'.$i : $i; ?>"> <?php echo $birthmonth[$i-1]; ?> </option> <?php } ?> </select>
-
Sorry, didn't read everything fully. Getting a little tired here. Anyways, I would have to agree with oni-kun on how it should be done.
-
I think you can add a value tag to the input tag and it will place a default value in your input box. Something like this: <input type="text" name="siteurl" size="25" value="http://www.phpfreak.com">
-
php mail program sends email but doesn't pick up form data?
perrij3 replied to mikeconley48's topic in PHP Coding Help
I had a simpler problem before. I fixed it like this: $message = "Name:" . $_POST['name'] . "\n\n"; $message .= "Email:" . $_POST['email'] ."\n\n"; -
Ok, I figured out the issue. I had Default set to a TinyInt in my Database. I changed it to a Int and it worked. Not sure why this would make a difference, but it did. I am only save a 0 or 1 there. Would a Bool be better to use instead of a Int. I can only have 1 default image per person.
-
I gave that a try and still the same error message.
-
I am trying to get the image I set as default with the following code. $sql4 = "SELECT * FROM image WHERE FK_OB_ID = $Obituary_ID AND Default = 1"; $result4 = mysql_query($sql4)or die (mysql_error()); $photo = mysql_fetch_assoc($result4); } } The area that I am having the problem with is the AND Default = 1 line. When I take it out, it works fine for now. I only have one image for the Obituary_ID set, so there is only one image that it can retrieve. When I add the AND Default = 1, I get the following error message, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 1' at line 3. Could someone please let me know what I am doing wrong? Thanks for any help you can offer.
-
THAT WORKED!!! THANK YOU SO MUCH!!
-
I would first like to thank everyone for all the help they have provide me so far. I am still not getting any data passed to the second page. This is still what I am getting when I am using <?php echo '<pre>'.print_r($_POST, true).'</pre>'; ?> at the top of the second page. Array ( ) I do make the changes to the second page to look like this: <?php //Start a session to be able to post name of whom the obituary is for on the thank you page session_start(); //Check to see if the form has been submitted and that Obituary ID is not empty include('includes/connection.inc.php'); if ($_POST && !empty($_SESSION['post']['Obituary_ID'])) { //Set session variable $_SESSION['post']['Obituary_ID'] = $_SESSION['post']['Obituary_ID']; $Obituary_ID = $_SESSION['post']['Obituary_ID'];
-
I changed the lines of code, but still nothing. Here is the new code, maybe that will help. I took out some coding that deals with SQL as well to make it shorter and easier to read. <?php session_start(); // must be called whenever you use $_SESSION's require('includes/connection.inc.php'); require('includes/corefuncs.php'); //Remove backslashes nukeMagicQuotes(); //initialize flag $done = false; //get details of selected record if ($_GET && !$_POST) { if (isset($_GET['Obituary_ID']) && is_numeric($_GET['Obituary_ID'])) { $Obituary_ID = $_GET['Obituary_ID']; } else { $Obituary_ID = NULL; } if ($Obituary_ID) { $sql = "SELECT * FROM obituaries WHERE OB_ID = $Obituary_ID"; $result = mysql_query($sql) or die (mysql_error()); $row = mysql_fetch_assoc($result); } } //if form has been submitted, add record to guestbook if (array_key_exists('sign', $_POST)) { //prepare expected items for insertion into database foreach ($_POST as $key => $value) { if (in_array($key, $expected)) { ${$key} = mysql_real_escape_string($value); } } //abandon the process if primary key invalid if (!is_numeric($Obituary_ID)) { die('Invalid Request'); } //redirect page of $Obituary_ID is invalid if ($done || !isset($Obituary_ID)) { $_SESSION['post'] = $_POST; header('Location: /throops/thanks_guestbook.php'); exit; } } ?> The next page starts like this: <?php echo '<pre>'.print_r($_POST, true).'</pre>'; ?> <?php //Start a session to be able to post name of whom the obituary is for on the thank you page session_start(); //Check to see if the form has been submitted and that Obituary ID is not empty if ($_POST && !empty($_POST['Obituary_ID'])) { //Set session variable $_SESSION['Obituary_ID'] = $_POST['Obituary_ID']; $Obituary_ID = $_SESSION['Obituary_ID'];
-
I added this code <?php echo '<pre>'.print_r($_POST, true).'</pre>'; ?> on the very top of the second page before i start the session variable. The data that I enter is being posted to the database, but not to the next page.
-
I do not get any error messages when I run the code. I entered the print_r($_POST); code before my if statement and got this Array ( ) 1 So the problem has to be with posting the data. Do I have to add something in the ACTION part of the FORM to POST the data to the next page? Here is my PHP code and the FORM code for the page people enter the data on: <?php include('includes/connection.inc.php'); include('includes/corefuncs.php'); //Remove backslashes nukeMagicQuotes(); //initialize flag $done = false; //prepare an array of expected items $expected = array('Obituary_ID', 'FullName', 'EmailAddress', 'AddressField1', 'AddressField2', 'YourCity', 'YourState', 'YourZip', 'Comment', 'DateEntered'); //create database connection $conn = dbConnect(''); //get details of selected record if ($_GET && !$_POST) { if (isset($_GET['Obituary_ID']) && is_numeric($_GET['Obituary_ID'])) { $Obituary_ID = $_GET['Obituary_ID']; } else { $Obituary_ID = NULL; } if ($Obituary_ID) { $sql = "SELECT * FROM obituaries WHERE OB_ID = $Obituary_ID"; $result = mysql_query($sql) or die (mysql_error()); $row = mysql_fetch_assoc($result); } } //if form has been submitted, add record to guestbook if (array_key_exists('sign', $_POST)) { //prepare expected items for insertion into database foreach ($_POST as $key => $value) { if (in_array($key, $expected)) { ${$key} = mysql_real_escape_string($value); } } //abandon the process if primary key invalid if (!is_numeric($Obituary_ID)) { die('Invalid Request'); } //prepare the SQL query $sql = "INSERT INTO guestbook (`FK_OB_ID`, `Name`, `Email`, `Address1`, `Address2`, `City`, `State`, `Zip`, `Condolence`, `DateEntered`) VALUES ('$Obituary_ID', '$FullName', '$EmailAddress', '$AddressField1', '$AddressField2', '$YourCity', '$YourState', '$YourZip', '$Comment', NOW())"; //Submit the query $done = mysql_query($sql) or die(mysql_error()); //redirect page of $Obituary_ID is invalid if ($done || !isset($Obituary_ID)) { header('Location: /throops/thanks_guestbook.php'); exit; } } ?> </head> <body> <!-- Start Main Content --> <!-- Form to add a new entry to the guestbook --> <form id="guestbook" name="guestbook" method="POST" action=""> <table> <tr> <td class="tablefield"><label for="FullName"><strong>Name:</strong></label></td> <td class="tabledata"><input type="text" maxlength="100" size="30" type="text" name="FullName" tabindex="1" id="FullName"></td> </tr> <tr> <td class="tablefield"><label for="EmailAddress"><strong>Email:</strong></label></td> <td class="tabledata"><input type="text" maxlength="100" size="30" type="text" name="EmailAddress" tabindex="1" id="EmailAddress"></td> </tr> <tr> <td class="tablefield"><label for="AddressField1">Address 1:</label></td> <td class="tabledata"><input type="text" maxlength="100" size="30" type="text" name="AddressField1" tabindex="2" id="AddressField1"></td> </tr> <tr> <td class="tablefield"><label for="AddressField2">Address 2:</label></td> <td class="tabledata"><input type="text" maxlength="100" size="30" type="text" name="AddressField2" tabindex="3" id="AddressField2"></td> </tr> <tr> <td class="tablefield"><label for="YourCity">City:</label></td> <td class="tabledata"><input type="text" maxlength="50" size="30" type="text" name="YourCity" tabindex="4" id="YourCity"></td> </tr> <tr> <td class="tablefield"><label for="YourState">State:</label></td> <td class="tabledata"><select name="YourState" id="YourState" tabindex="5"> <option value="WY">Wyoming</option> </select> </td> </tr> <tr> <td class="tablefield"><label for="YourZip">Zip:</label></td> <td class="tabledata"><input type="text" maxlength="10" size="15" type="text" name="YourZip" tabindex="6" id="YourZip"></td> </tr> <tr> <td class="tablefield"><label for="Comment">Condolence Message:</label></td> <td class="tabledata"><textarea name="Comment" cols="40" rows="12" id="Comment" tabindex="11"></textarea></td> </tr> <tr> <td><input name="Obituary_ID" type="hidden" value="<?php echo $row['OB_ID']; ?>"></td> <td align="right"><input type="submit" name="sign" Value="Sign Guestbook"> </td> </tr> </table> </form>
-
The hidden input field is being populated with the correct ID number and all the data that is being collected from the form is posting correctly to the database.
-
I am having some issues with session variables. I want to pass the ID # from one page to the next. I have a from where people can enter a message. What the user enters is placed into a database. I want to be on the next page (the one that is displayed once a user submits the message) to display other information from the database and to be a link to different pages using the ID #. The issue is the ID # isn't being passed to the next page as far as I can tell. In the form on the first page, I use a hidden input box to record the ID # as such: <input name="O_ID" type="hidden" value="<?php echo $row['OB_ID']; ?>"> On the next page, I am trying to call that value (O_ID") using the following code: session_start(); //Check to see if the form has been submitted and that Obituary ID is not empty if ($_POST && !empty($_POST['O_ID'])) { //Set session variable $_SESSION['O_ID'] = $_POST['O_ID']; $O_ID = $_SESSION['O_ID']; //create database connection $conn = dbConnect(''); include('includes/connect.php'); $sql = "SELECT * FROM obituaries WHERE OB_ID = $O_ID"; $result = mysql_query($sql) or die (mysql_error()); $row = mysql_fetch_assoc($result); } Could someone please help me figure out where my error is at? Thanks for your help in advance.
-
Hey, I'm still very new to PHP as well. I was wondering if the error has to do with the : between $hour:$minute. maybe coding it something like: if($showTime) {echo "$hour" . ":" . "$minute $ampm";}
-
I am working on creating a website for a funeral home. I need to be able to add an obituary entry which contains information about the person. visitation details and service location. I have created my MySQL database for these tables as such: [u]Individual[/u] (Table 1) `OB_ID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT , `FirstName` VARCHAR( 50 ) NOT NULL , `MiddleName` VARCHAR( 50 ) NULL , `LastName` VARCHAR( 50 ) NOT NULL , `SurName` VARCHAR( 5 ) NULL , `DateBorn` DATE NULL , `DatePassed` DATE NULL , `Obituary` TEXT NULL , `DateEntered` TIMESTAMP NOT NULL, PRIMARY KEY ( `OB_ID` ) ) ENGINE = InnoDB [u]Visitation_Locale[/u] (Table 2) `VisitLoc_ID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT , `Name` VARCHAR( 100 ) NOT NULL , `Address1` VARCHAR( 100 ) NOT NULL , `Address2` VARCHAR( 100 ) NULL , `City` VARCHAR( 50 ) NOT NULL , `State` CHAR( 2 ) NOT NULL , `Zip` CHAR( 10 ) NOT NULL , PRIMARY KEY ( `VisitLoc_ID` ) ) ENGINE = InnoDB [u]Service[/u] (Table 3) `Service_ID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT , `Name` VARCHAR( 100 ) NOT NULL , `Address1` VARCHAR( 100 ) NOT NULL , `Address2` VARCHAR( 100 ) NULL , `City` VARCHAR( 50 ) NOT NULL , `State` CHAR( 2 ) NOT NULL , `Zip` CHAR( 10 ) NOT NULL , PRIMARY KEY ( `Service_ID` ) ) ENGINE = InnoDB [u]Individual_Service[/u] (Table 4) `FK_OB_ID` SMALLINT NOT NULL , `FK_Service_ID` SMALLINT NOT NULL , `StartTime` VARCHAR( 8 ) NOT NULL , `EndTime` VARCHAR( 8 ) NOT NULL , `Date` DATE NOT NULL , PRIMARY KEY ( `FK_OB_ID` , `FK_Service_ID` ) ) ENGINE = InnoDB [u]Individual_Visitations[/u] (Table 5) `Visit_ID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT , `FK_OB_ID` SMALLINT NOT NULL , `FK_VisitLoc_ID` SMALLINT NOT NULL , `StartTime` VARCHAR( 8 ) NOT NULL , `EndTime` VARCHAR( 8 ) NOT NULL , `Date` DATE NOT NULL , PRIMARY KEY ( `Visit_ID` ) ) ENGINE = InnoDB What I am trying to do is create 3 forms that go like this. First the user enters the information for the obituary, then the user enters information about the visitation (a person can have more than 1 visitation), after that a form to select where the service will be at. The reason for this is each visitation and service will have a different day and time, so I figured this would be the easiest way for the user to enter all the data into the database. The problem I am having is with passing the obituary ID (OB_ID) to the next form. Everything is tied to that number. I don't know if my thinking is correct on this or not, but this is how I image it should work. The user enters the information into the first form, presses submit. The php file that I am using to post this information into the database some how receives the new (OB_ID) number it created and passes it onto the next form (visitation). Am I headed in the right direction or is my thinking way off? I did read somewhere about the storing a user ID variable that is generated when someone submits data by using a session variable. I tried to set one up in this code, but it doesn't seem to work or I just am not sure how to retrieve it on the next page. Here is the code that I am using to <?php // clear any existing session variables $_SESSION = array(); // set a variable to control access to other pages $_SESSION['ObituaryInfo'] = true; $required = array('user_id'); include('../includes/connection.inc.php'); include('../includes/corefuncs.php'); if (array_key_exists('insert', $_POST)) { //change birth date to MqSQL format $bm = $_POST['birthmonth']; $bd = trim($_POST['birthday']); $by = trim($_POST['birthyear']); if (empty($bd) || empty($by)) { $error = 'Please fill in all birth date fields'; } elseif (!is_numeric($bd) || !is_numeric($by)) { $error = 'Please use numbers only'; } elseif (($bd < 1 || $bd > 31) || ($by < 1890 || $by > 2100)) { $error = 'Please use numbers within the correct date or year range in birth date.'; } elseif (!checkdate($bm,$bd,$by)) { $error = 'You have used an invalid birth date'; } else { $bd = $bd < 10 ? '0'.$bd : $bd; $DateBorn = "$by-$bm-$bd"; } //change passed date to MqSQL format $pm = $_POST['passedmonth']; $pd = trim($_POST['passedday']); $py = trim($_POST['passedyear']); if (empty($pd) || empty($py)) { $error = 'Please fill in all passed date fields'; } elseif (!is_numeric($pd) || !is_numeric($py)) { $error = 'Please use numbers only'; } elseif (($pd < 1 || $pd > 31) || ($py < 1000 || $py > 99999)) { $error = 'Please use numbers within the correct date or year range for the passing date.'; } elseif (!checkdate($pm,$pd,$py)) { $error = 'You have used an invalid passing date.'; } else { $pd = $pd < 10 ? '0'.$pd : $pd; $DatePassed = "$py-$pm-$pd"; } //Remove backslashes nukeMagicQuotes(); //prepare an array of expected items $expected = array('FirstName', 'MiddleName', 'LastName', 'SurName', 'DateBorn', 'DatePassed', 'Obituary', 'DateEntered'); //create database connection $conn = dbConnect(''); //make $_POST data safe for insertion into database foreach ($_POST as $key => $value) { if (in_array($key, $expected)) { ${$key} = mysql_real_escape_string($value); } } //prepare the SQL query $sql = "INSERT INTO obituaries (`FirstName`, `MiddleName`, `LastName`, `SurName`, `DateBorn`, `DatePassed`, `Obituary`, `DateEntered`) VALUES('$FirstName', '$MiddleName', '$LastName', '$SurName', '$DateBorn', '$DatePassed', '$Obituary', NOW())"; //process the query $result = mysql_query($sql) or die(mysql_error()); //store Person Obituary ID $user_id = mysql_insert_id( $conn ); //if successful, redirect to Vistitation form. if ($result) { header('Location: http://localhost/funeralhome/admin/add_ob_visitation.php'); exit; } } ?> Thank you for any help or suggestions you can provide.
-
[SOLVED] Email form issues with PHP 5 vs. PHP 4
perrij3 replied to perrij3's topic in PHP Coding Help
Ok, I figured out where my error was, I had to change the follow code: // Build the message $message = "Name: $name\n\n"; $message .= "Email: $email\n\n"; $message .= "Comments: $comments\n\n"; to // Build the message $message = "Name:" . $_POST['name'] . "\n\n"; $message .= "Email:" . $_POST['email'] ."\n\n"; $message .= "Comments:" . $_POST['comments'] . "\n\n"; I'm not really sure why this is, but it works now. -
What if you change your SQL statement to something like this: $query = "SELECT * FROM `table_here` ORDER BY `ID` DESC" This would get all the data from this table and put it descending order. If you want it in ascending order, use ASC instead of DESC. This would eliminate needing to find the max and min ID numbers. I would then try using the while loop again.
-
I'm no where near an expect on this topic, but this may or may not be valid. I was just wondering if when you use the relative positions with divs, if you could use the clear="both" in CSS or add it to a <br clear="all"> after your div. Maybe that would stop them from appearing on top of each other.
-
I am new to PHP as well, but maybe this could help you. I wrote this code to retrieve data from a MySQL database. There are a few differences from your code. I use a WHILE loop instead of a FOR statement like you did. I would also recommend using CSS to change the display of the page, instead changing it in the HTML tags itself. Here is the code I used to display my data. I saved this file as F_NcompDate.php <?php function createOptions(){ $host="localhost"; $user=""; $password=""; $cxn = mysql_connect($host,$user,$password) or die ("Couldn't connect to database."); $dbname = 'ABCDEFG'; mysql_select_db($dbname); $query = "SELECT * FROM `workorder` WHERE `Completed`='0' ORDER BY `Date_Filed` DESC, `Location` ASC"; $result = mysql_query($query) or die (mysql_error()); while($row = mysql_fetch_array($result)) // Loop thru recordset and get values { echo "<tr><td width=\"40\">"; echo $row["Date_Filed"]; echo "</td>"; echo "<td width=\"50\">"; echo $row["WorkOrder_ID"]; echo "</td>"; echo "<td width=\"70\" align=\"center\">"; echo $row["Location"]; echo "</td>"; echo "<td width=\"80\">"; echo $row["By"]; echo "</td>"; echo "<td width=\"260\">"; echo $row["Problem"]; echo "</td>"; echo "<td width=\"260\">"; echo $row["Comments"]; echo "</td>"; echo "<td width=\"40\">"; echo $row["Date_Completed"]; echo "</td></tr>"; } } // End createOptions() ?> I had to call this function on another php page. Here is the code I used to call the this function. <?php include("F_NcompDate.php"); //include your function(s) ?> <head> <title>Title of Page</title> <link href="css/gobal.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header1"> <img src="images/hi.gif" alt="Holiday Inn Logo" width="200" height="83" id="logo"/> <p align="right"><a href="home.html" target="_self" class="headlink">Home</a> | <a href="reports.html" target="_self" class="headlink">Reports</a> </p> <h1 align="center">Header</h1> </div> <div id="reportContainer"> <h1 align="center">Non Completed Work Orders By Finished Date</h1> <table border="1" width="800"> <tr> <th>Dated Filed</th> <th>Work Order #</th> <th>Location</th> <th>Filed By</th> <th>Problem</th> <th>Solutions</th> <th>Target Date</th> </tr> <?php createOptions(); //execute your function defined in 'F_NcompDate.php' ?> </table> </div> </body> </html> Hope this helps.