PHP - Updata The Data Into The Text Field.
could anyone pls check this coding? i need to display the data from database into the text field for editing then submit to the existing database.
mysql_select_db("uni", $con); $sql=mysql_query("select * from student"); $res=0; while($row=mysql_fetch_array($sql)) { if($row['StudentID']==$_POST["sid"]) { ?> <form id="form2" name="form2" method="post" action="update.php"> <h2><p><?php echo "StudentID :" ?> <input type="text" name="sid" id="sid" value="<?php echo"".$row['StudentID'] ?>" /> <p><?php echo "StudentName :" ?> <input type="text" name="stname" id="stname" value="<?php echo"".$row['StudentName'] ?>" /> </p> <?php $res=1; } }?> <h2> <?php if($res==0) { echo "Please enter the Correct ID. "; } update.php mysql_select_db("uni", $con); mysql_query("UPDATE student SET StudentID = .$row['StudentID'] WHERE student.StudentID = '.$row['StudentID']'"); mysql_query("UPDATE student SET StudentName = .$row['StudentName'] WHERE student.StudentID = '.$row['StudentID']'"); echo "Successfully Edited"; //submit button Similar TutorialsHi guys, basically here pull out the data from database then creating taxt field automatically and submit into anther table. everything works fine but data not inserting in to the table. could you guys check my code please? <?php $con = mysql_connect("localhost","root",""); mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); ?> <?php $result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name ="cid[]">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['CourseID'] . '">'. $row['CourseID'] .'</option>'; } echo '</select>'; //------------------ ?> <?php if(!empty($_POST["submit"])) { $value = empty($_POST['question']) ? 0 : $_POST['question']; ?> <form name="form1" method="post" action="result.php"> <?php for($i=0;$i<$value;$i++) { echo 'Question NO: <input type="text" name="qno[]" size="2" maxlength="2" class="style10"> Enter Marks: <input type="text" name="marks[]" size="3" maxlength="3" class="style10"><br>'; } ?> <label> <br /> <br /> <input type="submit" name="Submit" value="Submit" class="style10"> </label> </form> <?php } else{ ?> <form method="POST" action="#"> <label> <span class="style10">Enter the Number of Question</span> <input name="question" type="text" class="style10" size="2" maxlength="2"> </label> <input name="submit" type="submit" class="style10" value="Submit"> </form> <?php }?> result.php <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("uni",$con) or die('Could not connect: ' . mysql_error()); foreach ($_POST['cid'] as $c) {$cid [] = $c;} foreach($_POST['qno'] as $q){$qno[] = $q;} foreach($_POST['marks'] as $m){$marks[] = $m;} $ct = 0; for($i=0;$i<count($qno);$i++) { $sql="INSERT INTO examquesion (CourseID,QuesionNo,MarksAllocated) VALUES('$cid[$i]','$qno[$i]','$marks[$i]')"; mysql_query($sql,$con) or die('Error: ' . mysql_error()); $ct++; } echo "$ct record(s) added"; mysql_close($con) ?> Hey guys, I am a webmaster for my church and I am fairly new to PHP. What am trying to is when a visitor goes to our radio ministry page and clicks a button which the message number is displayed in the read only textbox, it will go to my request CD page and auto populate the message number in that text field form the readonly text field from the previous page. I will show my code for both pages for you to review. This is the Radio page (where I want to take the message number value from) Code: [Select] <!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="Living Word Community Church radio ministry" /> <meta name="keywords" content="reformed radio fort worth, reformed radio dallas, biblical radio fort worth, biblical radio dfw" /> <title>In Light of Scripture-Radio Ministry</title> <link href="_css/Main.css" rel="stylesheet" type="text/css" /> <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script> <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> <div class="header"><a href="index.php"><img src="_images/LWCCWeb.jpg" alt="Insert Logo Here" name="Insert_logo" width="960" height="200" id="Insert_logo" style="background: #D8BF78; display:block;" /></a> <?php include("_includes/header.php"); ?> <div class="sidebar1"> <p></p> <table width="150" border="0" cellpadding="10" align="left"> <tr> <td><a href="directions.php"><img src="_images/ChurchBox.png" width="150" height="125" alt="Directions" /></a></td> </tr> <tr> <td><img src="_images/Service Times.png" width="150" height="778" alt="Service Times" /></td> </tr> </table> <!-- end .sidebar1 --></div> <div class="content"> <div id="radio"></div> <table width="600" border="0" cellpadding="10"> <tr> <td><img src="_images/ILOS.png" width="600" height="111" alt="In Light of Scripture" /></td> </tr> <tr> <td style=" padding-top:25px"><p><font size="5"><b>In Light of Scripture</b> has been locally broadcast for more than 25 years.<br /> This Sunday morning radio program features the expositional teaching of Pastor Stan McGehee Jr. </font><p/></td> </tr> </table> <div id="mediagraph"><a href="http://kdkr.org" target="_blank"><img src="_images/kdkr.jpg" width="300" height="200" alt="Braodcast on KDKR 91.3 Sunday Mornings at 7:30" /></a></div> <br /><br /> <font size="2"><p align="center"><b>The sermon featured this week on "In Light of Scipture" is</b></p></font> <font size="2"><p align="center" style="color:#711726"><b><i>Peace Despite Tribulation</i></b></p></font> <div id="messagenumber" align="center"> <form action="" method="get" name="messagenumber"> <input name="" type="text" value="JR-843" size="6" readonly="readonly" /> <input name="GetMessage" type="button" value="Get Message" /> </form> </div> <!-- end .content --></div></div> <div class="sidebar2"> <table width="150" border="0" cellpadding="16" align="left"> <tr> <td><a href="reformation.php"><img src="_images/MenuBox1.png" width="150" height="125" alt="What Do We Mean by Reformed?" /></a></td> </tr> <tr> <td><a href="ServiceTimesAndCal.php"><img src="_images/MenuBox2.png" width="150" height="125" alt="Worship Service Schedule and Calendar" /></a></td> </tr> <tr> <td><a href="radio.php"><img src="_images/MenuBox3.png" width="150" height="125" alt="In Light of Scripture Radio Ministry" /></a></td> </tr> <tr> <td><a href="cable.php"><img src="_images/MenuBox4.png" width="150" height="125" alt="Living Word Today Cable Program" /></a></td> </tr> <tr> <td><a href="Sermons.php"><img src="_images/MenuBox5.png" width="150" height="125" alt="Listen to Sermons Online" /></a></td> </tr> <tr> <td><a href="http://www.lwcchurch.org/blog/" target="_blank"><img src="_images/MenuBox6.png" width= "150" height="125" alt="Read our reformed blog" /></a></td> </tr> </table> <!-- end .sidebar2 --></div> <?php include("_includes/footer.php"); ?> <!-- end .container --></div> <script type="text/javascript"> var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"}); var MenuBar2 = new Spry.Widget.MenuBar("MenuBar2", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"}); </script> </body> </html> This is for the CD request form. I want it to populate the Message# text field Code: [Select] <!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="Order Living Word Community Church sermons and teachings on CD" /> <meta name="keywords" content="Stan McGehee cd, Reformed teachings on cd, Biblical teachings on cd, LWCC cds" /> <title>Order CD's Online</title> <link href="_css/Main.css" rel="stylesheet" type="text/css" /> <link href="js/jquery.datepick.css" rel="stylesheet" type="text/css" /> <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="jquery/jquery-1.5.js"></script> <script type="text/javascript" src="js/jquery.datepick.js"></script> <script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationRadio.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(function() { $('#popupDatepicker').datepick(); $('#inlineDatepicker').datepick({onSelect: showDate}); }); function showDate(date) { } </script> <link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" /> <link href="SpryAssets/SpryValidationRadio.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> <div class="header"><a href="index.php"><img src="_images/LWCCWeb2.png" alt="Insert Logo Here" name="Insert_logo" width="960" height="200" id="Insert_logo" style="background: #D8BF78; display:block;" /></a> <?php include("_includes/header.php"); ?> <div class="sidebar1"> <p></p> <table width="150" border="0" cellpadding="10" align="left"> <tr> <td><a href="directions.php"><img src="_images/ChurchBox.png" width="150" height="125" alt="Directions" /></a></td> </tr> <tr> <td><img src="_images/Service Times.png" width="150" height="890" alt="Service Times" /></td> </tr> </table> <!-- end .sidebar1 --></div> <div class="content"> <h2 style="padding-left:50px"> Order messages on CD from LWCC</h2> <div id"form"> <form action="FormToEmail2.php" method="post"> <table width="550" border="0" cellpadding="10"> <tr> <td><table width="550" border="0" cellpadding="10"> <tr> <td width="190">First Name:</td> <td width="314"><span id="spryfirstname"> <input name="firstname" type="text" id="firstname" maxlength="20" /> <span class="textfieldMaxCharsMsg">Too many letters</span><span class="textfieldRequiredMsg">Enter first name </span></span></td> </tr> <tr> <td>Last Name:</td> <td><span id="sprylastname"> <input name="lastname" type="text" id="lastname" maxlength="20" /> <span class="textfieldRequiredMsg">Enter last name</span><span class="textfieldMaxCharsMsg">Too many letters</span></span></td> </tr> <tr> <td>Email<font size="2"> (So we can confirm if needed)</font>:</td> <td><span id="spryemail"> <input name="email" type="text" id="email" maxlength="50" /> <span class="textfieldRequiredMsg">Enter Email</span><span class="textfieldInvalidFormatMsg">Must be Email.</span><span class="textfieldMaxCharsMsg">Email too long</span></span></td> </tr> <tr> <td>Street:</td> <td><span id="sprystreet"><span id="sprystreet"> <input name="street" type="text" id="street" maxlength="50" /> <span class="textfieldRequiredMsg">Enter Street Address</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></td> </tr> <tr> <td>City:</td> <td><span id="sprycity"><span id="sprytextfield5"> <input name="City" type="text" id="city" maxlength="50" /> <span class="textfieldRequiredMsg">Enter your city</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span><span class="textfieldRequiredMsg">Enter Email</span><span class="textfieldInvalidFormatMsg">Must be Email.</span><span class="textfieldMaxCharsMsg">Email too lon</span></span></td> </tr> <tr> <td>Apartment number:</td> <td><span id="aptnum"> <input name="Apt number" type="text" id="aptnum" maxlength="6" width="80px" /> <span class="textfieldRequiredMsg">Enter Email</span><span class="textfieldInvalidFormatMsg">Must be Email.</span><span class="textfieldMaxCharsMsg">Email too long</span></span></td> </tr> <tr> <td>State:</td> <td><span id="spryselect1"> <select name="statelist"> <option value="null"></option> <option value="Alabama">AL</option> <option value="Alaska">AK</option> <option value="Arkansas">AR</option> <option value="Arizona">AZ</option> <option value="California">CA</option> <option value="Colorado">CO</option> <option value="Connecticut">CT</option> <option value="Deleware">DE</option> <option value="District of Columbia">DC</option> <option value="Florida">FL</option> <option value="Georgia">GA</option> <option value="Hawaii">HI</option> <option value="Idaho">ID</option> <option value="Iowa">IA</option> <option value="Illinois">IL</option> <option value="Indiana">IN</option> <option value="Kansas">KS</option> <option value="Kentucky">KY</option> <option value="Louisiana">LA</option> <option value="Massachusetts">MA</option> <option value="Maryland">MD</option> <option value="Maine">ME</option> <option value="Michigan">MI</option> <option value="Minnesota">MN</option> <option value="Missouri">MO</option> <option value="Mississippi">MS</option> <option value="Montana">MT</option> <option value="Nebraska">NE</option> <option value="New Hampshire">NH</option> <option value="New Jersey">NJ</option> <option value="New Mexico">NM</option> <option value="Nevada">NV</option> <option value="New York">NY</option> <option value="North Carolina">NC</option> <option value="North Dakota">ND</option> <option value="Ohio">OH</option> <option value="Oklahoma">OK</option> <option value="Oregon">OR</option> <option value="Pennslyvania">PA</option> <option value="Rhode Island">RI</option> <option value="South Carolina">SC</option> <option value="Tennessee">TN</option> <option value="Texas">TX</option> <option value="Utah">UT</option> <option value="Vermont">VT</option> <option value="Virginia">VA</option> <option value="Washington">WA</option> <option value="Wisconsin">WI</option> <option value="West Virginia">WV</option> <option value="Wyoming">WY</option> </select> <span class="selectRequiredMsg">Please select state</span></span></td> </tr> <tr> <td>Zip Code:</td> <td><span id="spryzip"><span id="sprytextfield6"> <input name="Zip Code" type="text" id="zip" maxlength="50" /> <span class="textfieldRequiredMsg">Enter Zip Code</span><span class="textfieldInvalidFormatMsg">Zip Code is 5 numbers.</span></span><span class="textfieldRequiredMsg">Enter Email</span><span class="textfieldInvalidFormatMsg">Must be Email.</span><span class="textfieldMaxCharsMsg">Email too lo</span></span></td> </tr> <tr> <td>Which Pastor or Teacher?</td> <td> <div id="spryradio1"> <table width="250"> <tr> <td><label> <input type="radio" name="Speaker" value="Pastor Stan McGehee" id="radiogroup_4" /> Pastor Stan McGehee Sr</label></td> </tr> <tr> <td><label> <input type="radio" name="Speaker" value="Pastor Stan McGehee Jr" id="radiogroup_5" /> Pastor Stan McGehee Jr</label></td> </tr> <tr> <td><label> <input type="radio" name="Speaker" value="Pastor Jack McFarland" id="radiogroup_6" /> Pastor Jack McFarland</label></td> </tr> <tr> <td><label> <input type="radio" name="Speaker" value="Steve Bader" id="radiogroup_7" /> Steve Bader</label></td> </tr> </table> <span class="radioRequiredMsg">Please select speaker</span></div></td> </tr> <tr> <td>Where did you hear message?</td> <td> <div id="spryradio2"> <table width="200"> <tr> <td><label> <input type="radio" name="How did you hear?" value="At LWCC" id="RadioGroup1_0" /> At our church</label></td> </tr> <tr> <td><label> <input type="radio" name="How did you hear?" value="On the Radio" id="RadioGroup1_1" /> On the Radio</label></td> </tr> <tr> <td><label> <input type="radio" name="How did you hear?" value="On Cable" id="RadioGroup1_2" /> On Cable</label></td> </tr> </table> <span class="radioRequiredMsg">Please make a selection</span></div></td> </tr> <tr> <td>What service?</td> <td><div id="spryradio3"> <table width="248"> <tr> <td width="240"><label> <input type="radio" name="When did you hear message?" value="Sunday AM" id="When did you hear message?_0" /> Sunday AM</label></td> </tr> <tr> <td><label> <input type="radio" name="When did you hear message?" value="Sunday PM" id="When did you hear message?_1" /> Sunday PM</label></td> </tr> <tr> <td><label> <input type="radio" name="When did you hear message?" value="Wednesday PM" id="When did you hear message?_2" /> Wednesday PM</label></td> </tr> <tr> <td><label> <input type="radio" name="When did you hear message?" value="Adult Sunday School" id="When did you hear message?_3" /> Adult Sunday School</label></td> </tr> </table> <span class="radioRequiredMsg">Please make a selection.</span></div></td> </tr> <tr> <td>Message Number <font size="2">(If known)</font>: </td> <td><input name="Message#" type="text" id="messagenumber" maxlength="50" /></td> </tr> </table> </td> </tr> <tr> <td><table width="550" border="0" cellpadding="10"> <h3 style="padding-left:135px">Please pick date of message</h3> <div id="selectdate" align="center"><input id="inlineDatepicker" name="When Did You Hear?" type="text" /></div> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-4715900-1"); pageTracker._initData(); pageTracker._trackPageview(); </script></table></td> <tr> <td style="padding-left:250px"><input name="submit" value="Submit" type="submit" /> <input name="clearBtn" type="reset" /></td> </tr> </table> </td> </tr> </table> </form></div> <!-- end .content --></div></div> <div class="sidebar2"> <table width="150" border="0" cellpadding="25" align="left"> <tr> <td><a href="reformation.php"><img src="_images/MenuBox1.png" width="150" height="125" alt="What Do We Mean by Reformed?" /></a></td> </tr> <tr> <td><a href="ServiceTimesAndCal.php"><img src="_images/MenuBox2.png" width="150" height="125" alt="Worship Service Schedule and Calendar" /></a></td> </tr> <tr> <td><a href="radio.php"><img src="_images/MenuBox3.png" width="150" height="125" alt="In Light of Scripture Radio Ministry" /></a></td> </tr> <tr> <td><a href="cable.php"><img src="_images/MenuBox4.png" width="150" height="125" alt="Living Word Today Cable Program" /></a></td> </tr> <tr> <td><a href="Sermons.php"><img src="_images/MenuBox5.png" width="150" height="125" alt="Listen to Sermons Online" /></a></td> </tr> <tr> <td><a href="http://lwcchurch.blogspot.com" target="_blank"><img src="_images/MenuBox6.png" width="150" height="125" alt="Read our reformed blog" /></a></td> </tr> </table> <!-- end .sidebar2 --></div> <?php include("_includes/footer.php"); ?> <!-- end .container --></div> <script type="text/javascript"> var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"}); var MenuBar2 = new Spry.Widget.MenuBar("MenuBar2", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"}); var sprytextfield1 = new Spry.Widget.ValidationTextField("spryfirstname", "none", {validateOn:["blur"], maxChars:20}); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprylastname", "none", {maxChars:20, validateOn:["blur"]}); var sprytextfield3 = new Spry.Widget.ValidationTextField("spryemail", "email", {maxChars:50, validateOn:["blur"]}); var sprytextfield4 = new Spry.Widget.ValidationTextField("sprystreet", "none", {validateOn:["blur"], maxChars:50}); var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "none", {maxChars:50, validateOn:["blur"]}); var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {validateOn:["blur"]}); var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6", "zip_code", {validateOn:["blur"]}); var spryradio1 = new Spry.Widget.ValidationRadio("spryradio1"); var spryradio2 = new Spry.Widget.ValidationRadio("spryradio2"); var sprytextfield7 = new Spry.Widget.ValidationTextField("sprymessagenumber", "none", {isRequired:false}); var spryradio3 = new Spry.Widget.ValidationRadio("spryradio3"); </script> </body> </html> Is it possible to have a text field on my site, and the text that is entered into it, be given to another site that I auto redirect the user to? If it is possible, could somebody give me the exact code (I'm not a programmer) I would need to use? Thanks for any help on this. Hi i have this edit form that allows user to mofy data but the problems on the text box is that it deletes the rest of the data after the space from the first word i tried to increase the size of the varChars on mysql but did no work why it happens how can i stop from happening?? this the form input <input type="text" name="name" id="name" class='text_box' value="<?php echo $_GET['name'];?>"/> I have a MySQL table called "products": Quote +------+-------+-------+-------+ | id | sizes | sizem | sizel | +------+-------+-------+-------+ | 1 | 2 | 0 | 1 | | 2 | 3 | 1 | 0 | +------+-------+-------+-------+ What I am wanting to know is if I can make PHP print a value from it, but only if it is not a zero.. something like: $sizeL = (table(products)id1.sizel); if (table(products)id1.sizel == "0") {echo "";} else {echo "$sizeL";} Yeah I know the above code is far from beeing valid, but is the best I could come up with. heh I want half of the results to to show up with a hyperlink (if I've added the link as a field in my CSV file) and half of the results to show up with no hyperlink. The link URL's are located in field 8 of a database : [8] as seen below. Could anyone help me to figure out how to add an "if" statement perhaps? Something like "if 8 true" then display "<a href"? I did not write this php code I am only modifying it. The csv file is very very straightforward, but this PHP is beyond me. Would appreciate the help! <p><a href="<?=htmlspecialchars($r[8])?>"><?=htmlspecialchars($r[1])?></a><br /> <?=htmlspecialchars($r[2])?><br /> <?=htmlspecialchars($r[3])?><br /> <?=htmlspecialchars($r[4])?><br /> <?=htmlspecialchars($r[5])?><br /> <a href="mailto:<?=htmlspecialchars($r[7])?>"><?=htmlspecialchars($r[7])?></a> </p> Basically I have a date of birth field (date) now how would I go about splitting that date field into 3 variables $year $month and $day? Any small push forward is much appreciated, I have searched but it seems that I might not be putting it into words correctly. Actually while writing this I suppose I might of thought of the solution Code: [Select] <?php $year = date('Y', strtotime($row['dob'])); $month = date('m', strtotime($row['dob'])); $day = date('d', strtotime($row['dob'])); ?> Would that be how you would go about it? Okay, so I'm trying to run a query to pull the information from a specific item that they click on in order to edit it. When I run an echo $query, though, it shows the field names rather than the information from the table. How can I make it so that it pulls the information rather than the field names? Here's what I have... <?php include("lib.php"); define("PAGENAME", "Edit Equipment"); if ($player->access < 100) $msg1 = "<font color=\"red\">"; //name error? $error = 0; $query = $db->execute("SELECT * FROM items WHERE id=?", array($_POST['id'])); echo "$id"; $result = mysql_query($query); echo "$query"; $data = mysql_fetch_assoc($result); $msg1 .= "</font>"; //name error? ?> Thanks!! I have a table for collecting airline satisfaction survey results(see attached image). I run a query to select the staff field there are 25 rows in this column I run a switch case block to filter out a result set that includes the responses 'poor', 'fair', 'good', and 'excellent' the result set should contain 20 elements Code: [Select] function score_staff() { $staff_count = 0; $result_set_cnt = 0; $query = "SELECT staff FROM flight_survey"; $result = mysql_query($query); while ($get_info = mysql_fetch_row($result)){ foreach ($get_info as $field){ switch($field) { case "poor": $staff_count++; $result_set_cnt++; $exit; case "fair": $staff_count+=2; $result_set_cnt++; $exit; case "good": $staff_count+=3; $result_set_cnt++; $exit; case "excellent": $staff_count+=4; $result_set_cnt++; $exit; drfault: // do nothing } } } echo $staff_count."<br>"; echo $result_set_cnt."<br>"; } For each match I add 1 to the result set so with 20 matches $result_set_cnt should be 20 and not 53 as shown at the bottom of the attached image. The array $get_info bewilders me and I can't seem to access it's elements without putting it in a while loop. Anyway I'm pretty new to php and have a lot to learn. If anyone can explain how I could change the code so that the result set would contain 20 I think I'll be alright. thanks For instance if i set the following 2x variables; "$varOne = $_GET[first_name]" "$varTwo = $_GET[last_name]" "$varThree = $_GET[userid]" how do i insert them both together into a DB field for example: $full = $varOne,$varTwo,$varThree (without the , ) this would then be echo as : joebloggs66985 i have the INSERT in there atm but i wanted to insert first name and last name together with there userid to generate a sort of username possibility. sorry if i didnt explain correcly I'm building a php program that registers users onto a website. With the help of people from this thread http://www.phpfreaks.com/forums/index.php?topic=332260.15 I was able to accomplish the goal and now the signup works with conditions that check for a valid email, and if the password is strong enough. T he program correctly displays the the problem when a user does NOT enter a valid email, or a strong enough password, but the user has to re-enter the email and password everytime. I want to make it so that the fields remained populated with what the user entered previously, so he or she does not have to re-enter his or her email/password. Here is the code (its really ghetto) Code: [Select] <?php function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } define('DB_NAME', 'catch'); define('DB_USER', 'username'); define('DB_PASS', 'password'); define('DB_HOST', 'page.sqlserver.com'); // contact to database $connect = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Error , check your server connection.'); mysql_select_db(DB_NAME); //Get data in local variable $v_name=$_POST['name']; $v_email=$_POST['email']; $v_msg=$_POST['msg']; if ( check_email_address($_POST['name']) == false) { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> You must enter a valid email. <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if( $v_name == "" || $v_msg == "" ) // if name is empty or if pass is empty { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> You must enter an email and password. <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if( strcspn( $_REQUEST['msg'], '0123456789' ) == strlen( $_REQUEST['msg'] ) ) // the above statement says if pass does not contain a number { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> <div style="color:red;">Your password must contain a number.</div> <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if( strlen($_POST['msg']) < 8 ) // the above statement says if pass is not 8 characters long { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> <div style="color:red;">Your password must be at least 8 characters long.</div> <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if ( $_POST['msg'] == strtolower($_POST['msg']) ) // the above statement says if pass is all lowercase { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> <div style="color:red;">Your password must have at least one capital letter.</div> <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } if ( preg_replace("/[^a-zA-Z0-9\s]/", "", $_POST['msg']) == $_POST['msg'] ) // the above statement says if pass contains no special characters { $query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } echo <<<EOD <head> <link rel="stylesheet" type="text/css" href="http://hedgezoo.com/signup.css"> </head> <h2>Free Registration</h2> <form action="contact_insert2.php" method="POST" id="insert"> <table> <tr> <td>Email</td> <td ><input type="text" size="40" name="name"></td> </tr> <tr> <td>Password</td> <td><input type="password" size="40" name="msg" ></td> </tr> <tr> <td colspan=2 id="sub"> <div style="color:red;">Your password must have at least one special character.</div> <br /> <input type="submit" name="submit" value="submit"> </td> </tr> </Table> </form> EOD; } else echo <<<EOD <B>GO FUCK YOURSELF</B> EOD; ?> Hello, I have a field in which when a user types something into it, it saves it into a table in my SQL. But is it possible to remove a particular phrase from the field if the user enters it. Example: I have a text field that says 'please enter your website domain here'. The user then enters 'www.domain.com'. Is it possible for PHP to remove the 'www.' and only save the 'domain.com' to my SQL (bearing in mind that not all users may enter www.) Here is the code for the text field: Code: [Select] <input name="website_name" type="text" class="text-box" id="website_name" value="<?php echo $website_name; ?>" size="24" /> Here is the code for the _POST: if(isset($_POST['send'])) { $database->updateUserField($session->username, "website_name", $_POST['website_name']); } (the code so far all works fine - I just want to add an extra 'variable', if you will, to the code) Thanks for your help!! Hi all, I am relatively new to coding but wondered if someone can helpe me with this. I currently have a PHP file which outputs text that has been entered into a text box and saved. The original output code was this: if ( $this->theme->conf->item_description AND $this->doc->data->dmdescription ) : <?php echo $this->doc->data->dmdescription;?> but I want the text that shows to be truncated to say, 100 characters plus '...' so I came up with the following... <?php $someText = ($this->doc->data->dmdescription);?> <?php echo(substr($someText, 0,100)).'...'; ?> However it shows nothing. I guess $someText is bing linked to dmdescription rather than the text within dmdescription? Any ideas greatly appreciated! bplumb Does anyone have suggestions on how the following can be accomplished? Objective: I need a method to grab the {$email} variable from from via $_GET and populate (display) that variable string in the textbox of the form. Example: http://domain.com?email=john.smith@abc.com Code: [Select] <form action='index.php' method='post' name='emailForm' id="emailForm"> <div><input type='text' name='email' id="emailBox" size="40" value='<?php echo $_POST[email]; ?>' /></div> <div><input type='submit' name='frm2' class="button2" value='submit'/> Right now, the email (captured string) variable will show once the form is submitted (based on the "POST" function but i want to be able to capture and immediately insert the email address - if provided in the top URL on initial load. Is there a way to accomplish this with PHP or do I need JavaScript? Merry xmas and happy new in advance to you all. I have a web form where user submit an ad. Everything is working just fine. However there is a field name brief. The brief field is where user add info about their ad. Now people are including web url, phone numbers and email address in this field which make the ad look like spam. In the code there is already a function that check if they have entered their email address in the email field. I want to add a function to the check field to include the brief field. The function should either automatically delete any phone number/email addr/web url or replace with with my website name if detected in the brief field. Your help will be highly appreciated. Code: [Select] <?php function check_fields() { global $db_entry, $visible_val, $cat_fields, $email, $HTTP_POST_VARS, $photos_count, $phptomaxsize, $userfile, $prviewphotomax, $incl_prevphoto, $incl_mtmdfile, $mtmdfile_maxs, $userfile_name, $select_text, $msg2; if(!get_magic_quotes_gpc()) { foreach ($HTTP_POST_VARS as $key5 => $value ) { $HTTP_POST_VARS[$key5]=addslashes($HTTP_POST_VARS[$key5]); } } foreach ( $cat_fields as $key => $value ) { $HTTP_POST_VARS[$key]=ereg_replace('<', '&#060;', $HTTP_POST_VARS[$key]); $HTTP_POST_VARS[$key]=ereg_replace('>', '&#062;', $HTTP_POST_VARS[$key]); if ($cat_fields[$key][2]=="minmax") { $HTTP_POST_VARS[$key]=ereg_replace(',', '', $HTTP_POST_VARS[$key]); $HTTP_POST_VARS[$key]=preg_replace ('/[A-Za-z]|\$|,|\?|\+/', "", $HTTP_POST_VARS[$key]); } if ($cat_fields[$key][4]=="date") { $key_d=$key."_dd"; $key_m=$key."_mm"; $key_y=$key."_yy"; $HTTP_POST_VARS[$key]=$HTTP_POST_VARS[$key_y]."-".$HTTP_POST_VARS[$key_m]."-".$HTTP_POST_VARS[$key_d]; if (($HTTP_POST_VARS[$key_m] > 12) or ($HTTP_POST_VARS[$key_m] < 1) or ($HTTP_POST_VARS[$key_d] > 31) or ($HTTP_POST_VARS[$key_d] < 1) or ($HTTP_POST_VARS[$key_y] < 1)) { $message=" <center> <font class='msgf2' > ".$msg2['incorr_date_f']." ".$cat_fields[$key][0]." </font> </center> "; output_mssg_ex($message); return; } } if ($cat_fields[$key][4]=="checkbox") { $aa5=split('<option>',$cat_fields[$key][7]); $i_aa5=0; foreach ($aa5 as $value1) { $i_aa5++; $namechbx=$key.$i_aa5; if ($HTTP_POST_VARS[$namechbx]!="") {$HTTP_POST_VARS[$key]=$HTTP_POST_VARS[$key].$HTTP_POST_VARS[$namechbx]."; ";} } } $str_length1=strlen($HTTP_POST_VARS[$key]); $aa4=split(':',$cat_fields[$key][3]); $fmaxsize=$aa4[1]; if ($aa4[2]!="") $fmaxsize=$aa4[2]; $fmaxsize=2*$fmaxsize; if ( $str_length1 > $fmaxsize) { $message=" <center> <font class='msgf2' > ".$msg2['Ad_info_in_field']." <font class='msgf1' >".$cat_fields[$key][0]." </font> ".$msg2['is_too_large_inf']."</font> </center> "; output_mssg_ex($message); return; } if ($HTTP_POST_VARS[$key]==$select_text) {$HTTP_POST_VARS[$key]="";} if ($cat_fields[$key][5]=='1') { if (( $HTTP_POST_VARS[$key]=="") or ( $HTTP_POST_VARS[$key]=="http://")) { $message=" <center> <font class='msgf2' > ".$msg2['Ad_field_c']." <font class='msgf1' > ".$cat_fields[$key][0]." </font> ".$msg2['was_mising_on_form']."</font> </center> "; output_mssg_ex($message); return; } } } if ($cat_fields['email'][5]=='1'){ $HTTP_POST_VARS['email']=check_email($HTTP_POST_VARS['email']); } for ($i=1; $i<=$photos_count; $i++) { $i1=$i-1; if (file_exists($userfile[$i1])){ if (filesize($userfile[$i1]) > $phptomaxsize) { $phptomaxsize1=$phptomaxsize/1000; $message=" <center> <font class='msgf2' > ".$msg2['Your_photo_n']." $i ( ".$userfile_name[$i1]." ) ".$msg2['is_too_large_ph']." < $phptomaxsize1 ".$msg2['Kbyte_v'].". </font></font> </center> "; output_mssg_ex($message); return; } } } if ($incl_prevphoto=="yes") { $i1++; if (file_exists($userfile[$i1])){ if (filesize($userfile[$i1]) > $prviewphotomax) { $prviewphotomax1=$prviewphotomax/1000; $message=" <center> <font class='msgf2' > ".$msg2['Your_preview_photo_d']." ( ".$userfile_name[$i1]." ) ".$msg2['is_too_large_prph']." < $prviewphotomax1 ".$msg2['Kbyte_v'].". </font></font> </center> "; output_mssg_ex($message); return; } } } if ($incl_mtmdfile=="yes") { $i1++; if (file_exists($userfile[$i1])){ if (filesize($userfile[$i1]) > $mtmdfile_maxs) { $mtmdfile_maxs1=$mtmdfile_maxs/1000; $message=" <center> <font class='msgf2' > ".$msg2['Your_multimedia_file']." ".$userfile_name[$i1]." ".$msg2['is_too_large_mmf']." < $mtmdfile_maxs1 ".$msg2['Kbyte_v'].". </font></font> </center> "; output_mssg_ex($message); return; } } } } function checknusrads() { global $cat_fields, $table_ads, $ct, $page, $adsonpage, $html_header, $html_footer, $usrads_chcktime, $usrads_max, $categories,$ch_nmusr, $REMOTE_ADDR, $msg2, $msg, $templ, $indx_url; $timech1=time() - $usrads_chcktime*86400; $sql_query="select count(idnum) from $table_ads where ipaddr1='$REMOTE_ADDR' and time > $timech1"; $sql_res=mysql_query("$sql_query"); $row=mysql_fetch_row($sql_res); $count=$row[0]; if ($count >= $usrads_max) { $message=" <font class='msgf2'> <center> ".$msg2['exceeded_max_n_ads']." ($usrads_max) ".$msg2['allowed_per_time_p']." ($usrads_chcktime ".$msg2['days_v']." <p> <font class='stfnt'> <a href='{$indx_url}md=browse&ipaddr1=$REMOTE_ADDR&visunvis=1'>".$msg2['Click_here_v']." </a> ".$msg2['to_see_your_ads']." </font> </center> </font> "; $thtml= " <center><table width='400'><tr><td> <font class='stfntb'> <b><a href='$indx_url'>".$msg['top'].":</a></b></font> <font class='stfntb'> <b> <a href='{$indx_url}ct=$ct'>".$categories[$ct][0]." </b></a> </font> <hr size='1'><p> $message <p><hr size='1'> </tr></td></table> </center> "; include($templ['msg']); return; } } function check_duplication() { global $pradsdupl, $HTTP_POST_VARS, $table_ads, $msg2, $ct, $indx_url; if ($pradsdupl=='yes'){ $email_d=$HTTP_POST_VARS['email']; $title_d=$HTTP_POST_VARS['title']; $dupl_k="0"; $time1=time() - 1000; $sql_query="select idnum from $table_ads where title='$title_d' and email='$email_d' and catname='$ct' and (time > $time1)"; $sql_res=mysql_query("$sql_query"); while ($row = mysql_fetch_array ($sql_res)) { $dupl_id=$row['idnum']; $dupl_k="1"; } if ($dupl_k=="1"){ global $moderating; $title_d=stripslashes($title_d); if ($moderating!="yes"){ $ttlad1="<a href='{$indx_url}md=details&ct=$ct&id=$dupl_id'>$title_d (ID# $dupl_id)</a>"; } else {$ttlad1="<font color='#000077'>$title_d (ID# $dupl_id)</font>";} $message=" <center> <font FACE='ARIAL, HELVETICA' COLOR='#880000' > <b> ".$msg2['tried_duplicate_ad']." <br> $ttlad1 </font></b></font> </center> "; output_mssg_ex($message); return; } } } function submit_ad() { global $db_entry, $visible_val, $cat_fields, $email, $HTTP_POST_VARS, $ch_nmusr, $photo_url, $photo_path, $id_count, $userfile, $userfile_name, $visible_val, $html_header, $html_footer, $msg, $msg2, $paymgtw, $photos_url, $photos_path, $photos_count, $moderating, $ad_idnum, $sndadmnotif,$use_spmg, $templ; global $actadoptv; if($actadoptv=="yes"){$moderating="yes"; include_once("actlink.php");} global $usevrfcode; if ($usevrfcode=="yes"){include_once("vrfuncs.php"); if(!ch_vrcode()){return;}} if($paymgtw=="yes"){include("ecmc.php"); check_pmsubmit();} if ($ch_nmusr=="yes"){checknusrads();} check_fields(); ?> Many thanks again i have a form that has a price field, but if anything other than a decimal (0.00) a zero is entered into the database. There is the problem of people trying to add a dollar sign before their amount. What is the best way to validate a price amount to be entered into the database. The column in the database type is decimal(6,2). Any suggestions? I have text field in database, where I have let's say 5000 words. I want to split this text having 5000 words in pages, each one having 500 words. How can I realise this ? A practical example would be appreciate ! Thank you in advance. Ok so I basically have two textfields and a submit button. The first text field basically allows the user to input a duration of an event in the format of Hours:Minutes:Seconds such as: 02:30:00 is two and a half hours. The second textfield allows the user to put in an average time 'something' does something in the same format as above. So for example 00:20:00 is 20 minutes. 1st Textfield: Code: [Select] <input name="tmarrtextfield" type="text" class="textbox" id="tmarrtextfield" value="00:00:00"> 2nd Textfield: Code: [Select] <input name="tmatttextfield" type="text" class="textbox" id="tmatttextfield" value="00:00:00"> What I need is for when the form is submitted to the same page.. the code to...: 1. Convert the normal text info into actual time data. 2. Divide the duration by the average timing so for example: 02:30:00 (150 minutes) / 00:20:00 (20 minutes) = 7.5 (Would return a rounded down number or up, doesn't matter) then store the number as a variable that will be echoed later. Harry. Hi guys i have to create text field & enter data and store in the data base. here im able to create text field but couldn't insert the data. so could anyone please check this code for me. <body> <form method="POST" action="cell.php"> Enter the number of question <input type="text" name="question"> <input type="submit"> <?php $value=$_POST['question']; for($i=0;$i<$value;$i++) { echo "Question NO:"; echo '<input type="text" name="qno">'."\t"; echo "Enter Marks:"; echo '<input type="text" name="marks">'."\t"; echo "<br>"; } ?> </form> <form name="form1" method="post" action="cellresult.php"> <label> <input type="submit" name="Submit" value="Submit"> </label> </form> </body> cellresult.php <body> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $sql="INSERT INTO cell (QNO,MARKS) VALUES ('$_POST[qno]','$_POST[marks]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> </body> |