PHP - Probably Simple But Kinda Baffled
The alias form isn't being read for some reason, with having $alias = $_POST['alias']; i don't quiet understand why this isn't it isn't being picked up as a variable below, any clues? cheers
Code: [Select] <?php include("header.php"); if(isset($_POST['formAlias']) && $_POST['formAlias'] == 'Yes') { $alias = $_POST['alias']; $alias = preg_replace("/[^a-zA-Z0-9_]/", "", $alias); $namelength = strlen($alias); if($namelength < 3){ $error1="Your alias must be at least 3 characters!</span></div>"; echo $error1; }else{ } $query = sprintf("SELECT COUNT(id) FROM players WHERE UPPER(alias) = UPPER('$alias')", mysql_real_escape_string($alias)); $result = mysql_query($query); list($count) = mysql_fetch_row($result); if($count >= 1) { $error1="$alias is already taken."; echo $error1; }else{ } $sql = "updatehereble"; mysql_query($sql) or die(mysql_error()); }else{ } ?> </p> <p> <input name="alias" type="text" id="alias"> </p> <form action="alias.php" method="post"> Do you wish to use an alias? <input type="checkbox" name="formAlias" value="Yes" /> <input type="submit" name="formSubmit" value="Submit" /> </form> Similar TutorialsPHP = 5.5.14
MySQL = 5.2.17
I've cloned a mysqli_connect() statement in a 'require' file placed in a non-public access location on the server. It's the same format (and location) currently working fine with another application, EXCEPT i changed the database name to what I need to use for this application, AND added the $con= part on the front end to substitute for the commented out $con= line in the example code I'm modifying to insert data into a new MySQL DB Table.
The dB Table is fine and I have Inserted data via myPHPAdmin with no problems. Only two form variables are in the simple PHP script thus far just to test if it will work before proceeding.
I've used pseudonames for the actual /home/.... location and filename, and am now Baffled about the Line 2 Error Message I'm getting (below the code).
<?php require '/home/myusername/domains/mydomain.com/myclonedrequire.php'; //$con=mysqli_connect("example","uid","pwd","my_db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // escape variables for security $year = mysqli_real_escape_string($con, $_POST['year']); $callsign = mysqli_real_escape_string($con, $_POST['callsign']); $sql="INSERT INTO `lqplogs` (`year`, `callsign`) VALUES ('$year', '$callsign'); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?>ERROR Message: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in (above file & location) on line 2 There are NO '\' characters in any of my files. Here is the simple Form file code: <?php ?> <html: <head><title></title></head> <body> <form action="insert.php" method="post"> YEAR: <input type="text" name="year"> CALLSIGN: <input type="text" name="callsign"> <input type="submit"> </form> </body> </html> <?php ?>Thanks for any assistance! -FreakingOUT Hey everyone, I'm getting an error on this code and I'm having a difficult time sorting it out. Most of this page is in html, but here is what little PHP I'm using as of now: Code: [Select] <select class="ddbox2" name="occasion"> <option value="select" selected>- Select -</option> <?php $resdate = "02/20/2012"; $result = mysql_query("SELECT `time` FROM delivery_times WHERE `index` > '0'"); while ($row = mysql_fetch_row($result)) { $posstime = $row[0]; $reserved = mysql_query("SELECT * FROM reservations WHERE `resdate` = '$resdate' AND `deltime` == '$posstime'"); $rowcheck = mysql_num_rows($reserved); // <-- THIS IS LINE 198 if ($rowcheck == 0) { echo "<option value='$posstime'>$posstime</option>"; } } ?> </select> What I'm doing is creating a dropdown menu for an html form depending on what is in my database, but here is the error that I'm getting: "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\new_site\custform.php on line 198" When I change line 198 to read: $rowcheck = mysql_num_rows($result); I don't get the error, but I don't get the information that I need to complete my task. I was thinking that maybe this query isn't allowed in a while loop for some reason, but I don't think that would be the case. Any ideas on what I could be doing wrong? Hello,
NOTE: I'm not asking for help to modify the code below, only looking for feedback regarding why it is working
I'm working over other's people code and I found this lines:
<div class="button-container" style="top:20px; left:0px"> <input type="submit" name="submit" value="Get Report" <a href="#" class="large-button" style="left: 0px" > <div class="button-glare"> </div> </a> </div>Clearly the input tag is wrong (W3C validator confirm it), however works fine and does what is supposed to do (apply some css styles over the submit button). IE11 Developer tools detect the errors, but FF nor Chrome does. this is what it looks like (attached image) and this is the related CSS /* CSS Document */ /* Button Containers */ .button-container { float: left; overflow: visible; position: relative; } .button-container .large-button { background: linear-gradient( to top, green, lightgray); border-radius: 6px; font-size: 14px; font-weight: bold; color: #FFFFFF; line-height: 14px; padding: 10px 20px 8px; text-shadow: -1px -1px 1.5px rgba(0, 0, 0, 0.5); position: relative; } .button-container .button-glare { border-radius: 4px; height: 50%; left: 1px; position: absolute; right: 1px; top: 1px; z-index: -1; }any idea why it does work? thanks Miko I have a script to check for duplicate username's on signup. Even when there is no entry found and the script preforms the update statement, the error will come back indicating the requested name already exists. #Check to see if requested name already exists $name = $_POST['name']; $siteid = $_POST['siteid']; $checkname = mysql_query("SELECT * FROM projects WHERE url = '$name'"); $founduser = mysql_num_rows($checkname); if ($founduser != 0) { echo"$name already exists in the database. Please select another name";} if ($founduser == 0) { mysql_query("UPDATE projects SET url = '$name' WHERE siteid = $siteid"); die; echo"URL updated successfully";} If I remove the UPDATE statement and simply return an echo statement for each IF statement, everything works fine: if ($founduser != 0) { echo"$name already exists in the database. Please select another name";} if ($founduser == 0) { echo"$name is available";} So what's happening is, when $founduser == 0, the update script preforms just fine and the database is populated correctly, but then the entire script will then re-run itself and find the name that was just entered, resulting in $founduser != 0. How do I stop the script when it preforms the UPDATE statement? I tried putting die; in after the UPDATE statement, but the entire script still re-runs itself. I am pulling my hair out here... hope i'm in the right place. Hello,my name is carlton. i have a html form i created in dreamweaver cs. i have the accompanying .php script to forward user details to the server. i fill in the form, hit the submit button and nothing appears in the table i created. the testing server has been successfully configured the database "babiesnmovies" is recognized by dreamweaver. PLS tell me what i'm missing. below is a copy of the form and the script. Thank you so much. //this is the HTML registration web form i created in dreamweaver// Code: [Select] <legend>Parents Contact Information</legend> </h3> <form id="form1" name="form1" method="PUT" action="babiesnmovies.php"> <p> <label for="babiesnmovies.com/register">Your First Name</label> <input type="text" name="yourfirstname" id="babiesnmovies.com/register" /> <label for="babiesnmovies.com/registered">Your Last Name</label> <input type="text" name="yourlastname" id="babiesnmovies.com/registered" /> </p> <label for="babiesnmovies.com/yourname">Your Phone Number</label> <input type="text" name="yourphonenumber" id="babiesnmovies.com/yourname" /> <label for="babiesnmovies.com/email">Your E-mail</label> <input type="text" name="youremail" id="babiesnmovies.com/email" /> </p> </form> <p> </p> <h3> <legend>Baby's Vitals</legend> </h3> <form id="form2" name="form2" method="PUT" action="babiesnmovies.php"> <p> <label for="babiesnmovies.com/baby'slast">Baby's First Name</label> <input type="text" name="babysfirstname" id="babiesnmovies.com/baby'sfirst" /> <label for="babiesnmovies.com/babies">Baby's Middle Name</label> <input type="text" name="babysmiddlename" id="babiesnmovies.com/babies" /> </p> <p> <label for="babyslastname">Baby's Last Name</label> <input type="text" name="babyslastname" id="babyslastname" /> </p> <p> <label for="babiesnmovies.com/babybday">Baby's Birthdate</label> <input type="text" name="babysbirthdate" id="babiesnmovies.com/babybday" /> <label for="babiesnmovies.com/babyage">Baby's Age</label> <input type="text" name="babysage" id="babiesnmovies.com/babyage" /> </p> <p> <label for="babiesnmovies.com/baby">Baby's Height</label> <input type="text" name="babysheight" id="babiesnmovies.com/baby" /> <label for="babiesnmovies.com/babyweight">Baby's Weight</label> <input type="text" name="babysweight" id="babiesnmovies.com/babyweight" /> </p> <p> <label for="babiesnmovies.com/babyeyes">Baby's Eye Color</label> <input type="text" name="babyseyecolor" id="babiesnmovies.com/babyeyes" /> <label for="babiesnmovies.com/babyhair">Baby's Hair Color</label> <input type="text" name="babyshaircolor" id="babiesnmovies.com/babyhair" /> </p> <p> <label for="babiesnmovies.com/babyrace">Baby's Ethnicity</label> <input type="text" name="babysethnicity" id="babiesnmovies.com/babyrace" /> </p> <p><input name="formsubmit" type="submit" value="Submit" /> </form> //this is the babiesnmovies.php script// <?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_babiesnmovies = "XXX"; $database_babiesnmovies = "XXX"; $username_babiesnmovies = "XXX"; $password_babiesnmovies = "XXX"; $babiesnmovies = mysql_pconnect($hostname_babiesnmovies, $username_babiesnmovies, $password_babiesnmovies) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db("db337879506", $con); $sql="INSERT INTO register (id, YourFirstName, YourLastName, YourPhoneNumber, YourEmailAddress, BabysFirstName, BabysMiddleName, BabysLastName, BabysBirthdate, BabysAge, BabysHeight, BabysWeight, BabysEyeColor, BabysHairColor, BabysEthnicity) values ( 'NULL','$yourfirstname', '$yourlastname', '$yourphonenumber', 'youremailaddress', '$babysfirstname', '$babysmiddlename', '$babyslastname', '$babysbirthdate', '$babysage', '$babysheight', '$babysweight', '$babyseyecolor', '$babyshaircolor', '$babysethnicity')"; $yourfirstname = $_POST ['YourFirstName']; $yourlastname = $_POST ['YourLastName']; $yourphonenumber = $_POST ['YourPhoneNumber']; $youremailaddress = $_POST ['YourE-mailAddress']; $babysfirstname = $_POST ['BabysFirstName']; $babysmiddlename = $_POST ['BabysMiddleName']; $babyslastname = $_POST ['BabysLastName']; $babysbirthdate = $_POST ['BabysBirthdate']; $babysage = $_POST ['BabysAge']; $babysheight = $_POST ['BabysHeight']; $babysweight = $_POST ['BabysWeight']; $babyseyecolor = $_POST ['BabysEyeColor']; $babyshaircolor = $_POST ['BabysHairColor']; $babysethicity = $_POST ['Babys Ethnicity']; ?> Thank you. Hi I'm trying to update a form to a mysql database- it's simply all text fields except for one integer which is the primar key (auto increment etc) http://www.arts.ulster.ac.uk/interviews/test.php http://www.arts.ulster.ac.uk/interviews/thanks3.php test.php holds the form and the recaptcha which all seems to be fine and it posts to thanks3.php which (when i switched to $_GET) is passing the variables to that page but those values are not being stored. I then input my query into the mySQL query browser: INSERT INTO UCASinterviews VALUES ('','$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents'); which updated the values i put in but gave this error: Incorrect integer value: '' for column 'ID' at row 1 thanks3.php just won't transfer that info to the table no matter what I try. I used $_GET, I used PHP_SELF, I stripped the rest of the page away to make sure nothing was conflicting and now I'm totally stumped- please could someone look at this with fresh eyes? test.php: <!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="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <form action="thanks3.php" method="post" id="form2" style="margin-left:15px; display:;"> <dl id="contform"> <dd><label>Name:</label><br /> <input class="padform" type="text" name="name" size="43" maxlength="20" tabindex="2"/></dd> <label>UCAS ID:</label><br /> <input class="padform" name="UCAS" type="text" id="UCAS" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Email:</label><br /> <input class="padform" name="email" type="text" id="email" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Mobile:</label><br /> <input class="padform" name="mob" type="text" id="mob" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Landline:</label><br /> <input class="padform" name="tel" type="text" id="tel" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Subject:</label><br /> <select name="subject" tabindex="1" class="padform"> <option value="English">English</option> <option value="European Studies">European Studies</option> <option selected value="Film Studies">Film Studies</option> <option value="French">French</option> <option value="German">German</option> <option value="History">History</option> <option value="Irish">Irish</option> <option value="Spanish">Spanish</option> <option value="Journalism">Journalism</option> <option value="Photo Imaging">Photo Imaging</option> <option value="Media Studies and Production">Media Studies & Production</option> <option value="Interactive Media Arts">Interactive Media Arts</option> </select></dd> <dd><label>Address:</label><br /> <textarea class="padform"name="address" cols="40" rows="15" id="address" tabindex="5"/> </textarea></dd> <dd> <label>Preferred Interview Date:</label> <select name="interviewdate" class="padform"> <option value="26/02/11">26 February 2011</option> <option selected value="12/03/11">12 March 2011</option> </select> </dd> <dd> <label>Preferred Interview Time:</label> <select name="interviewtime" class="padform"> <option value="AM">Morning (AM)</option> <option selected value="PM">Afternoon (PM)</option> </select> </dd> <dd> <label>Parents/Guardians:</label> <select name="parents" class="padform"> <option value="1">1</option> <option selected value="2">2</option> </select> </dd> <dd> <p> <?php require_once('recaptcha/recaptchalib.php'); $publickey = "6LdU2b4SAAAAAGsh6Z78HjunUL6Mt-ZqCXtIimOs"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> </p> </dd> <dd style="background:none;"><input class="btn" type="submit" name="submit" value="Send" tabindex="6" id="submit" /></dd> </dl> </form> </div> </body> </html> thanks3.php <?php require_once('recaptcha/recaptchalib.php'); $privatekey = "6LdU2b4SAAAAAN_Z9rLyvle0vb4n4EbyAVyXDa6V"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification require_once("../includes/db_connect.php"); if($_POST['submit']=="true"){ $name=$_POST['name']; $address=$_POST['address']; $UCAS=$_POST['UCAS']; $mobile=$_POST['mob']; $email=$_POST['email']; $tel=$_POST['tel']; $subject=$_POST['subject']; $interviewdate=$_POST['interviewdate']; $interviewtime=$_POST['interviewtime']; $parents=$_POST['parents']; $addEntry="INSERT INTO UCASinterviews VALUES ('','$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents');"; $addResult=mysql_query($addEntry,$db); } } ?> I have other forms working with this near enough the same structure/layout/code - i'm ready to have a coronary! Is it the database setup? It's same as it ever was myISAM, UTF unicode... Right i want to have friends displayed on peoples profiles but i can only ave there name and not the avater displayed here is the code ive got which doesnt work <? $picture = mysql_query("SELECT * FROM users WHERE username = '$dip->person'"); $pc = mysql_fetch_object($picture); $query_friends=mysql_query("SELECT * FROM friends WHERE username='$viewuser' AND type='Friend'"); $rows=mysql_num_rows($query_friends); if ($rows == "0"){ echo "<center>No friends</center>"; } $friend = 0; while($dip=mysql_fetch_object($query_friends)){ echo " <img src='$pc->image' width='50' height='50' border='1'><br><a href='profile.php?viewuser=$dip->person'>$dip->person</a>,"; $friend++; echo ($friend % 3 == 0)? "<br>" : ""; } ?> The friends are from the friends database and the avater is from the users database how can i link them so the name and the avater show ive tried this but only the names are displayed and the avaters dont show Hi everyone, I'm trying to select either a class or an id using PHP Simple HTML DOM Parser with absolutely no luck. My example is very simple and seems to comply to the examples given in the manual(http://simplehtmldom.sourceforge.net/manual.htm) but it just wont work, it's driving me up the wall. Here is my example: http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=94468&lschb= I think the HTML is invalid: i cannot parse it. Well i need more examples - probly i have overseen something! If anybody has a working example of Simple-html-dom-parser...i would be happy. The examples on the developersite are not very helpful. your dilbertone Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 Code: [Select] <?php //ob_start(); include "../connect.php"; Header('Cache-Control: no-cache'); Header('Pragma: no-cache'); $UserId=$_POST['UserId']; $UserId = stripslashes($UserId); $UserId = mysql_real_escape_string($UserId); $UserName=$_POST['UserName']; $UserName = stripslashes($UserName); $UserName = mysql_real_escape_string($UserName); $UserFirstName=$_POST['UserFirstName']; $UserFirstName = stripslashes($UserFirstName); $UserFirstName = mysql_real_escape_string($UserFirstName); $UserLastName=$_POST['UserLastName']; $UserLastName = stripslashes($UserLastName); $UserLastName = mysql_real_escape_string($UserLastName); $UserGender=$_POST['UserGender']; $UserGender = stripslashes($UserGender); $UserGender = mysql_real_escape_string($UserGender); $UserLink=$_POST['UserLink']; $UserLink = stripslashes($UserLink); $UserLink = mysql_real_escape_string($UserLink); $UserPicture=$_POST['UserPicture']; $UserPicture = stripslashes($UserPicture); $UserPicture = mysql_real_escape_string($UserPicture); $sql="SELECT * FROM Fb_Profile WHERE UserId='$UserId' and UserName ='$UserName' and UserFirstName ='$UserFirstName' and UserLastName ='$UserLastName' and UserGender ='$UserGender' and UserLink ='$UserLink' and UserPicture ='$UserPicture'"; $result=mysql_query($sql); $count=mysql_num_rows($result); //Lets add a first time active check 0 or 1 if 1 skip and check for update<br /> if($UserId == 'undefined') { return true; } if($count==1) { echo "&msgText=Facebook MySql Copy Successfully!\n"; return false; } else { echo "&msgText=Invalid Login!\n"; //THIS HERE IS WHAT I AM HAVING A PROBLEM WITH, IF STATEMENT STATING THAT IF $UserId IS EMPTY AND THE OTHER VARIABLES RETURN NOTHING BUT IF IS HAS A VALUE IT INSERTS //IF(!empty $UserId) $FB_Profile_Copy = mysql_query("INSERT INTO Fb_Profile(UserId,UserName,FirstName,LastName,Gender,Link,Picture) VALUES('$UserId','$UserName','$UserFirstName','$UserLastName','$UserGender','$UserLink','$UserPicture')"); $FB_BackGround_Copy = mysql_query("INSERT INTO Fb_BackGround(UserId) VALUES('$UserId')"); return false; } ?> Code: [Select] <?php if ( $_SERVER['HTTP_REFERER'] == "http://domain.net/sub/index.php" ) { echo "true"; } else { echo "false"; } ?> is the code i'm using. /sub/index.php redirects to http://domain.net/index.php it's not seeming to work. please help sort out this bug. I think I'm using simple xml wrong I'm trying to read strings of xml and get it to list the "attributes" in the strings but it's not working. How would I read and list the attributes of this string <Address><to>Joshua</to><from>Rockhampton</from><country>Australia</county></Address> It needs to out put a string that can be printed and look like (or something like) to:Joshua from:Rockhampton country:Australia All my code produces errors and the page just goes blank and I don't know what is wrong.l Im trying to parse this xml but i can get it to output a simple string, can someone see what im doing wrong?? Code: [Select] $str = "<channel><item> <id>cb-uA4QHmpDxYdpgW1jPwiYsUwjBViwlinS</id> <title>Rules of Engagement - Play Ball Extended Preview - Season 5 - Episode 12</title> </item> </channel>"; $n_data = new SimpleXmlElement($str, LIBXML_NOCDATA); foreach ($n_data->channel->item as $d) { $vid = $d->id; $title = $d->title; print_r($d->title); //testing die(); //testing $arr2[] = array('vid' => $vid, 'title' => $title, 'site_id' => 10 ,'time' => 456); } The print_r() returns Code: [Select] SimpleXMLElement Object ( [0] => Rules of Engagement - Play Ball Extended Preview - Season 5 - Episode 12 ) If i simply echo $d->title it returns a string, but i need to reapply $d->title to another array as shown above Have tried to do this myself all day now and i`m getting a little frustrated now. I have a contact form with a select box which can have multiple options selected, i`m using formmail.php to process the info. Problem is I have forgot how to list the values within the array and format them within the email body. $licences is the multiple select box any help would be gratefully received!! Code: [Select] <?php $name=addslashes($_POST['name']); $email=addslashes($_POST['email']); $town=addslashes($_POST['town']); $phone=addslashes($_POST['phone']); $licences=addslashes($_POST['licences']); $message=addslashes($_POST['message']); // you can specify which email you want your contact form to be emailed to here $toemail = "admin@mysite.com"; $subject = "Question : mysite.com"; $headers = "MIME-Version: 1.0\n" ."From: \"".$name."\" <".$email.">\n" ."Content-type: text/html; charset=iso-8859-1\n"; $body = "Name: ".$name."<br>\n" ."Email: ".$email."<br>\n" ."Town/City: ".$town."<br>\n" ."Phone: ".$phone."<br>\n" ."Interested in Licence/s: ".$licences."<br>\n" ."Message:<br>\n" .$message; if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email)) { echo "That is not a valid email address. Please return to the" ." previous page and try again."; exit; } mail($toemail, $subject, $body, $headers); echo "Thanks for submitting your message."; ?> I am trying to write a PHP page that takes an XML file stored on an external server, parses it, and rewrites the data to a new XML file formatted to my liking. The feed is for events and has about 250 events to parse. The problem is that if one event has an empty node, the script will use the same event data for the node used previously. Upon research, I see that empty nodes are parsed as an empty SimpleXMLElement Object. See my code for example: XML Original: Code: [Select] <event_info> <event id="1222209"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>102.9 FM</radio> <sched_opp><![CDATA[Toledo]]></sched_opp> </event> <event id="1222210"> <outcome_score><![CDATA[]]></outcome_score> <quotes></quotes> <radio>107.1 FM</radio> <sched_opp><![CDATA[Ohio]]></sched_opp> </event> </event_info> Output XML (note <outcome_score> on second event): Code: [Select] <event_info> <event id="1222209"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>102.9 FM</radio> <sched_opp><![CDATA[Toledo]]></sched_opp> </event> <event id="1222210"> <outcome_score><![CDATA[L, 1-0 (OT)]]></outcome_score> <quotes></quotes> <radio>107.1 FM</radio> <sched_opp><![CDATA[Ohio]]></sched_opp> </event> </event_info> PHP code: $xml = simplexml_load_file($source); echo "<event_info>"; foreach($xml->event as $event) { echo "<event>"; if($event->outcome_score != '') { echo "<outcome_score><!CDATA[{$event->outcome_score]]></outcome_score>"; } if($event->quotes != '') { echo "<quotes><!CDATA[{$event->quotes]]></quotes>"; } } if($event->radio != '') { echo "<radio><!CDATA[{$event->radio]]></radio>"; } if($event->sched_opp != '') { echo "<sched_opp><!CDATA[{$event->sched_opp]]></sched_opp>"; } echo "</event>"; } echo "</event_info>"; Basically, whenever an event has no outcome score, the most recent outcome score is repeated for all events after. Any help would be greatly appreciated! Thanks! Please .i want php code to get metacfe thumbnail from url this is the url http://www.metacafe.com/watch/5823413/the_sinister_eyes_of_dr_orloff_movie_trailer/ php code to grab 5823413 for thumbnail links this http://www.metacafe.com/thumb/5823413.jpg Hi Guys
I'm updating my website and I'm stumped on the last section. I have a dynamic Table with various fields showing from Mysql, I use MS Access as a front end, and I have a field named Download, I enter the file location of a customers invoice and it stores the link in mysql, works perfectly. BUT, the dynamic table looks like this: Download - \users\MM4512\Invoices\Invoice23.PDF which is hyperlinked so they can download it etc.. Is there a way I can change this section from the above to a simple (Download Invoice) instead of all that text? The code used is : <td><a href="<?php echo $row_Invoices['download']; ?>" target="_blank"><?php echo $row_Invoices['download']; ?></a></td> Hello, i am newbie at PHP codes and i need help little! How to limit of chars of song? I uploaud an images and post php code! $fp_data = ereg_replace("^.*<body>","",$fp_data); $fp_data = ereg_replace("</body>.*","",$fp_data); list($currentlisteners,$status,$peak,$max,$reported,$bit,$song) = explode(",", $fp_data, 7); if($showsong == '1') { $stationinfo = ' '.$currentsong.' '.$song.' '; } if($showlisteners == '1') { $stationinfo = $stationinfo.' '.$currentlisteners.' of '.$peak.' '.$listenerlabel.' '; } } } // Include the layout for display require(JModuleHelper::getLayoutPath('mod_ngs_shoutcast')); ?> Thank you! |