PHP - Appropriate Syntax For Inserting Php Code Within <input> Element
Hi Group,
I looked through the internet and couldn't find an answer, but I was wondering on the appropriate syntax on inserting PHP code into an input element. See below. <input type="text" name="id" value="<?php echo $main['id']; ?>" size="10" /> Now this is purely an example (and I'm aware of php short tags, just don't want to use them). I only ask cause I've used CodeLobster and Eclipse and they don't really know what to do with the added php syntax. CodeLobster and Eclipse wouldn't finish marking up the rest of the line in the appropriate colors (all the text was black after the < in <?php like how I showed it above), however Eclipse's built in debug system thinks this is a syntax error. It runs just fine in the browser and does what I want it to, but I'd like the appropriate systax to get rid of this "error". Thanks in advance, ImmortalFirefly Similar TutorialsI'm trying to insert an image and this is my code:
echo "<tr>"; echo '<td><input type="submit" name="btnPost" value="'.$rec['SKU'] . '"</td>' ; echo "<td>".$rec['NAME']."</td>"; echo "<td>".$rec['DESCR']."</td>"; echo "<td>".$rec['PRICE']."</td>"; echo "<td>"<img src=".$rec['IMAGE']">."</td>"; echo "</tr>"; $row++ ; I tried just echoing the .$rec['IMAGE'] without the img tag, but all it does is echo the name of the file instead of presenting the image itself. This is the code I'm using on another page in my HTML and it works fine, but I was curious how to insert the image inside my while loop. <img src="<?php echo $rec['IMAGE']; ?>"> Im building a list of offers and adding them to a table in a database. Pretty much all it is is HTML. Im inserting an ahref link that has a php echo in it. So it looks like this: <div class="offerlinks"><a href="http://website.com/offer/blahblah&blah=blah&sid=<?php echo $_SESSION['uid'];?>">Offer name</a><br><b>Info:</b> Signup<br><b>Value</b> 1 pt</div> When I insert this (through my form) I get mysql error 1064 which is syntax error. I tested it without the php & it gives me 0, which worked fine. I need the php code so I can append userid to the SID var. Am I doing something wrong? Well I guess I obviously am so the real question is what am I doing wrong & how could I do it the right way? Thanks guys Before I get into my problem a couple of things. First, this is a work project. My organization cannot afford a full time developer so as a database guy I'm being asked to develop a web based data system using php/html/mysql/javacript/etc. So I am not asking anyone to help me cheat or violate an honor code for a school project. Also I am having to learn PHP on the fly, by the seat of my pants. Second, my organization is using a version of PHP older that 5.5.X and I am powerless to update the version. So I know that some of the syntax I am using has been deprecated in more recent PHP versions. I don't mean to sound snarky or ungrateful but I really need some help solving this problem versus unhelpful comments about deprecated code. Third I am adapting code from the guys at TechStream so H/T to them. Here is what I am trying to build. My office helps other offices in my large organization manage their records through the creation of a file plan. We are currently using a clunky, user-unfriendly Access database that was created back in 2009. I am tasked to transition that Access hoopty into a proper, web-based, user friendly system. The index.php form page consists of 2 parts. You can see the original TechStream demo he http://demo.techstre...ssing-with-PHP/ I've adapted the top part of the form ("Travel Information") for my users to enter information about their office such as Office Name, Office Code, Office Chief, Creator (the user), Status and date. I've adapted the bottom part of the form ("Passenger Details") to be "Folder Details". This is an html table where users can add up to 10000 rows to list all the folders for their office by entering the folder name in the text box and then assign descriptors to each folder using the drop down menus. I've changed the drop down menus to reflect the descriptors we need, i.e. file-series, classification, media type. The user needs the flexibility to add folders as the number of folders will vary between offices. This adding and deleting of folders is accomplished dynamically through a javascript script.js file. Now, here's my problem. When the user clicks submit button that fires a php script that runs an insert into query to place the array data into the backend mysql database. However, when the foreach loop is only inserting the office office from the top portion of the form with the first folder in the bottom portion of the form. In other words let's say the user fills out the top part with his office information and then adds 5 folders into the html table at the botton. The first folder will be inserted into the database table with both office information and folder information. However the subsequent 4 folders will have their folder information inserted into the table but the office information fields will be null. The office information needs to be inserted with each folder the user adds to the html table piece. I suspect that my foreach loop is only capturing that office information on the first iteration of the loop and then flushing or deleting the office information after the first loop. Also, I suspect there is some disconnect between the html table for entering individual folders and the top part of the form that is not in html format. Any help I can get is most welcome. Thanks in advance! Code is below. index.php <?php session_start(); if(!isset($_SESSION['myusername'])) { header('Location:index.php'); } echo $_SESSION['myusername']; echo '<a href="logout.php"><span>Logout</span></a></li>'; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Records Management File Plan Application</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet" type="text/css" href="css/default.css"/> <script type="text/javascript" src="js/script.js"></script> </head> <body> <form action="InsertFileDetailArraytoDB.php" class="register" method="POST"> <h1>Office File Plan Application/h1> <fieldset class="row1"> <legend>Office Information</legend> <p> <label>Office Code * </label> <input name="officecode[]" type="text" required="required"/> <label>Date* </label> <select class="date" name="day[]"> <option value="1">01 </option> <option value="2">02 </option> <option value="3">03 </option> <option value="4">04 </option> <option value="5">05 </option> <option value="6">06 </option> <option value="7">07 </option> <option value="8">08 </option> <option value="9">09 </option> <option value="10">10 </option> <option value="11">11 </option> <option value="12">12 </option> <option value="13">13 </option> <option value="14">14 </option> <option value="15">15 </option> <option value="16">16 </option> <option value="17">17 </option> <option value="18">18 </option> <option value="19">19 </option> <option value="20">20 </option> <option value="21">21 </option> <option value="22">22 </option> <option value="23">23 </option> <option value="24">24 </option> <option value="25">25 </option> <option value="26">26 </option> <option value="27">27 </option> <option value="28">28 </option> <option value="29">29 </option> <option value="30">30 </option> <option value="31">31 </option> </select> <select name="month[]"> <option value="1">January </option> <option value="2">February </option> <option value="3">March </option> <option value="4">April </option> <option value="5">May </option> <option value="6">June </option> <option value="7">July </option> <option value="8">August </option> <option value="9">September </option> <option value="10">October </option> <option value="11">November </option> <option value="12">December </option> </select> <select name="year[]"> <option value="2013">2013 </option> <option value="2014">2014 </option> <option value="2015">2015 </option> <option value="2016">2016 </option> </select> </p> <p> <label>Office Chief* </label> <input name="officechief[]" required="required" type="text"/> <label>Status* </label> <select name="status[]"> <option value="Draft">Draft </option> <option value="Submitted">Submitted </option> <option value="Approved">Approved </option> </select> </p> <p> <label>Creator * </label> <input name="creator[]" required="required" type="text"/> </p> <div class="clear"></div> </fieldset> <fieldset class="row2"> <legend>Folder Details</legend> <p> <input type="button" value="Add Folder" onClick="addRow('dataTable')" /> <input type="button" value="Remove Folder" onClick="deleteRow('dataTable')" /> <p>(All actions apply only to entries with check marked check boxes.)</p> </p> <table id="dataTable" class="form" border="1"> <tbody> <tr> <p> <td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td> <td> <label>Folder Name</label> <input type="text" required="required" name="BX_NAME[]"> </td> <td> <label for="BX_fileseries">File Series</label> <select id="BX_fileseries required="required" name="BX_fileseries[]"> <option>100-01-Inspection and Survey/PII-NO</option> <option>200-02-Credit Card Purchases/PII-NO</option> <option>300-07-Time and Attendance/PII-YES</option> </td> <td> <label for="BX_classification">Classification</label> <select id="BX_classification" name="BX_classification" required="required"> <option>Unclassified</option> <option>Confidential</option> <option>Secret</option> <option>Top Secret</option> <option>Ridiculous Top Secret</option> <option>Ludicrous Top Secret</option> </select> </td> <td> <label for="BX_media">Media</label> <select id="BX_media" name="BX_media" required="required"> <option>Paper</option> <option>Shared Drive</option> <option>Film</option> <option>Floppy Disk</option> <option>Mixed</option> <option>Other</option> </select> </td> </p> </tr> </tbody> </table> <div class="clear"></div> </fieldset> <input class="submit" type="submit" value="File Plan Complete »" /> <div class="clear"></div> </form> </body> </html>PHP script with foreach loop to loop through the array from index.php and insert into database: InsertFileDetailArrayToDB.php /* When the user has finished entering their folders, reviewed the form inputs for accuracy and clicks the submit button, this will loop through all folder entries and using the SQL insert into query will place them in the database. When it completes data insertion it will redirect the user back to the file detail input form*/ <?php /*this part requires the user to be logged in and allows their user name to be included in the insert into query. If you remove the "ob_start();" piece it will screw up the header statement down at the botton. See the comments by the header statement for an explanation of its purpose*/ ob_start(); session_start(); if(!isset($_SESSION['myusername'])) { header('Location:index.php') } /*these two lines would ordinarily display the user name and a link a allowing the user to log out. However this php script does not output anything so the user will never it.*/ echo $_SESSION['myusername']; echo '<a href="logout.php"><span>Logout</span></a></li>'; ?> <?php /*this include statement connects this script to the MySQL database so the user form inputs can be inserted into the file_plan_details table*/ include ('database_connection.php'); foreach($_POST['BX_NAME'] as $row=>$BX_NAME) { $BX_NAME1 = mysql_real_escape_string($_POST['BX_NAME'); $officecode1 = mysql_real_escape_string($_POST['officecode'][$row]); $username1 = mysql_real_escape_string($_SESSION['myusername'][$row]); $day1 = mysql_real_escape_string($_POST['day'][$row]); $month1 = mysql_real_escape_string($_POST['month'][$row]); $year1 = mysql_real_escape_string($_POST['year'][$row]); $creator1 = mysql_real_escape_string($_POST['creator'][$row]); $officechief1 = mysql_real_escape_string($_POST['officechief'][$row]); $status1 = mysql_real_escape_string($_POST['status'][$row]); $BX_fileseries1 = mysql_real_escape_string($_POST['BX_fileseries'][$row]); $BX_classification1 = mysql_real_escape_string($_POST['BX_classification'][$row]); $BX_media1 = mysql_real_escape_string($_POST['BX_media'][$row]); $fileplandetailinsert1 = "INSERT INTO file_plan_details (folder_name, office_code, user_name, day, month, year, creator, office_chief, status, file_series, classification, media) VALUES ('$BX_NAME1','$officecode1','$username1','$day1','$month1','$year1','$creator1','$officechief1','$status1','$BX_fileseries1','$BX_classification1','$BX_media1')"; mysql_query($fileplandetailinsert1); } /*this header statement redirects the user back to the folder detail input form after it inserts data into the db After I build a main navigation page, I will switch out index.php with whatever I name the script that will produce the main navigation page*/ header('Location:index.php'); ?>script.js function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; if(rowCount < 10000){ // limit the user from creating fields more than your limits var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; } }else{ alert("Maximum Passenger per ticket is 5."); } } function deleteRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowCount <= 1) { // limit the user from removing all the fields alert("Cannot Remove all the Passenger."); break; } table.deleteRow(i); rowCount--; i--; } } } Edited by mac_gyver, 17 December 2014 - 01:13 PM. code tags around posted code please When I hit the submit button I would like the answer to appear in the box labled answer. Is that possible? Code: [Select] <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <style type="text/css"> input {position:absolute; left:120px;} p {margin-bottom:-10px;} </style> </head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <p>first number:<input type="text" name="first_number" /></p> <p>second number:<input type="text" name="second_number" /></p> <p>answer:<input type="text" name="answer" /></p> <ul> <li>add: <input type="radio" name="group1" value="add" /></li> <li>subtract: <input type="radio" name="group1" value="subtract" /></li> <li>multiply: <input type="radio" name="group1" value="multiply" /></li> <li>divide: <input type="radio" name="group1" value="divide" /></li> </ul> <p><input type="submit" value="submit" /></p> </form> <?php $answer = $_POST['group1']; $first = $_POST['first_number']; $second = $_POST['second_number']; $ans=0; if ($answer == "add") { $ans = $first + $second; echo $ans; } else if ($answer == "subtract"){ $ans = $first - $second; echo $ans; } else if ($answer == "multiply"){ $ans = $first * $second; echo $ans; } else if ($answer == "divide"){ $ans = $first / $second; echo $ans; } else { echo 'damm...'; } ?> </body> </html> This function is throwing the following error: invalid input syntax for type timestamp "1301297896" Code: [Select] function removeInactiveUsers(){ if(!TRACK_VISITORS) return; $timeout = time()-USER_TIMEOUT*60; $result = pg_query_params($this->connection, "delete from active_users where timestamp < $1", array($timeout)); $this->calcNumActiveUsers(); } I know the problem is with $timeout using a php timestamp vs postgresql timestamp but I'm not sure how to fix that Hi, I tried putting this Viglink code into my custom themes index.template.php on my SMF forum (I should do that right?) and I ended up with this error... Code: [Select] Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .../Themes/androidrtk_rev4n/index.template.php on line 554 545: subMenusContainerId:\'admsubMenus\', 546: duration:\'150\' 547: }); 548: }); 549: } 550: </script> 551: 552: <script type="text/javascript"> 553: var vglnk = { api_url: '//api.viglink.com/api', 554: key: 'ad93febdf4e33c034d9635037b687fb3' }; 555: 556: (function(d, t) { 557: var s = d.createElement(t); s.type = 'text/javascript'; s.async = true; 558: s.src = ('https:' == document.location.protocol ? vglnk.api_url : I figured since it was a copy paste code that it would work just fine In any case, how can I fix this? Thanks in advance, Jimmy I have this simple form that registers schools. This year I have decide to upgrade and include a feature that checks if the school is already registered or not based on the imputed name. Here is the code (that is the only way I know how): mysql_connect("", "", "") or die(mysql_error( '' )); mysql_select_db("") or die(mysql_error( '' )); $query = "SELECT * FROM School_Registrations WHERE School_Name= '$_POST[SchoolName]' "; $result = mysql_query($query); if (mysql_numrows($result) > 0) { while($row = mysql_fetch_array($result)) echo" error code here";} else {mysql_query("INSERT INTO `database`.`School_Registrations` (all the variables here);") or die(mysql_error( '' )); echo "Success Code";} I am trying to incorporate this code somewhere into the 'else' statement but I have no luck. I am constantly getting some errors and when I fix one there is one more to take its place. I am lost. The last one I can not fix and I am not sure what it wants from me: Fatal error: Call to undefined function getPage() It works by itself without the if/else statement but not in the code listed above $url = 'http://www.otherpage.com/page.php?'; $url .= 'email='.urlencode($_POST['email']); $result2 = getPage('', $url, '', 15); function getPage($proxy, $url, $header, $timeout) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_REFERER, 'http://azsef.org'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8'); $result2['EXE'] = curl_exec($ch); $result2['INF'] = curl_getinfo($ch); $result2['ERR'] = curl_error($ch); curl_close($ch); return $result2; } Can you tell me why doesn't it work? Thanks 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? Hi guys,
Having some trouble entering some php into my wordpress site that runs on Optimize Press.
I'm trying to insert this URL/ tracking code into my page as a hyperlink - 'Click Here Now'.
http://www.mysite.co...1_50onRed&sub1=<?php echo $sub1; ?>&sub2=<?php echo $sub2; ?>&sub3=<?php echo $sub3; ?>&sub4=<?php echo $sub4; ?>&sub5=<?php echo $sub5; ?>&lpid=<?php echo $lpid; ?>
This is what I have done so far:
<a href="http://www.mysite.co...;sub1=<?php echo $sub1; ?>&sub2=<?php echo $sub2; ?>&sub3=<?php echo $sub3; ?>&sub4=<?php echo $sub4; ?>&sub5=<?php echo $sub5; ?>&lpid=<?php echo $lpid; ?>">Click Here Now</a>
This does generate a hyperlink, however when I click it, I get: 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 '=' at line 2
I understand for this code to work the page has to be saved in php. I thought wordpress did this automatically?
Can anyone help please? Also, please bear in mind I am using the Optimize Press plugin.
Many thanks in advance!
Tom
I am trying to insert a new user into my database from my php code. This is the error message that I am getting from the webpage: Quote Error: 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 'order, previousOrder) VALUES ('c_s@gmail.com','test','3','callulm','Smith','17' at line 1 This is the code that I am using: Code: [Select] <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("deliverpizza", $con); $sql="INSERT INTO customer(userName, password, privilege, firstName, lastName, address, postCode, order, previousOrder) VALUES ('$_POST[username]','$_POST[password]','$_POST[privilege]','$_POST[firstname]','$_POST[lastname]','$_POST[address]','$_POST[postcode]','$_POST[order]','$_POST[previousOrder]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Hi and thank you in advance for helping me. Here is the code fragment: $sql="SELECT UserID,UserName FROM `UserValidation` WHERE UserID='".$_SESSION["UserID"]."'"; $rs=CustomQuery($sql); $RecData=db_fetch_array($rs); global $conn,$strUserValidation; $strSQLSave = "INSERT INTO RecruiterNames (UserID, UserName) values ("; $strSQLSave .= $RecData["UserID"].","; $strSQLSave .= chr(34).$RecData['UserName'].chr(34); $strSQLSave .= ")"; db_exec($strSQLSave,$conn); Here is the error I receive: php error happened Technical information Error type 256 Error description 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 '"")' at line 1 URL www.dealwithaces.com/ACESDB/register.php? Error file /home/debra/public_html/dealwithaces.com/ACESDB/include/dbconnection.php Error line 36 SQL query INSERT INTO RecruiterNames (UserID, UserName) values (,"") More info Call stack File: line Function Arguments #0. include/dbconnection.php:36 db_query 1. INSERT INTO RecruiterNames (UserID, UserName) values (,""); 2. Resource id #10; #1. include/dbconnection.php:47 db_exec 1. INSERT INTO RecruiterNames (UserID, UserName) values (,""); 2. Resource id #10; #2. include/events.php:25 AfterSuccessfulRegistration 1. Array ( [UserName] => bsbnick [Password] => kaos55 [UserEmail] => mike@world-class-multimedia.com [GroupID] => 1 [UserActive] => 0 ) ; #3. register.php:298 Global scope N/A I need two fields from UserValidation table (UserID and UserName) to be inserted into table RecruiterNames (UserID and UserName), but ONLY when GroupID = 3 Thank you again for your help. Mike I have 2 files; Newfault.php and thankyou.php 1) Data is entered into a form in Newfault.php 2) The data from this form is retieved in thankyou.php and is then inserted into a table called "Calls" Problem: My entered record is being added to my database OK, but it is also adding a blank record for some reason and I can't work out why. Can anyone help? This is for my uni assignment. Thanks, Ladykudos Im inserting HTML into a database, and then outputting it on a PHP page. Its an iframe code, so when I output it, it shows the iframe. I need it to just display the HTML code. How can I do this? I thought it would be something simple but I can find anyway to do it. Help very appreciated!! Thanks Hi, I have this script that gets variables from a form and sends email. Code: [Select] <?php $EmailTo = Trim(stripslashes($_POST['to'])); $Subject = Trim(stripslashes($_POST['subject'])); $email = Trim(stripslashes($_POST['email'])); // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: My Company <info@mycompany.com>' . "\r\n"; $headers .= 'Cc: $_POST['cc']' . "\r\n"; $headers .= 'Bcc: $_POST['bcc']' . "\r\n"; // prepare email body text $Body = ""; $Body .= $email; $Body .= "\n"; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, stripslashes($Body), $headers); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=../PC_email_compose.php?emailsentok=true\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=../PC_email_compose.php?emailsenterror=true\">"; } ?> It works fine except for these 2 variable: Code: [Select] $headers .= 'Cc: $_POST['cc']' . "\r\n"; $headers .= 'Bcc: $_POST['bcc']' . "\r\n"; I know it's a syntax error...but I can't figure it out. Thanks I have a form that is passing the User to following code. The code below is just ported from another site that I created, which works extremely well. I've had to change the datatable, database connection and some of the variables for this site, but it's otherwise the same. I've triple checked the variables. The datatable is accurate. It doesn't appear to be passing variable from the Form with the exception of "content", and I'm getting the following error: Quote 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 'year='', position='', content='Test', ppg='', rp' at line 6 Query: INSERT INTO players SET playerFirst='', playerLast='', feet='', inches='' year='', position='', content='Test', ppg='', rpg='', apg='', spg='', bpg='', fgp='', ftp='', status='' What am I missing? Code: [Select] <?php include('db.php'); $playerFirst = $_POST['playerFirst']; $playerLast = $_POST['playerLast']; $feet = $_POST['feet']; $inches = $_POST['inches']; $year = $_POST['year']; $position = $_POST['position']; $content = $_POST['content']; $ppg = $_POST['ppg']; $rpg = $_POST['rpg']; $apg = $_POST['apg']; $spg = $_POST['spg']; $bpg = $_POST['bpg']; $fgp = $_POST['fgp']; $ftp = $_POST['ftp']; $status = $_POST['status']; //if(isSet($_POST['playerFirst']['playerLast']['feet']['inches']['year']['status'])) //{ /* search for existing row */ $sql = "SELECT msg_id FROM players WHERE playerFirst='".mysql_real_escape_string($playerFirst)."' AND playerLast='".mysql_real_escape_string($playerLast)."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); /* update existing row */ $sql = "UPDATE players SET feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' year='".mysql_real_escape_string($year)."', position='".mysql_real_escape_string($position)."', content='".$content."', ppg='".$ppg."', rpg='".$rpg."', apg='".$apg."', spg='".$spg."', bpg='".$bpg."', fgp='".$fgp."', ftp='".$ftp."', status='".$status."', WHERE msg_id='".$row['msg_id']."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } else { /* insert new row */ $sql = "INSERT INTO players SET playerFirst='".mysql_real_escape_string($playerFirst)."', playerLast='".mysql_real_escape_string($playerLast)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' year='".mysql_real_escape_string($year)."', position='".mysql_real_escape_string($position)."', content='".$content."', ppg='".$ppg."', rpg='".$rpg."', apg='".$apg."', spg='".$spg."', bpg='".$bpg."', fgp='".$fgp."', ftp='".$ftp."', status='".$status."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } This is the code: <?php $Fname = $_POST["Fname"]; if (!isset($_POST['SUBMIT'])) { // if page is not submitted to itself echo the form ?> <html> <body> <head> <title>Personal INFO</title> </head> <body bgcolor="#008080"> <h1><blink><font color="#FF0000"><strong>Naruto Biography Creation</strong></font></blink></h1> <h3><font size="1" color="#0000FF">Please note, info with a (*) must be filled in!</h> </font> <form method="post" action="<?php echo $PHP_SELF;?>"> <p><font size="2"><b>*First Name:</b></font><input type="text" size="30" maxlength="12" name="Fname"><br /> <br /> <font size="2"><b>*Last Name:</b></font><input type="text" size="30" maxlength="36" name="Lname"><br /> <br /> <b><font size="2">*Gender:</font></b><br /> <input type="radio" value="Male" name="Gender" style="font-weight: 700"><b><font size="2">Male</font> </b><input type="radio" value="Female" name="Gender" style="font-weight: 700"><b><font size="2">Female</font></b></p> <p><b><font size="2">Background Info:</font></p> <textarea rows="3" cols="33" name="Background INFO" wrap="hard">Enter your Character's History</textarea><p><font size="2">Appearance:</font></p> <p> <textarea rows="3" cols="33" name="*Appearance" wrap="hard">State how your character look</textarea></p> <p><font size="2">Personality:</font><br/><span> <textarea rows="3" cols="33" name="*Personality" wrap="hard">Explain your Character's qualities, attitude, etc.</textarea></span></p> <p><span><br /></span> <font size="2">*Affiliation:</font><br /> <select name="Affiliation" size="3" width="8"> <option value="None" selected>Select one</option> <option value="Leaf">Leaf</option> <option value="Sand">Sand</option> <option value="Cloud">Cloud</option> <option value="Rogue">Rogue</option> </select><br /> <font size="2">*Rank:</font><br /> <select name="Rank" size="3" width="8"> <option value="none" selected>Select one</option> <option value="Gennin">Genin</option> <option value="Chuunin">Chuunin</option> <option value="Jounin">Jounin</option> <option value="S class">S class</option> </select> </p> <p> <input type="submit" value="submit" name="submit"></p> </form> </body> </html> <? } esle { echo "Hello,".$Fname." ".Lname.".<br />"; } ?> I get this all the time Quote Parse error: syntax error, unexpected $end in F:\wamp\www\index.php on line 78 I work on Wamp, and I am a beginner so I am totally lost could anyone help please I'm attempting to add syntax highlighting to my bbcode function. I started with the general basis for a bbcode function that there are a million tutorials on. To make things simpler I took out the rest of the bbcode tags. Code: [Select] <?php //Eventually will need to add some logic to color the code tags function parseBBCode($string) { $search = array( '/\[code\](.*?)\[\/code\]/is', ); $replace = array( '<div class="code"><code>$1</code></div>' ); //Render the tabs in html //may need to find a better place for this in the future $string = str_replace(' ', ' ', $string); return preg_replace($search, $replace, $string); } ?> I've tried using the highlight_string() function but it never highlights it. I assumed this was because when I store the data in the database I used htmlentities() on the text. So I also tried the following to no avail: Code: [Select] '<div class="code">'.highlight_string(html_entity_decode('$1'), true).'</div>' And this where I'm calling the function: Code: [Select] $posts = ''; while($post = $db->fetchArray($content)) { $posts .= '<span style="font-size: 22px;">'.$post['title'].'</span><br /> <hr />'; $posts .= '<br />'.nl2br(stripslashes(parseBBCode($post['post']))).'<br /><br /><hr />'; $user = $db->query('SELECT username FROM isnet_users WHERE id = '.$post['poster_id'].';'); $user = $db->fetchArray($user); $posts .= '<strong>Author: </strong>'.$user['username'].'<br /><br />'; } //end while I've tried a few other methods that have produced syntax highlighting but have broken other posts that don't need it. So is there something I'm just obliviously missing? $tab is a variable for my table's name <?php while($row=mysqli_fetch_assoc($result)){ ?> <?php echo $row['{$tab}_name']?> Hi, I need some help here, the one which I have highlighted in red, 'dob' and 'gender', are not inputting any values into my database table. I'm just wondering did I miss out something important, or should I change the 'type' in my database table? Thanks <?php $dob = $_POST['dob']; $gender = $_POST['gender']; /**INSERT into tutor_profile table**/ $query2 = "INSERT INTO tutor_profile (name, nric, dob, gender, race) VALUES ('$name', '$nric', '$dob', '$gender', '$race')"; $results2 = mysqli_query($dbc, $query2) or die(mysqli_error()); ?> <html> <div> <label for="dob" class="label">Date Of Birth</label> <input name="dob" type="text" id="dob"/> </div> </html> <!--Race--> <div> <label for="race" class="label">Race</label> <?php echo '<select name="race" id="race"> <option value="">--Please select one--</option>'; $dbc = mysqli_connect('localhost', '111', '111', '111') or die(mysqli_error()); $query = ("SELECT * FROM race ORDER BY race_id ASC"); $sql = mysqli_query($dbc, $query) or die(mysqli_error()); while($data = mysqli_fetch_array($sql)) { echo'<option value="'.$data['race_id'].'">'.$data['race_name'].'</option>'; } echo '</select><br/>'; mysqli_close($dbc); ?> </div> One more question. So I have a function with two parameters, $x and $y. Here it is. Code: [Select] function dydx($x,$y){ $equation = 2 * $x; return $equation; } Now here's the problem. I want $equation to be user defined. Easy enough, I use a post command and I get $equation to equal whatever the user inputs. The problem is that if I get input from the user, I'm not sure how to take that input and then have the function parameters work on it. Like if the user inputs "3*$x + 2*$y", i want to be able to let the parameters for the function dydx act on it. How could I go about doing this? |