PHP - Simple Issue
Hello,
I don't have any php knowledge and am having a hard time trying to implement the following: - a drupal node is getting a numeric parameter with the URL in the following form "http://the.url/?X=123" - what I want is for the script to check if the value has been passed with the URL, then use it in a form... if the entered URL was "http://the.url" without the X variable, then use a default value of 321. <?php $_GET['X']; if (isset($X)) { print $X ; } else print "321" ?> Thanks in advance for your help. Similar TutorialsI have this simple piece of code. I am using GET[] to retrieve the catID from URL, then match it and set a backgorund image, some backgorund images can change per catID variable. When selected or clicked on. It is not working, it is producing the catId in ech $_Get[], but not matching it with $filename to set correct Image. Ex. Browser catID may == 1, it code displays catid = 1, file name = deals_2.jpg. This is worng. should be catid = 1 , filename = 1. PLEASE HELP, missing something. Code: [Select] <?php $imgpath = '/shushmedeals/templates/shushme_deals/images/'; //$bgimgID = $item->id; $bgimgID = isset($_GET['categoryId']); $bgimgID = $_GET['categoryId']; echo $bgimgID; //echo 'shoot her eman'; //echo $imgpath; if($bgimgID){ $bgimgID = 1; $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } if($bgimgID = 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } if($bgimgID = 3){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img2.jpg'; } else { $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img3.jpg'; } if($filename){ echo '<br>'.$filename; // SET COOKIE //setcookie('bgimg', $filename); //echo $_COOKIE['bgimg']; } else { echo "There is no Background for this category"; // DO NOT SET COOKIE } // Print an individual cookie echo $_COOKIE["location"]; ?> I am trying to recursively pull records from a database to write to a csv. There are three test rows of data in my table (and no not including the table headers). The only issue is i can’t seem to get my for loop to display all the records – it only displays the last 2 rows so i’m very confused. Anyone suggest why this isn’t working? Code: [Select] $num_rows = mysql_num_rows($export); for ($i=0; $i <= $num_rows; $i++ ) { $row = mysql_fetch_row($export); echo $row[1] . $row[2] . $row[3] . $row[4] . $row[5] . $row[6] ."<br/>"; echo $i; } Incidentally the query is just a fetch all from datasbase. Anyone see where i'm going wrong? Thanks, drongo Hi, I'm trying to make an error message appear when a user misses a text field, or fills in an error. All the errors are sent to a form.php, this then sends the error message back to the current page. Here is the code I am using to retrieve the error message: if($form->error = ("user")){ echo $form->error("user"); } if($form->error = ("pass")){ echo $form->error("pass"); } Which works fine, but I only want ONE error message to be displayed at a time. This IS what I want: There are two fields, user, and password. If the user fails to enter anything into both, only one error message will appear "Please enter your username" (which is what the form.php does). When the user fills in the username, but fails to fill in the password then it works, only one error message appears (as there is only one error to send) When the user fills in the password, but fails to fill in the username it also works, only one error message appears. Its just when the user fails to fill in either, it prints both error messages when I only want it to print the 'user' error message. Please help, Thanks Hi All, I'm trying to debug my first few lines of PHP where I have all my "checks" to make sure someone is logged in. I have this code all by itself and it is still not executing. This is the only page that I'm having trouble with. header('Location: login.php?logout=1'); Error... Parse error: syntax error, unexpected T_ELSE in /home/smileits/public_html/space/webmin/install.php on line 15 Code... Code: [Select] <?if ($_GET['a'] == "") {?><br><br><div align="center"><h2>Welcome to aWebBB</h2><br><br>After editing the configuration file located at /forum/config.php and created a database named 'awebbb_forum' (or different) please click <a href="install.php?a=install">here</a> to install.<br></div><?} else { }if ($_GET['a'] == "install") {echo "Installing MYSQL Tables...<br>";include "../config.php";$db = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $query = 'CREATE TABLE `fcat` ( `id` int(11) NOT NULL auto_increment, `category` varchar(50) default NULL, `description` varchar(250) default NULL, PRIMARY KEY (`id`))';$result = mysql_query($query); echo "Created Categories Table<br>";$query2 = 'CREATE TABLE `flist` ( `id` int(11) NOT NULL auto_increment, `tid` varchar(50) default NULL, `categories` varchar(30) default NULL, `tname` varchar(100) default NULL, `poster` varchar(50) default NULL, `date` date default NULL, PRIMARY KEY (`id`))';$result2 = mysql_query($query2); echo "Created Thread List Table<br>";$query4 = 'CREATE TABLE `forum` ( `id` int(11) NOT NULL auto_increment, `tid` varchar(50) default NULL, `categories` varchar(30) default NULL, `tname` varchar(100) default NULL, `poster` varchar(30) default NULL, `fpost` text, `sig` varchar(150) default NULL, `avatar` varchar(150) default NULL, `time` time default NULL, `date` date default NULL, PRIMARY KEY (`id`))';$result4 = mysql_query($query4); echo "Created Main Fourm Table<br>";$query5 = 'CREATE TABLE `prefs` ( `id` int(11) NOT NULL auto_increment, `sitename` varchar(99) default NULL, `forumname` varchar(99) default NULL, `sitetitle` varchar(99) default NULL, `menulink` varchar(11) default NULL, `normallink` varchar(11) default NULL, `defimage` varchar(150) default NULL, `defsig` varchar(150) default NULL, `backcolor` varchar(20) default NULL, `msitecolor` varchar(20) default NULL, `siteurl` varchar(150) default NULL, `headimage` varchar(150) default NULL, `hiwidth` varchar(4) default NULL, `hiheight` varchar(4) default NULL, `forumcolor` varchar(11) default NULL, `normaltext` varchar(11) default NULL, `copyright` varchar(150) default NULL, `email` varchar(100) default NULL, `adenable` varchar(11) default NULL, `adcode` text, `adlocation` varchar(20) default NULL, PRIMARY KEY (`id`))';$result5 = mysql_query($query5); $query7 = "INSERT INTO `prefs` VALUES (1, 'Site Name', 'Forum Name', 'Title of your site', 'white', 'blue', 'images/world.jpg', 'Love Life', 'white', 'blue', '', 'images/logo1.jpg', '700', '80', 'white', 'black','','','','','');"; mysql_query($query7); echo "Created Preferences Table<br>";$query6 = 'CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `level` char(2) default NULL, `username` varchar(20) default NULL, `password` varchar(20) default NULL, `emailadd` varchar(50) default NULL, `fullname` varchar(40) default NULL, `country` varchar(30) default NULL, `date` date default NULL, `sig` varchar(150) default NULL, `avatar` varchar(150) default NULL, PRIMARY KEY (`id`))';$result6 = mysql_query($query6); echo "Created Users Table<br>"; $query7 = 'CREATE TABLE `menu` ( `id` int(11) NOT NULL auto_increment, `bname` varchar(50) default NULL, `link` varchar(200) default NULL, PRIMARY KEY (`id`) )'; $result7 = mysql_query($query7); echo "Created Menu Table<br>";echo '<meta http-equiv="refresh" content="1;url=install.php?a=users">'; } else { }if ($_GET['a'] == "users") {?>Please Create the Administrative User Account:<br><br><style type="text/css"><!--div.error-box {width:200px; background:pink; margin-top: 2px; border: 1px solid red; text-align: center;}//--></style><?$a=$_GET['b'];if ($a == "skyreg" ) {$fullname=$_POST['fullname'];$username=strtolower($_POST['username']); $password1=$_POST['password1'];$password2=$_POST['password2'];$emailadd=$_POST['emailadd'];$country=$_POST['country'];if ($fullname == "") {$fullnamebox="<div class=\"error-box\">";$fullnamebox1="</div>";} else { }if ($username == "") {$usernamebox="<div class=\"error-box\">";$usernamebox1="</div>";} else { }if ($password1 == "") {$pword1box="<div class=\"error-box\">";$pword1box1="</div>";} else { }if ($password2 == "") {$pword2box="<div class=\"error-box\">";$pword2box1="</div>";} else { }if ($emailadd == "") {$emailaddbox="<div class=\"error-box\">";$emailaddbox1="</div>";} else { }if ($country == "") {$countrybox="<div class=\"error-box\">";$countrybox1="</div>";} else { }if ($fullname == "" OR $username == "" OR $password1 == "" OR $password2 == "" OR $emailadd == "" OR $country == "") {$errormessage="<font color=\"red\">Please Fill in all Feilds.</font><br>";} else { include "../config.php";$db12 = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $query12 = "SELECT username FROM users WHERE username = '$_POST[username]'"; $result12 = mysql_query($query12); while($r=mysql_fetch_array($result12)) { $username12=$r["username"]; }if ($username12 == $username) {$errormessage3="<font color=\"red\">The username chosen is in use, choose another.</font>";} else { if ($password1 == $password2) {$fullname=$_POST['fullname'];$username=strtolower($_POST['username']); $password=$_POST['password1'];$emailadd=$_POST['emailadd'];$schoolyear=$_POST['schoolyear'];$country=$_POST['country'];$defsig1=$_POST['defsig'];$defimage1=$_POST['defimage'];include "../config.php"; // As you can see we connected to the database with config$db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $query = "INSERT INTO users(level, username, password, emailadd, fullname, country, date, sig, avatar) VALUES('1', '$username','$password','$emailadd','$fullname', '$country', now(), '$defsig1', '$defimage1')"; mysql_query($query); echo "Account Created";echo '<meta http-equiv="refresh" content="1;url=install.php?a=done">'; mysql_close($db); } else {$errormessage2="<font color=\"red\">Passwords Entered do not Match.</font>";}}mysql_close($db12);}} else { }if ($a != "skyreg" OR $a != "reg") { ?><div align="center"><?=$errormessage;?><?=$errormessage2;?><?=$errormessage3;?><br><form method="post" action="install.php?a=users&b=skyreg"><input type="hidden" name="defimage"><input type="hidden" name="defsig"><?=$fullnamebox;?>Full Name:<br><input type="text" name="fullname"><br> <?=$fullnamebox1;?><?=$usernamebox;?>Username:<br><input type="text" name="username"><br> <?=$usernamebox1;?><?=$pword1box;?>Password:<br><input type="password" name="password1"><br> <?=$pword1box1;?><?=$pword2box;?>Retype Password:<br><input type="password" name="password2"><br> <?=$pword2box1;?><?=$emailaddbox;?>E-mail Address:<br><input type="text" name="emailadd"><br> <?=$emailaddbox1;?><?=$countrybox;?>Country:<br><input type="text" name="country"><br> <?=$countrybox1;?><input type="reset" value="Clear Form"> <input type="submit" value="Register"></form></div><? } else { }} else { }if ($_GET['a'] == "done") {?><div align="center"><br><br>All done!!!<br><br>Please procede to the <a href="index.php">Admin section</a> and Edit the <a href="pref_edit.php">site preferences</a>.<br><br><font color="red"><h2>Remember to delete install.php AND upgrade.php for security reasons!!!</h2></font></div><?} else { }?> I cant figure out why im having this problem. i stuck this at the top of my page on its own and it wont update the row to read Code: [Select] <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> I echo $_GET['pm_id']; and that turn out correct and the number matches the pm_id on the row. everything is lowercase I typed read manually into the column and echo that and it showed read also I have this same exact line of code on another script that works fine. does someone see something im over looking? this is driving me crazy http://localhost/stargate/users/view.php?pm_id=1376672&inbox=2 Code: [Select] <?php require("menu.php"); ?> <html> <body> <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> </body> </html> Hi All, I have a simple 'delete record' code that is not working. Would someone please take a gander at it and let me know if they see anything wrong that would prevent it from actually deleting a record. Code: [Select] <?php //connects to the database include ('db_connect.php'); //post variable $pk = $_POST['pk']; //MySQL code to query ---- 'contacts' = table & 'primary_key' = record id # $deleteContact = "DELETE FROM `contacts` WHERE `primary_key` = ".$pk." LIMIT 1"; //excutes query to MySQL $res = mysqli_query($link,$deleteContact); //close connection to database mysqli_close($link); ?> Any help would be great. Thank you. The code below works echo '<script language="javascript">'; echo 'top.location.href = "/breaking-news/bsnewsstorygoeshere/";'; echo '</script>'; this also works echo '<script language="javascript">'; echo 'top.location.href = "http://anywebsite.com";'; echo '</script>'; the problem, is I have a URL listed in a url variable that can be retreived via $_GET['url'] my question is how to get that variable into the above code? I've tried echo '<script language="javascript">'; echo "top.location.href = \"$_GET['url']\";"; echo '</script>'; but that doesnt seem to work, can anyone advise? I have the simple code below which seems to have worked on forms from a contact page on a website. Unfortunately, it seems to only send the forms if all fields are entered. I have played with the code but cannot seem to get it to send any field that has been completed on submit. Can someone help please? <?php $emailAddress = "bigL@gmail.com"; $thankyouPage = ""; session_start(); if (!empty($_POST)) { foreach ($_POST as $key=>$value) { $_POST[$key] = stripslashes($_POST[$key]); $_POST[$key] = htmlspecialchars($_POST[$key],ENT_QUOTES); } } if (isset($_POST['send']) AND isset($_SESSION['msgCount'])) { if ($_SESSION['msgCount'] >= "3") $alert = "Only 3 messages can be s +ent per session."; if (empty($alert)) { $_SESSION['msgCount']++; putenv('TZ=EST5EDT'); // eastern time $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n" +; $message = "<table cellpadding='5' border='1'>"; foreach ($_POST as $key => $value) if (!preg_match("(^send)",$key)) { $value = wordwrap($value,65,"<br />"); $message .="<tr><td><b>$key</b></td><td>$value</td></tr>"; } $message .= "</table>"; $message .= "<br />Time of the message: ".date(" F d h:ia")."<br +/>"; $message .= "IP Address: ".$_SERVER['REMOTE_ADDR']."<br />"; $message .= "Hostname: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])."< +br />"; $subject = $_SERVER['HTTP_HOST']." Message"; mail($emailAddress,$subject,$message,$headers); if (!empty($thankyouPage)) { header('location: '.$thankyouPage); die(); } unset($_POST); $alert = "Your enquiry has been sent, we will respond as soon as p +ossible."; } } if (!isset($_SESSION['msgCount'])) $_SESSION['msgCount'] = 0; ?> 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 Hi, I have this code below which groups all the SubHeading together and then queries the same table to find RiskConsequence which are grouped that match SubHeading then to query this table one more last time with all the Risk Mitigation that matches the grouped RiskConsequence. Problem I get is it does the SubHeading, the RiskConsequences it only does one of them not all of them before it moves onto the RiskMitigation. I know I have a php coding issue just cant see the wood from the tree's as the queries work. Code: [Select] <?php include ("include.php"); $query = "SELECT * FROM tblriskassessmentdatabank GROUP BY SubHeading"; $results = mysql_query($query) or die("Error: " . mysql_error()); while($row1 = mysql_fetch_array($results)){ echo'<a href="#" onClick="return(changeDisplay(';echo"'";echo($row1[SubHeading]);echo"'))";echo'">';echo($row1[SubHeading]);echo'</a><br /><br />'; echo'<div id="';echo($row1[SubHeading]); echo'" class="HideText">'; $risksub = $row1[SubHeading]; $query1 = "SELECT * FROM tblriskassessmentdatabank GROUP By RiskConsequence"; $results1 = mysql_query($query1) or die("Error: " . mysql_error()); while($row2 = mysql_fetch_array($results1)){ echo'<a href="#" onClick="return(changeDisplay(';echo"'";echo($row2[RiskConsequence]);echo"'))";echo'">';echo($row2[RiskConsequence]);echo'</a><br />'; echo'<div id="';echo($row2[RiskConsequence]); echo'" class="HideText">'; $risksub1 = $row2[RiskConsequence]; $query1 = "SELECT * FROM tblriskassessmentdatabank WHERE RiskConsequence = '$risksub1'"; $results1 = mysql_query($query1) or die("Error: " . mysql_error()); while($row3 = mysql_fetch_array($results1)){ echo'<input name="checkbox[]" type="checkbox" id="checkbox[]" value="';echo($row3[IssueNumber]);echo'" /> <label for="checkbox[]"></label>';echo($row3[RiskMitigation]);echo'<br /><br />'; } echo'</div>'; } echo'</div>'; } ?> Folks, I remember once having a php or html5 issue where the first option had to be blank in the drop down. Otherwise, it wasn't working. What wasn't working ? How wasn't working ? I can't remember. either php had difficulty reading user input or the drop down was not showing any options. And so, I had to add a blank value. So, something like this wasn't working ...
<label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <option value="no">No</option> </select>
And, I think I added a blank value, at somebody's advice, to get it to work. I think it was something like this, if I remember correctly:
<label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value=" ">Select here</option> <option value="yes">Yes</option> <option value="no">No</option> </select>
Or, maybe it was something like this:
<label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value=" "></option> <option value="yes">Yes</option> <option value="no">No</option> </select>
I can't remember. All I remember slightly that there was a blank value. I been going through my php files to find that particular file to jog my memory but I failed to find it. Can you folks explain to me if a blank value is required or not ? What is the benefit/disaster of adding it and how should the blank value be added ? Show me an example.
Was this a php or html 5 issue ? Can anybody fugure ?
Thank You 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 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."; ?> 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. 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> 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 |