itgranny Posted June 22, 2015 Share Posted June 22, 2015 I am having trouble with having my page remember a POST item. What I'm trying to do is to have the data updated message to include a link using a userid, a random number that's used to find things in the database. I've tried several ways but still having trouble. Below are 2 such ways (along with others). I keep getting a page where the userid doesn't show up. It doesn't make sense though because it gets inserted into the database. Could someone take a look?Instead of coming up with a link like this:http://www.mynewpage.com/visitdetails.php?userid=113555588701606e973.42256784 It looks like this and I get a page doesn't exist error. http://www.mynewpage.com/visitDetails.php?userid= connection info here..... $today = date("F j, Y, g:i a"); $careComments = htmlspecialchars("$_POST[careComments]", ENT_QUOTES); $feedComments = htmlspecialchars("$_POST[feedComments]", ENT_QUOTES); $waterComments = htmlspecialchars("$_POST[waterComments]", ENT_QUOTES); $ventilationComments = htmlspecialchars("$_POST[ventilationComments]", ENT_QUOTES); $recordsComments = htmlspecialchars("$_POST[recordsComments]", ENT_QUOTES); $invNotes = htmlspecialchars("$_POST[invNotes]", ENT_QUOTES); $facilityComments = htmlspecialchars("$_POST[facilityComments]", ENT_QUOTES); $summaryComments = htmlspecialchars("$_POST[summaryComments]", ENT_QUOTES); $deads = "$_POST[deads]"; $start = "$_POST[start]"; $mortality = $deads/$start*100; $userid = "$_POST[userid]"; $sql="INSERT INTO visitNotes (id,today,userid,date,site,name,groupID,caretaker,reason,careComments,cough,looseness,sorting,treating,walking,med1,med2,euthanasia,biosecurity,feed,feedComments,adjustments,tickets,water,waterComments,cleanwater,meter,temps,ventilationComments,humidity,fans,curtains,inlets,hilo,alarm,backup,pitLevel,recordsComments,medRecords,rodent,testAlarm,lp,lpLevels,genFuel,genFuelLevel,genHoursRecord,genHours,invRecords,invNotes,currentInv,start,deads,mortality,cleanOffice,facilityComments,mow,gates,chute,lights,deadDisp,summaryComments) VALUES ('$_POST[id]','$today','$_POST[userid]','$_POST[date]','$_POST[site]','$_POST[name]','$_POST[groupID]','$_POST[caretaker]','$_POST[reason]','$careComments','$_POST[cough]','$_POST[looseness]','$_POST[sorting]','$_POST[treating]','$_POST[walking]','$_POST[med1]','$_POST[med2]','$_POST[euthanasia]','$_POST[biosecurity]','$_POST[feed]','$feedComments','$_POST[adjustments]','$_POST[tickets]','$_POST[water]','$waterComments','$_POST[cleanwater]','$_POST[meter]','$_POST[temps]','$ventilationComments','$_POST[humidity]','$_POST[fans]','$_POST[curtains]','$_POST[inlets]','$_POST[hilo]','$_POST[alarm]','$_POST[backup]','$_POST[pitLevel]','$recordsComments','$_POST[medRecords]','$_POST[rodent]','$_POST[testAlarm]','$_POST[lp]','$_POST[lpLevels]','$_POST[genFuel]','$_POST[genFuelLevel]','$_POST[genHoursRecord]','$_POST[genHours]','$_POST[invRecords]','$invNotes','$_POST[currentInv]','$_POST[start]','$_POST[deads]','$mortality','$_POST[cleanOffice]','$facilityComments','$_POST[mow]','$_POST[gates]','$_POST[chute]','$_POST[lights]','$_POST[deadDisp]','$summaryComments')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added <br>"; echo "<a href='visitDetails.php?userid='$_POST[userid]'>Email Visit Results</a>"; echo "<br><br><a href='visitDetails.php?userid='" . $userid . "'>Visit Results</a>"; mysqli_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted June 22, 2015 Share Posted June 22, 2015 Do you have error reporting ON. It would appear that either $_POST['userid'] is empty or not being POSTed. Quote Link to comment Share on other sites More sharing options...
itgranny Posted June 22, 2015 Author Share Posted June 22, 2015 Yeah, that's what's happening but why? It goes into the database just fine in the code earlier. Why can't it remember it either as coming from a POST or even a variable? Quote Link to comment Share on other sites More sharing options...
Barand Posted June 22, 2015 Share Posted June 22, 2015 Is that the whole of the code or have you just posted sections? BTW, that (F j, Y) is a useless format for storing dates in a DB. You cannot compare, sort or use datetime functions directly on that format. Always store dates as YYYY-MM-DD. Store dates for functionality, not prettiness. You can reformat on output of the data. Make "today" a DATETIME field and write NOW() to it. Quote Link to comment Share on other sites More sharing options...
itgranny Posted June 22, 2015 Author Share Posted June 22, 2015 On the form page, I have this code to get the userid. The whole userid thing is so nobody can guess what the url is. <?php $userid = uniqid(rand(),true); ?> Then it gets posted to this page along with my other form items. The only thing that's not here is the connection which is just a mysqli string. I'm just not sure why it can remember it to put it in the database, but forgets it in that last line. Quote Link to comment Share on other sites More sharing options...
itgranny Posted June 23, 2015 Author Share Posted June 23, 2015 This is the form. I changed out the connection. <!DOCTYPE html> <html> <head> <title>Supervisor Form</title> <!-- to make text boxes pure numbers --> <SCRIPT language=Javascript> <!-- function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } //--> </SCRIPT> <style> body {background-color:lightgrey} .normal { font-family: Tahoma, Arial, sans-serif; font-color: black; font-size: 12pt; text-align: left; } .title { font-family: Tahoma, Arial, sans-serif; font-color: black; font-size: 16pt; font-weight: bold; } .center { margin-left: auto; margin-right: auto; text-align: center; } table td { height: 30px; padding:5px; } </style> </head> <body> <div style="width:100%;"> <div class="center" style="width:800px"> <div style="background-color: white; margin-top: -8px; width: 100%;"> <!-- Top Part --> <form method="post" action="visitInsert.php"> <?php $userid = uniqid(rand(),true); ?> <input type="hidden" name="userid" value="<?php echo $userid; ?>"> <table width=100% border="1" style="border-collapse:collapse"> <tr> <td class="title" width= "170px" rowspan="2">RVF Site Evaluation<br> <img src="images/logo.png"> </td> <td class="normal" width="220px"> <b>Date of visit:</b> <select name="date" size="1"> <?php $month= date("m"); $day= date("d"); $year= date("Y"); for($i=0; $i<=15; $i++){ echo "<option value='"; echo date('m-d-y',mktime(0,0,0,$month,($day-$i),$year)); echo "'>"; echo date('m-d-y',mktime(0,0,0,$month,($day-$i),$year)); echo "</option>"; } ?> </select> </td> <td class="normal" width="200px"> <b>Site:</b> <?php mysql_connect('localhost', 'user', 'pass'); mysql_select_db('visit'); $sql = "SELECT site FROM sites ORDER BY site"; $result = mysql_query($sql); echo "<select name='site'>"; while ($row = mysql_fetch_array($result)) { echo "<option style='text-transform: uppercase;'" . $row['site'] . "' >" . $row['site'] . "</option>"; } echo "</select>"; ?> </td> </tr> <tr> <td class="normal"> <b><b>Supervisor:</b></b> <?php $sql = "SELECT name FROM serviceman ORDER BY name"; $result = mysql_query($sql); echo "<select name='name'>"; while ($row = mysql_fetch_array($result)) { echo "<option style='text-transform: uppercase; value='" . $row['name'] . "' >" . $row['name'] . "</option>"; } echo "</select>"; ?> </td> <td class="normal"> <b>Group ID:</b> <input style="text-transform: uppercase" type="text" name="groupID" > </td> </tr> <tr> <td class="normal"><b>Caretaker There?</b> <br>Yes <input id="caretaker" name="caretaker" type="radio" value="T"> No <input id="caretaker" name="caretaker" type="radio" value="F"> </td> <td class="normal" colspan="2"> <b>Reason for Visit</b><br> Count <input id="count" name="reason" type="radio" value="1"> Mark <input id="mark" name="reason" type="radio" value="2"> Production/Management <input id="production" name="reason" type="radio" value="3"> </td> </tr> </table> <br> <!-- Bottom Part --> <table width=100% border="1" class="normal" style="border-collapse:collapse"> <tr> <!-- listed criteria --> <td style="width:200px;"> </td> <td style="width:250px; text-align: center; "> <b >Evaluation </b> </td> <td style="width:350px; text-align: left; "> <b>Comments</b> </td> </tr> <tr class="topic"> <td colspan="5"> <b>Pig Care</b> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Cough </td> <td > 0<input name="cough" type="radio" value="0"> 1<input name="cough" type="radio" value="1"> 2<input name="cough" type="radio" value="2"> 3<input name="cough" type="radio" value="3"> 4<input name="cough" type="radio" value="4"> </td> <td class="topic" rowspan="9"> <span > Comments: <textarea rows="24" cols="50" placeholder="Type pigcare comments here...." style=" border: none; " name="careComments"></textarea> </span> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Looseness </td> <td> 0<input name="looseness" type="radio" value="0"> 1<input name="looseness" type="radio" value="1"> 2<input name="looseness" type="radio" value="2"> 3<input name="looseness" type="radio" value="3"> 4<input name="looseness" type="radio" value="4"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Sorting </td> <td> 0<input name="sorting" type="radio" value="0"> 2<input name="sorting" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Treating Sick Animals </td> <td> 0<input name="treating" type="radio" value="0"> 2<input name="treating" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Walking Pens </td> <td> 0<input name="walking" type="radio" value="0"> 2<input name="walking" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Water Meds 1 </td> <td style="text-align: center;"> <?php $sql = "SELECT med FROM med"; $result = mysql_query($sql); echo "<select name='med1'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['med'] . "'>" . $row['med'] . "</option>"; } echo "</select>"; ?> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Water Meds 2 </td> <td style="text-align: center;"> <?php $sql = "SELECT med FROM med"; $result = mysql_query($sql); echo "<select name='med2'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['med'] . "'>" . $row['med'] . "</option>"; } echo "</select>"; ?> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Euthanasia </td> <td> 0<input name="euthanasia" type="radio" value="0"> 2<input name="euthanasia" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Biosecurity </td> <td> 0<input name="biosecurity" type="radio" value="0"> 2<input name="biosecurity" type="radio" value="2"> </td> </tr> <tr class="topic"> <td colspan="5"> <b>Feed</b> </td> </tr> <tr class="topic"> <td style="text-align: right;"> All pigs have access to feed </td> <td> 0<input name="feed" type="radio" value="0"> 1<input name="feed" type="radio" value="1"> 2<input name="feed" type="radio" value="2"> 3<input name="feed" type="radio" value="3"> 4<input name="feed" type="radio" value="4"> </td> <td class="topic" rowspan="3"> <span > Comments: <textarea rows="9" cols="50" placeholder="Type feed comments here...." style=" border: none;" name="feedComments"></textarea> </span> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Feeder adjustments are correct </td> <td> 0<input name="adjustments" type="radio" value="0"> 3<input name="adjustments" type="radio" value="3"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Feed tickets </td> <td> 0<input name="tickets" type="radio" value="0"> 1<input name="tickets" type="radio" value="1"> </td> </td> </tr> <tr class="topic"> <td colspan="5"> <b>Water</b> </td> </tr> <tr class="topic"> <td style="text-align: right;"> All pigs have access to water </td> <td> 0<input name="water" type="radio" value="0"> 1<input name="water" type="radio" value="1"> 2<input name="water" type="radio" value="2"> 3<input name="water" type="radio" value="3"> 4<input name="water" type="radio" value="4"> </td> <td class="topic" rowspan="3"> <span > Comments: <textarea rows="9" cols="50" placeholder="Type water comments here...." style=" border: none;" name="waterComments"></textarea> </span> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Line/filters clean </td> <td> 0<input name="cleanwater" type="radio" value="0"> 2<input name="cleanwater" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Water meter readings </td> <td> 0<input name="meter" type="radio" value="0"> 2<input name="meter" type="radio" value="2"> </td> </tr> <tr class="topic"> <td colspan="5"> <b>Ventilation</b> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Pig comfort temperatures </td> <td> 0<input name="temps" type="radio" value="0"> 2<input name="temps" type="radio" value="2"> </td> <td class="topic" rowspan="8"> <span > Comments: <textarea rows="30" cols="50" placeholder="Type ventilation comments here...." style=" border: none;" name="ventilationComments"></textarea> </span> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Pig comfort humidity </td> <td> 0<input name="humidity" type="radio" value="0"> 2<input name="humidity" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Fans </td> <td> 0<input name="fans" type="radio" value="0"> 1<input name="fans" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Curtains </td> <td> 0<input name="curtains" type="radio" value="0"> 1<input name="curtains" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Inlets </td> <td> 0<input name="inlets" type="radio" value="0"> 1<input name="inlets" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Hi-Low records </td> <td> 0<input name="hilo" type="radio" value="0"> 1<input name="hilo" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Alarm settings </td> <td> 0<input name="alarm" type="radio" value="0"> 1<input name="alarm" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Back up settings </td> <td> 0<input name="backup" type="radio" value="0"> 1<input name="backup" type="radio" value="1"> </td> </tr> <tr class="topic"> <td colspan="5"> <b>Records</b> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Pit level </td> <td> 0<input name="pitLevel" type="radio" value="0"> 1<input name="pitLevel" type="radio" value="1"> </td> <td class="topic" rowspan="10"> <span > Comments: <textarea rows="36" cols="50" placeholder="Type records comments here...." style=" border: none;" name="recordsComments"></textarea> </span> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Med records </td> <td> 0<input name="medRecords" type="radio" value="0"> 1<input name="medRecords" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Rodent plan </td> <td> 0<input name="rodent" type="radio" value="0"> 1<input name="rodent" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Alarm test </td> <td> 0<input name="testAlarm" type="radio" value="0"> 1<input name="testAlarm" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> LP level checked </td> <td> 0<input name="lp" type="radio" value="0"> 1<input name="lp" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> LP levels </td> <td> <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="lpLevels" style="width: 40px;" maxlength="2">% </td> </tr> <tr class="topic"> <td style="text-align: right;"> Generator fuel level </td> <td> 0<input name="genFuel" type="radio" value="0"> 1<input name="genFuel" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Generator fuel </td> <td> <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="genFuelLevel" style="width: 40px;" maxlength="2">% </td> </tr> <tr class="topic"> <td style="text-align: right;"> Generator hours recorded </td> <td> 0<input name="genHoursRecord" type="radio" value="0"> 1<input name="genHoursRecord" type="radio" value="1"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Generator hours </td> <td> <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="genHours" style="width: 40px;" maxlength="7"> hours </td> </tr> <tr class="topic"> <td colspan="3"> <b>Inventory</b> </td> </tr> <tr> <td style="text-align: right;"> Inventory records </td> <td> 0<input name="invRecords" type="radio" value="0"> 1<input name="invRecords" type="radio" value="1"> </td> <td rowspan="5"> <span > Comments: <textarea rows="10" cols="50" placeholder="Type inventory notes here...." style=" border: none;" name="invNotes"></textarea> </span> </td> </tr> <tr> <td style="text-align: right;"> Current inv.</td> <td><INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="currentInv" style="width: 40px;" maxlength="8"></td>; <tr> <td style="text-align: right;"> Starting inventory </td> <td> <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="start" style="width: 40px;" maxlength="8"> </td> </tr> <tr> <td style="text-align: right;"> Deads </td> <td> <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="deads" style="width: 40px;" maxlength="5"> </td> </tr> <tr class="topic"> <td colspan="3"> <b>Facility</b> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Office clean </td> <td> 0<input name="cleanOffice" type="radio" value="0"> 2<input name="cleanOffice" type="radio" value="2"> </td> <td rowspan="6" style='vertical-align:top;'"> <span > Comments: <textarea rows="10" cols="50" placeholder="Typesite/facility comments here. (lighting, gates and flooring, chutes, dead disposal, etc.)" style=" border: none;" name="facilityComments"></textarea> </span> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Mowing/Outside </td> <td> 0<input name="mow" type="radio" value="0"> 2<input name="mow" type="radio" value="2"> </td> <tr class="topic"> <td style="text-align: right;"> Chute </td> <td> 0<input name="chute" type="radio" value="0"> 2<input name="chute" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Gates </td> <td> 0<input name="gates" type="radio" value="0"> 2<input name="gates" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Lights </td> <td> 0<input name="lights" type="radio" value="0"> 2<input name="lights" type="radio" value="2"> </td> </tr> <tr class="topic"> <td style="text-align: right;"> Dead disposal </td> <td> 0<input name="deadDisp" type="radio" value="0"> 2<input name="deadDisp" type="radio" value="2"> </td> </tr> <tr class="topic"> <td colspan="3"> <b>Summary/Goals</b> </td> </tr> <td colspan="3" <span > <textarea rows="5" cols="93" placeholder="Visit notes (communications and followups)" style=" border: none;" name="summaryComments"></textarea> </span> </td> </tr> <tr> <td colspan="3"><input type="submit" name="submit" value="submit"> </td> </tr> </table> </form> <br><br><br><br><br> </div> </div> </div> </body> </html> This is the actual reciever. Its the bottom lines. I've tried them several ways. None work. <?php $con=mysqli_connect('localhost', 'user', 'pass', "visit"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $today = date("F j, Y, g:i a"); $careComments = htmlspecialchars("$_POST[careComments]", ENT_QUOTES); $feedComments = htmlspecialchars("$_POST[feedComments]", ENT_QUOTES); $waterComments = htmlspecialchars("$_POST[waterComments]", ENT_QUOTES); $ventilationComments = htmlspecialchars("$_POST[ventilationComments]", ENT_QUOTES); $recordsComments = htmlspecialchars("$_POST[recordsComments]", ENT_QUOTES); $invNotes = htmlspecialchars("$_POST[invNotes]", ENT_QUOTES); $facilityComments = htmlspecialchars("$_POST[facilityComments]", ENT_QUOTES); $summaryComments = htmlspecialchars("$_POST[summaryComments]", ENT_QUOTES); $deads = "$_POST[deads]"; $start = "$_POST[start]"; $mortality = $deads/$start*100; $userid = "$_POST[userid]"; $sql="INSERT INTO visitNotes (id,today,userid,date,site,name,groupID,caretaker,reason,careComments,cough,looseness,sorting,treating,walking,med1,med2,euthanasia,biosecurity,feed,feedComments,adjustments,tickets,water,waterComments,cleanwater,meter,temps,ventilationComments,humidity,fans,curtains,inlets,hilo,alarm,backup,pitLevel,recordsComments,medRecords,rodent,testAlarm,lp,lpLevels,genFuel,genFuelLevel,genHoursRecord,genHours,invRecords,invNotes,currentInv,start,deads,mortality,cleanOffice,facilityComments,mow,gates,chute,lights,deadDisp,summaryComments) VALUES ('$_POST[id]','$today','$_POST[userid]','$_POST[date]','$_POST[site]','$_POST[name]','$_POST[groupID]','$_POST[caretaker]','$_POST[reason]','$careComments','$_POST[cough]','$_POST[looseness]','$_POST[sorting]','$_POST[treating]','$_POST[walking]','$_POST[med1]','$_POST[med2]','$_POST[euthanasia]','$_POST[biosecurity]','$_POST[feed]','$feedComments','$_POST[adjustments]','$_POST[tickets]','$_POST[water]','$waterComments','$_POST[cleanwater]','$_POST[meter]','$_POST[temps]','$ventilationComments','$_POST[humidity]','$_POST[fans]','$_POST[curtains]','$_POST[inlets]','$_POST[hilo]','$_POST[alarm]','$_POST[backup]','$_POST[pitLevel]','$recordsComments','$_POST[medRecords]','$_POST[rodent]','$_POST[testAlarm]','$_POST[lp]','$_POST[lpLevels]','$_POST[genFuel]','$_POST[genFuelLevel]','$_POST[genHoursRecord]','$_POST[genHours]','$_POST[invRecords]','$invNotes','$_POST[currentInv]','$_POST[start]','$_POST[deads]','$mortality','$_POST[cleanOffice]','$facilityComments','$_POST[mow]','$_POST[gates]','$_POST[chute]','$_POST[lights]','$_POST[deadDisp]','$summaryComments')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added <br>"; echo "<a href='visitDetails.php?userid='$_POST[userid]'>Email Visit Results</a>"; echo "<br><br><a href='visitDetails.php?userid='" . $userid . "'>Visit Results</a>"; mysqli_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted June 23, 2015 Share Posted June 23, 2015 Don't put quotes around the userid in url echo "<br><br><a href='visitDetails.php?userid='" . $userid . "'>Visit Results</a>";?> | | +-- href ends here -----+ 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.