PHP - Inserting Data From Drop-down List & Text Field
Hi 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) ?> Similar TutorialsI have a search function in php where the text characters are matched to characters in a tables field--- works perfectly.... I need to make the input box have a droplist of words from database, this is also easy for me to do. the problem here is there is no definitive value! the options list always outputs a blank in the url--- its supposed to search a matching value and then output the matching value to url... Here is the droplist code: $output['RATESTITLE']='<input class="inputbox" type="text" size="24px" name="ratestitle" value="'.$sch->filter['ratestitle'].'" onfocus="if (this.value ==\''.$output['LANGUAGE_SEARCH_RATESTITLE'].'\') {this.value = \'\'}" />'; this outputs a input text box--- i want to have a droplist of options to populate this text box... If you must know this is the third day im at it... Hello all , here is another problem of my project. I need to create a textarea , drop down list and submit button . At first , I can type whatever I want in the textarea , but for certain part I can just choose the word I want from drop down list and click submit , then the word will appear in the textarea as my next word . But I have no idea how to make this works , is there any simple example for this function ? Thanks for any help provided . 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 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> hello, if i have an appostraphy in a text box while sumitting, it returns an error. any ideas? 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. This is kind of hard to explain, but I will try my best. I have a script that is attempting to display information in a MySQL database by month fields that are chosen by the user. For instance, they can choose for the start date to start in January, and pick the end date which in this example will be April. The script then puts the required field that match the specific dates into a column for each month. For the most part it outputs fine as: Jan: 15, Feb: 14, Mar: 9, Apr: 2. However, sometimes there is nothing in the database for certain months. This causes the script to display wrong so instead I get: Jan 3, Feb: , Mar: , Apr: . In the above example, the Jan: 3 might be wrong, because the field might have been for Mar instead. I need it to display like this when there is no fields in the database: Jan: 0, Feb: 0, Mar: 3, Apr: 0. How would I go about doing this? i have a with my script I made a basic messaging service for my website. I have a form with a textarea as an input variable. It inserts the textarea value to a database using a php script upon form submission. The SQL field is set as longtext so the user can insert a large text string. There's a few things i need to do to perfect it. I need to make it so the user can only insert text characters, so not to allow script manipulation; and I need to figure out why it's deleting my intro message when changing the `read` field from `unread` to `read`. The `messages` SQL table is separated into 6 fields: to, from, message, read, subject, and number. when the user reads a message, i have a php script that reads as follows: <?php include("include/session.php"); function curPageName() { return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } $pagename = curPageName(); $replaced2 = eregi_replace("message", "", $pagename); $number = eregi_replace(".php", "", $replaced2); mysql_select_db("******_starcraft") or die(mysql_error()) ; $query = " SELECT * FROM `messages` WHERE number='$number' "; $result = mysql_query($query); $info = mysql_fetch_array ( $result ); $to = $info['to']; $from = $info['from']; $subject = $info['subject']; $message = $info['message']; $read = $info['read']; mysql_query("DELETE FROM `messages` WHERE `number`='$number'") ; mysql_query("INSERT INTO `messages` VALUES ('$to', '$from', '$message', 'read', '$subject', '$number')") ; ?> Now, after trouble shooting, i found that the problem is occuring when it tries to insert the $message string into the third field of the `messages` table. I find this strange because when you send the message to this user using the "compose message" script, the input variable is inserted into the database table without a stitch. Is there something i'm missing? i feel like it's on the tip of my tounge... thanks in advance, -dan Can someone please help me figure out how to insert "image" from table users, that contains the .jpg data associated with "screen_name", into table friends "friendimg" Here are the tables: friends: id, member, friendwith, friendimg users: id, screen_name, image $_GET["id"] only contains "screen_name" and"image" is not included add.php Code: [Select] <?php if(isset($_GET["id"])) { echo "<br/><a href=\"member?add=".$_GET["id"]."\">Add ".$_GET["id"]." to your list of friends</a>"; } ?>member.php Code: [Select] <?php if(isset($_GET["add"])) { $username = $_SESSION["screen_name"]; $friend = $_GET["add"]; $query = "SELECT * FROM friends WHERE member='$username' AND friendwith='$friend'"; $result = mysql_query($query); $exist = mysql_num_rows($result); if($exist=='0') { $query = "INSERT INTO friends(member,friendwith) VALUES('$username','$friend')"; mysql_query($query); echo "<br/>You are now friends with $friend"; } else { echo "<br/>$friend is already in your list of friends!"; } } ?> This UPDATE script works:
$query = $pdo->prepare("UPDATE posts SET headline = ? WHERE id = ?"); $query->bindValue("1", $_POST['headline']); $query->bindValue("2", "2"); $query->execute();Though, this INSERT script does not work: $query = $pdo->prepare("INSERT INTO posts (headline, post) VALUES (?, ?)"); $query->bindValue("1", $_POST['headline']); $query->bindValue("2", $_POST['post']); $query->execute();Nothing gets added, when executing this script. The connection: <?php $dsn = "mysql:dbname=phpblog;host=localhost"; $user = "root"; $password = ""; try{ $pdo = new PDO($dsn, $user, $password); }catch(PDOException $e){ echo "Connection failed: " . $e->getMessage(); } ?>Any suggestions why the INSERT script is not working? Edited by glassfish, 25 November 2014 - 09:26 AM. Hello all Ok here is the problem... I want when a user inputs the requested data to the text fields , the script to insert those data in the prope table depending on the choise the user does by choosing one option from the drop down menu. Below is the php code (apparently not working) $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } $site_type = $_REQUEST['category_selection']; if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission") && ($site_type = "Web_Sites")) { $insertSQL = sprintf("INSERT INTO partner_sites (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['url_field'], "text"), GetSQLValueString($_POST['title_field'], "text"), GetSQLValueString($_POST['anchor_field'], "text"), GetSQLValueString($_POST['description_field'], "text"), GetSQLValueString($_POST['webmaster_nane_field'], "text"), GetSQLValueString($_POST['webmaster_email_field'], "text"), GetSQLValueString($_POST['category_selection'], "text")); mysql_select_db($database_content_conn, $content_conn); $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission") && ($site_type = "Blogs")) { $insertSQL = sprintf("INSERT INTO partner_blogs (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['url_field'], "text"), GetSQLValueString($_POST['title_field'], "text"), GetSQLValueString($_POST['anchor_field'], "text"), GetSQLValueString($_POST['description_field'], "text"), GetSQLValueString($_POST['webmaster_nane_field'], "text"), GetSQLValueString($_POST['webmaster_email_field'], "text"), GetSQLValueString($_POST['category_selection'], "text")); mysql_select_db($database_content_conn, $content_conn); $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission") && ($site_type = "Directories")) { $insertSQL = sprintf("INSERT INTO partner_directories (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['url_field'], "text"), GetSQLValueString($_POST['title_field'], "text"), GetSQLValueString($_POST['anchor_field'], "text"), GetSQLValueString($_POST['description_field'], "text"), GetSQLValueString($_POST['webmaster_nane_field'], "text"), GetSQLValueString($_POST['webmaster_email_field'], "text"), GetSQLValueString($_POST['category_selection'], "text")); mysql_select_db($database_content_conn, $content_conn); $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error()); } And the html form <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="link_submission" id="link_submission"> <table width="630" border="0" align="center" cellpadding="5" cellspacing="5"> <tr> <td width="76">URL:*</td> <td width="519"><label for="url_field"></label> <span id="sprytextfield1"> <label for="url_field"></label> <input name="url_field" type="text" id="url_field" size="50" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td> </tr> <tr> <td>Anchor Text:*</td> <td><label for="anchor_field"><span id="sprytextfield2"> <input type="text" name="anchor_field" id="anchor_field" /> <span class="textfieldRequiredMsg">A value is required.</span></span></label></td> </tr> <tr> <td>URL Title:*</td> <td><label for="title_field"><span id="sprytextfield3"> <input type="text" name="title_field" id="title_field" /> <span class="textfieldRequiredMsg">A value is required.</span></span></label></td> </tr> <tr> <td>Description:*</td> <td><span id="sprytextarea1"> <label for="description_field"></label> <textarea name="description_field" id="description_field" cols="45" rows="3"></textarea> <span id="countsprytextarea1"> </span><span class="textareaRequiredMsg">A value is required.</span><span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span></td> </tr> <tr> <td>Webmaster Name:*</td> <td><label for="textfield2"><span id="sprytextfield4"> <input type="text" name="webmaster_nane_field" id="webmaster_nane_field" /> <span class="textfieldRequiredMsg">A value is required.</span></span></label></td> </tr> <tr> <td>Webmaster E-mail:*</td> <td><label for="textfield3"><span id="sprytextfield5"> <input name="webmaster_email_field" type="text" id="webmaster_email_field" size="40" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></label></td> </tr> <tr> <td>Category:*</td> <td><span id="spryselect1"> <label for="category_selection"></label> <select name="category_selection" id="category_selection"> <option>Select An Option</option> <option value="Web_Sites">Web Sites</option> <option value="Blogs">Blogs</option> <option value="Directories">Directories</option> </select> <span class="selectRequiredMsg">Please select an item.</span></span></td> </tr> <tr> <td> </td> <td><label for="select"></label> <input type="submit" name="button" id="button" value="Url Submission" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="link_submission" /> </form> Im begging for your help..... hi guys Ive written this php to take in two variables from the http POST, the idea is that I can multiple devices submit temperature readings to the php script, the script then append the unix time stamp and then the the 3 variables - device id, temp and unix time are then stored in a mysql DB. I can get the variables to present on a php page for debugging but I cant get the variables to be stored in the mysql DB. See the code: Code: [Select] <?php $unixtime = time(); // get device variables $device_id=$_GET['device']; $device_temp=$_GET['temp']; /* //for testing purposes echo "unixtime: " . $unixtime . "<br />"; echo "device id: " . $device_id . "<br />"; echo "device_temp: " . $device_temp . "<br />"; */ // Make a MySQL Connection mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); //mysql query $query = "INSERT INTO temperature VALUES ('',$device_id,$temp,$unixtime)"; // Insert a row of information into the relevant device table mysql_query($query); or die(mysql_error()); mysql_close(); echo "Data Inserted!"; ?> I cant see where Im going wrong to correct this, but as nothing is displayed on the page i believe I am not forming the query correctly? - any ideas would be much appreciated. Thank you Mathew Hello All, First, I'm new to php and I have spent a lot of time searching forums and google for the answer to my question with no luck, so if it's a topic already covered, PLEASE reply with a link or point me in the right direction. OK, I have a form that let's users upload multiple images. The upload portion works fine. What I can't figure out how to do is put the image name of each file that gets uploaded all into the same table record. I also need each file name to be put into it's own column in the table. For example, file1, file2 and file3 will get dumped into the same record and into it's respective column (uploaded_image1, uploaded_image2, uploaded_image3). I've included the working upload code and the code that inserts some of the information into the database (just not the image names). Code: [Select] echo "<textarea name=challenge rows=15 cols=60> </textarea><br/><br/>" echo "<textarea name=insight rows=15 cols=60> </textarea><br/><br/>" for($i=1; $i<=$max_no_img; $i++){ echo "Image $i <input type=file name='image[]' ><br/>"; } echo "<input type=submit value=Submit>"; Code: [Select] // Connect to DB $host = 'xxx'; $user = 'xxx'; $pass = 'xxx'; $db = 'xxx'; mysql_connect($host,$user,$pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); // Post Variables $challenge = $_POST['challenge']; $insight = $_POST['insight']; $filename=serialize($_POST['filename']); // Upload Images while(list($key,$value) = each($_FILES[image][name])) { if(!empty($value)) { $filename = $value; $add = "upimage/$filename"; copy($_FILES[image][tmp_name][$key], $add); chmod("$add",0777); } } // Insert into database $query = "INSERT INTO table ( challenge, insight, uploaded_image1, uploaded_image2, uploaded_image3,)". "values ( '$challenge', '$insight', '$filename' '$filename2' '$filename3')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); I know just enough about php that the reason the above wont work, is because $filename2 and $filename3 haven't been given a value. Unfortunately, I have no idea how to separate that information in the array. If anyone can point me in the right direction I'd be forever grateful! Thanks, Gary Hey all I really need help with a project I am doing. I need to create a website with a registration form that checks if the user exists if not to add the user details to my local database MySQL. My webpage looks like it should, it connects with the database but when I enter a new user it does nothing when it should save the new user to the database! I am guessing my problem is within the if...else section. Please help my code is: Code: [Select] <?php include('connect.php'); //connection details to database in a connect.php page $name = ""; $surname = ""; $username = ""; $password = ""; $confirmp = ""; $errorMessage = ""; $num_rows = 0; //if form was submitted if ($_SERVER['REQUEST_METHOD'] == 'POST'){ //get values from fields $submit = $_POST['Submit']; $title = $_POST['title']; $name = $_POST['name']; $surname = $_POST['surname']; $username = $_POST['username']; $password = $_POST['password']; $confirmp = $_POST['confirmp']; //getting string lengths $nameLength = strlen($name); $surnameLength = strlen($surname); $usernameLength = strlen($username); $passwordLength = strlen($password); $confirmpLength = strlen($confirmp); //testing if strings are between certain numbers if ($nameLength > 1 && $nameLength <= 20) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Name must be between 2 and 20 characters" . "<br>"; } if ($surnameLength >= 2 && $surnameLength <= 50) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Surname must be between 2 and 50 characters" . "<br>"; } if ($usernameLength = 6) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Username must be 6 characters long" . "<br>"; } if ($passwordLength = 6) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Password must be 6 characters long" . "<br>"; } if ($confirmpLength = 6) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Password must be 6 characters long" . "<br>"; } if ($errorMessage == "") { $query = "SELECT * FROM user WHERE username = '$username' AND password = '$password'"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); //check to see if the $result is true if ($num_rows = 1){ $errorMessage = "Username already exists"; } else { if($password == $confirmp){ $query = "INSERT INTO user (title, name, surname, username, password) VALUES ('$title', '$name', '$surname', '$username', '$password')"; $result = mysql_query($query); session_start(); $_SESSION['login'] = "1"; header ("Location: login.php"); } else { $errorMessage = "Passwords do not match!"; } } } else { $errorMessage = "Error Registering"; } } else { $errorMessage = "Please enter your details"; } ?> <html> <head> <title>Mia's Beauty Products</title> </head> <body> <p><img src = "banner1.jpg" width = "975" height = "95" alt = "Mia's Beauty Product" /></p> <br> <p align= "center"><a href="register.php">Register</a> | <a href="login.php">Login</a> | <a href="insert.php">Insert</a> | <a href="list.php">List</a></p> <form method = "post" action = "register.php"> <table> <tr><td>Title:</td><td><select name = "title"> <option>Miss</option> <option>Mrs</option> <option>Mr</option> </select></td></tr> <tr><td>Name:</td><td><input name = "name" type = "text" value ="<?php print $name;?>"></td></tr> <tr><td>Surname:</td><td><input name = "surname" type = "text" value ="<?php print $surname;?>"></td></tr> <tr><td>Username:</td><td><input name = "username" type = "text" value ="<?php print $username;?>"></td></tr> <tr><td>Password:</td><td><input name = "password" type = "password" value ="<?php print $password;?>"></td></tr> <tr><td>Confirm Password:</td><td><input name = "confirmp" type = "password" value ="<?php print $confirmp;?>"></td></tr> <tr><td><input type = "submit" name = "Submit" value = "Submit"></td></tr> </table> </form> <p align= "center"><a href="code.txt">Code</a></p> <br> <?php print $errorMessage; ?> <p><img src = "banner2.jpg" width = "975" height = "95" alt = "Mia's Beauty Product" /></p> </body> </html> Thank you Amanda Stuck again on simple code. I am trying to insert some fields extracted from one table into another. I'm using code that worked elsewhere. The SQL statement flies, the script runs, the input array is printed back I get an echo back from the end of the script but nothing is added to the table. Even aded an echo print_r in the conditional and I know the data is getting to the execute command. The script follows with a sample of the input array. I have attached am image of the table I am trying to insert the data into. --Kenoli The script: <?php require '__classes/DB.php'; $sql = "SELECT name, table_id, image_name, description, medium FROM tbl_person_data "; $stmt = $pdo->query($sql); $array1 = $stmt->fetchall(PDO::FETCH_ASSOC); $stmt = $pdo->prepare("INSERT INTO Images (name, person_id, filename, description, medium) VALUES (?,?,?,?,?)"); //$pdo->beginTransaction(); foreach ($array1 as $row) { $stmt->execute($row); } echo "<pre>"; print_r ($row); echo "</pre>"; echo '<h4>Got to end of file</h4>'; ?> $array1: The input array [0] => Array ( [name] => Carol Lettko [table_id] => 21 [image_name] => Carol_Lettko-DSC_3022.jpg [description] => Baby Herons/Brickyard [medium] => photo ) [1] => Array ( [name] => [table_id] => 22 [image_name] => Carol_Lettko-DSC_0164.JPG [description] => Heron/Brickyard [medium] => photo ) [2] => Array ( [name] => [table_id] => 23 [image_name] => Carol_Lettko-IMG_5723.jpg [description] => Kayaker/Brickyard [medium] => photo )
I am at a loss why my query is not inserting values into db. Even if I do echo $query or var_dump($query) there is nothing printed at all. All values are being passed successfully just not being inserted. I am getting 'Could not connect' but I do not know why. All connections are established and as a test I took this code and ran it on it's own with dummy data and it inserted the data fine. I can only think it has something to do with the $response_array. Where am I going wrong. and would appreciate any help. Thanks Code: [Select] <?php require_once('Connections/sample.php'); ?> <?php session_start(); $new = 1; $activity = 'General Contact Enquiry'; $mobile = 'Submitted from mobile'; $name = mysql_real_escape_string($_POST['GC_name']); $department = mysql_real_escape_string($_POST['GC_department']); $message = mysql_real_escape_string($_POST['GC_message']); $email = mysql_real_escape_string($_POST['GC_email']); $company = mysql_real_escape_string($_POST['GC_company']); $position = mysql_real_escape_string($_POST['GC_position']); //response array with status code and message $response_array = array(); //validate the post form //check the name field if(empty($name)){ //set the response $response_array['status'] = 'error'; $response_array['message'] = 'Name cannot be blank'; //check the name field } elseif(empty($company)) { //set the response $response_array['status'] = 'error'; $response_array['message'] = 'You must enter a company name'; //check the position field }elseif(empty($position)) { //set the response $response_array['status'] = 'error'; $response_array['message'] = 'You must enter a position'; //check the email field } elseif(empty($email)) { //set the response $response_array['status'] = 'error'; $response_array['message'] = 'You must enter a valid email address'; //check the dept field }elseif($department=="Choose Department") { //set the response $response_array['status'] = 'error'; $response_array['message'] = 'You must select a department'; //check the message field }elseif(empty($message)) { //set the response $response_array['status'] = 'error'; $response_array['message'] = 'You must enter a message'; //check the dept field } else { //set the response $response_array['status'] = 'success'; $response_array['message'] = 'Your enquiry has been sent succesfully'; $flag=1; } //send the response back echo json_encode($response_array); if($flag == 1) { mysql_select_db($database_sample, $sample); $query = 'INSERT INTO feedback (company, department, name, email, position, feedback, date, new) VALUES (\''.$company.'\', \''.$department.'\', \''.$name.'\', \''.$email.'\', \''.$position.'\', \''.$message.'\', NOW() , \''.$new.'\')'; mysql_query($query) or die("Could not connect"); } ?> i want to insert only whats checked to db:) but everything get posted for now i came upwith a for loop but thats for inserting all data not only whats checked any one know a good way to do this? i want insert data from text box in html form.there are many text boxes gave name using 2 loops..please tell how can insert data to table?please reply I am trying to insert product descriptions into a mysql database, however they are failing because of apostrophes in the text. How do I fix this? Everything is working fine except $productdescription $ProductDescription contains, "Record In Stereo Sound, Then Play Back Your Videos Instantly On You Computer. The Sx130 Is Is All About Creativity, With Fun New Scene Modes Like Miniature Effect For Movies, And Fisheye Effect For Artistically Distorted Stills. While You're Having Fun Creating, The Camera's Smart Flash Exposure And Advanced Smart Auto Systems Are Ensuring That Every Image Is The Best It Can Be. Add The Digic 4 Image Processor, 12.1 Megapixels And Canon's Optical Image Stabilizer, And You've Got The Ideal Camera For Making The Good Times Last." SQL Error on insert, "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 're Having Fun Creating, The Camera's Smart Flash Exposure And Advanced Smart Aut' at line 1 " Code: [Select] mysql_select_db("testdb") or die(mysql_error()); mysql_query ("INSERT INTO product (merchantname, producttitle, productdescription, gtin, availability, price) VALUES ('$merchantname[1]','$producttitle[1]','$productdescription[1]','$gtin[1]',''$availability[1]','$price[1]')"); Hello, I have three scripts below that I was wondering if someone can look at as a second opinion. What they all have in common is they are supposed to append data to some tables in my database. They match the code on all my other scripts but for some reason these particular scripts will not append the data to the files. This first one... is supposed to insert the name of the doctor this person uses, and then gets the last ID created and inserts it into another table...no matter what I try, it will not do it. Code: [Select] <?php session_start(); $userid=$_SESSION['userID']; $firstName=$_SESSION['fname']; $lastName=$_SESSION['lname']; $camperID=$_POST['camperID']; $physicianFName=$_POST['physicianFName']; $physicianLName=$_POST['physicianLName']; $physicianSuffix=$_POST['physicianSuffix']; $practiceName=$_POST['practiceName']; $physicianAddress1=$_POST['physicianAddress1']; $physicianAddress2=$_POST['physicianAddress2']; $physicianAddress3=$_POST['physicianAddress3']; $physicianCity=$_POST['physicianCity']; $physicianState=$_POST['physicianState']; $physicianZip=$_POST['physicianZip']; $physicianOfficeP=$_POST['physicianOfficeP']; $physicianOfficeF=$_POST['physicianOfficeF']; $physicianSpecialty=$_POST['physicianSpecialty']; echo $camperID. ' ' .$physicianFName. ' ' .$physicianLName; //htc information and physician $htcName=$_POST['htcInfo']; $htcPhysician=$_POST['htcPhysician']; $con=mysql_connect("xxx.xxx.xxx.xx", "xxx", "xxxx") or die ("cannot connect"); mysql_select_db("testcamp") or die ("cannot select database"); $sql="INSERT INTO Physicians(physicianFName, physicianLName, physicianSuffix, practiceName, physicianAddress1, physicianAddress2, physicianAddress3, physicianCity, physicianState, physicianZip, physicianOfficeP, physicianOfficeF, physicianSpecialty) VALUES ('$physicianFName', '$physicianLName', '$physicianSuffix', '$physicianAddress1', '$physicianAddress2', '$physicianAddress3', '$physicianCity', '$physicianState', '$physicianZip', '$physicianOfficeP', '$physicianOfficeF', '$physicianSpecialty')"; $result=mysql_query($sql,$con); $physicianID=mysql_insert_id(); $sql2="INSERT INTO CamperPhysicianInfo(physicianID, camperID) VALUES ('$physicianID', '$camperID')"; $result2=mysql_query($sql2,$con); $sql3="INSERT INTO CamperHTCInfo(camperID, htcID) VALUES ('$camperID', '$htcName')"; $result3=mysql_query($sql3,$con); $sql4="INSERT INTO camperHTCPhysicianInfo(camperID, htcPhysicianID) VALUES ('$camperID', '$htcPhysician')"; $result4=mysql_query($sql4,$con); ?> This next one...is supposed to enter data into the CamperRegistrations tables and also enter data into another table for a questionaire that was completed on the form previous to this page...same thing no matter what I try will not append data. Code: [Select] <?php $question12=$_POST['question12']; $question12a=$_POST['question12a']; session_start(); $userid=$_SESSION['userID']; $firstName=$_SESSION['fname']; $lastName=$_SESSION['lname']; $camperID=$_SESSION['camperID']; $con=mysql_connect("xxx.xxx.xxx.xx", "xxx", "xxx") or die ("cannot connect"); mysql_select_db("testcamp") or die ("cannot select database"); $sql="INSERT INTO Question12(camperID, question12Answer, teaching) VALUES ('$camperID', '$question12', '$question12a')"; $result=mysql_query($sql,$con); $date=date("Y-m-d"); $defaultStatus=1; $sql2="INSERT INTO CamperRegistrations(userID, camperID, registrationDate, registrationStatus) VALUES ('$userid', '$camperID', '$date', '$defaultStatus')"; $result2=mysql_query($sql2,$con); ?> and then on this same page with this script... is it possible to carry session information when using HTML links instead of a submit form? I need the userid to carry to the next page with a link, but it won't do that either... Any help would be appreciated and thanks in advance for looking. ~jcjst21 |