PHP - Simple Else Statement
I'm usng this simple script to remove a row from a MySQL table:
Code: [Select] <?php $id = "123456789"; $pass = "bach"; $query = "DELETE FROM my_form WHERE member = ('$id') && password = ('$pass')"; $result = mysql_query($query); echo "The data has been deleted."; ?> Works as intended, if the password and ID match, then the row is deleted and it echos "The data has been deleted." I want to add an "else" statement... the the password and ID did not match, "the data has NOT been deleted". I know I can't use "else" if I don' begin with an "if"... but I'm not sure where to put it (after the query?) Thank you. Similar TutorialsI'm trying to work out a count of how many of what assets are in a certain location: there should be 13 different categories (asset types) in a location and i want the individual count of each category. here's what i have - which seems to give me a total count of all assets and locations together plus one asset description and one location..... almost right. Code: [Select] $con = mysql_connect('localhost','root',''); if(! $con) die(mysql_error()); mysql_select_db("test",$con); $result = mysql_query("SELECT DISTINCT COUNT(`Asset Description`) AS TOTALAD, LOCATION, `Asset Description` AS AD FROM master WHERE LOCATION like 'NC%'"); while($row = mysql_fetch_array($result)) { echo $row["LOCATION"]; echo "<br />"; echo $row["TOTALAD"]; echo "<br />"; echo $row["AD"]; echo "<br />"; } mysql_close($con); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=322930.0 what am i doing wrong? <?php $input_value = a tall order; if ( $input_value == a tall order ) { echo 'Correct!'; } if ( $input_value = err on the side of caution ) { echo 'correct!'; } else { echo 'Sorry, try again.'; } ?> also, once i get this to work i want it to be able to have the input value be a submit form in HTML so that anything the user puts in the box will go through this piece of code to decide what to do with what they put in. Thanks! This topic has been moved to Other Programming Languages. http://www.phpfreaks.com/forums/index.php?topic=354391.0 Hello, I'm pulling data from a table in order to pre-populate a form. I have either a "school" address or a "home "addresses" for each record in the table. I've already connected to the table and made the query... what I need to do now is simply create an "else" statement. If the value "Address_type" is "school", pre-populate the form... if it's not "school" then display an empty form: I think I've got the idea, but my syntax can't be right: Code: [Select] <?php if ($Address_type = 'school') { ?> School address street</b>: <input type="text" name="Address_street" value="<?php echo stripslashes($row['school_address']); ?>" /> School address city</b>: <input type="text" name="Address_city" value="<?php echo stripslashes($row['school_city']); ?>" /> School address state</b>: <input type="text" name="Address_state" value="<?php echo stripslashes($row['school_state']); ?>" /> School address zipcode</b>: <input type="text" name="Address_zip" value="<?php echo stripslashes($row['school_zip']); ?>" /> <?php }else { ?> School address street</b>: <input type="text" name="Address_street" /> School address city</b>: <input type="text" name="Address_city" /> School address state</b>: <input type="text" name="Address_state" /> School address zipcode</b>: <input type="text" name="Address_zip" /> <?php } ?> I'm having issues with the following: Code: [Select] <?php session_start(); $_SESSION['username']=$_POST['username']; $_SESSION['password']=$_POST['password']; if($_SESSION['username']=="username" && $_SESSION['password']=="password"){ if($_GET['product']=="add"){ $content.=' <p><label>Product Name:</label> <input type="text" name="product_name" size="30" /> <label>Product Price:</label> <input type="text" name="product_price" size="5" /> </p> <p><label>Product Category:</label> <input type="text" name="product_category" size="30" /></p> <p><label>Product Link:</label> <input type="text" name="product_link" size="30" /></p> <p><label>Product Image:</label> <input type="text" name="product_image" size="30" /></p> <p><label>Product Tag:</label> <input type="text" name="product_tag" size="30" /></p> <p><label>Product Keywords:</label> <input type="text" name="keyword" size="30" /></p> <p><label>Product Features:</label><br /> <textarea name="product_features" rows="10" cols="60"></textarea> </p> <p><label>Product Pros:</label><br /> <textarea name="product_pros" rows="5" cols="30"></textarea> </p> <p><label>Product Cons:</label><br /> <textarea name="product_cons" rows="5" cols="30"></textarea> </p> <p><label>Product Description:</label><br /> <textarea name="product_description" rows="10" cols="60"></textarea> </p> <p><label>Product Notes:</label><br /> <textarea name="product_notes" rows="5" cols="30"></textarea> </p> '; $logout='<div><a href="./acp_admincp.php?log-out">Log-Out</a></div>'; } elseif($_GET['product']=="view"){ } else{ $content.=' <a href="./admincp.php?product=add">Add New Product</a> <br /> <a href="./admincp.php?product=view">View Products</a> '; } } elseif(isset($_GET['log-out'])){ session_start(); session_unset(); session_destroy(); header("Location: ./admincp.php"); } else{ $content=' <form action="./admincp.php" method="post"> <p><label>Username:</label> <input type="text" name="username" size="30" />'; $content.='</p> <p><label>Password:</label> <input type="password" name="password" /></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <base href="http://ghosthuntersportal.com/" /> <title>Ghost Hunter's Portal - Admin Control Panel</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="verify-v1" content="" /> <meta name="keywords" content="ghost, hunters, hunter, ghosts, spirit, spirits, paranormal, investigation, investigator, investigators, k2, emf, meter, kii" /> <meta name="description" content="Ghost Hunters Potal. Parnormal research equipment store." /> <meta name="author" content="Andrew McCarrick" /> <meta name="robots" content="index, follow" <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <img src="./logo.png" alt="Ghost Hunter's Portal Admin Control Panel" /> <br /> <div style="color: #AA44AA; font-size: 26px; margin-top: -30px; margin-left: 125px;">Admin Control Panel</div> <?php echo $logout; echo $content; ?> </body> </html> I can log-in, and get to the page with the two links on it. However, once I click one of the links it falls back to the log-in page, and it ends up being a never ending loop. It's doing this: Log-In --> Page with links ---> Log-In page again Should be doing this: Log-In --> Page with links --> Add Product page or View Products page I can never get into the the actual sub page. Just to be clear, the address bar actually shows product=add or product=view, but it still shows the log-in page. Hello Everyone, I have to change the if statements to a switch statement, in this game. Can anyone help? Thanks. var checkKeyPressed = function (e) { // Press key A or key D to make dog run to the left or right // The running speed is specified by the step variable, 10 by default. // If you replace 10 with a larger integer, the dog will run faster. //press A, dog runs left if (e.keyCode == "65") { if (prex[0] > 5) { prex[0] = prex[0] - step; } } //press D, dog runs right if (e.keyCode == "68") { if (prex[0] < right) { prex[0] = prex[0] + step; } } }; 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 I have a table on a page that displays info from a database and everything is working fine but I want it so if the user entered data from another page to a certain field then the row on my data display table will turn red. Right now I have a If statement in every row of my table. Is it possible to have two if statements in a row? Here is my page code with the table. <? include "include/session.php"; include "include/z_db.php"; ?> <? require "bottom.php"; ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> </head> <!-- <body bgcolor="#339999"> --> <body bgcolor="white"> <img src="logo.jpg" width="197" height="193" align="right"><br /><br /><br /><br /><br /> <br /><br /><br /><br /><br /> <FORM> <INPUT TYPE="BUTTON" VALUE="New Tour" ONCLICK="window.location.href='http://www.integranite.net/EAToursDemo/Input.php'"> </FORM> <?php $result = mysql_query("SELECT * FROM Project"); ?> <div style="overflow:auto; height:30px; width:1650px"> <?php echo "<table border='1'> <tr> <th width='200'>School</th> <th width='200'>Teacher</th> <th>First Contact start date</th> <th>Development Start</th> <th>Development End</th> <th>Pricing Start</th> <th>Pricing End</th> <th>Marketing Start date</th> <th>Price Based On</th> <th>Trip Assigned To</th> <th>Trip Made</th> <th width='104'>Notes</th> </tr>"; echo "</table>"; echo "</div>"; ?> <div style="overflow:auto; height:400px; width:1650px"> <?php while($row = mysql_fetch_array($result)) { $checkbox = ''; if ($row['TripMade'] == 1) $checkbox = ' checked'; ?> <!--<div style="overflow:auto; height:40px; width:155px">--!> <table cellpadding="0" cellspacing="0" style="width:50px;"> <?php echo "<table border='1'>"; echo "<tr>"; echo "<td width='200'>" .$row['School'] . "</td>"; echo "<td width='200'>" .$row['Teacher'] . "</td>"; if(!strcmp($row['dtFirstContactSt']&& $row['dtMarketingSt'] , '0000-00-00' && '0000-00-00')) { echo "<td width='156'>" . "  </td>"; } else { echo "<td bgcolor=FF0000 width='156'>" .$row['dtFirstContactSt']. "</td>"; } if(!strcmp($row['dtDevelopmentSt'], '0000-00-00')) { echo "<td width='126'>" . "  </td>"; } else { echo "<td width='126'>" .$row['dtDevelopmentSt']. "</td>"; } if(!strcmp($row['dtDevelopmentEnd'], '0000-00-00')) { echo "<td width='119'>" . "  </td>"; } else { echo "<td width='119'>" .$row['dtDevelopmentEnd']. "</td>"; }; if(!strcmp($row['dtPricingSt'], '0000-00-00')) { echo "<td width='83'>" . "  </td>"; } else { echo "<td width='83'>" .$row['dtPricingSt']. "</td>"; } if(!strcmp($row['dtPricingEnd'], '0000-00-00')) { echo "<td width='76'>" . "  </td>"; } else { echo "<td width='76'>" .$row['dtPricingEnd']. "</td>"; } if(!strcmp($row['dtMarketingSt'], '0000-00-00')) { echo "<td width='142'>" . "  </td>"; } else { echo "<td width='142'>" .$row['dtMarketingSt']. "</td>"; } echo "<td width='104'>" .$row['PriceBasedOn']. "</td>"; echo "<td width='115'>" .$row['TripAssignedTo']. "</td>"; ?> <td width="72"><input type="checkbox" name="TripMade" value="Yes" <?= $checkbox ?>></td> <td><textarea name="Notes" rows="1" cols="10"><?php echo $row["Notes"]?></textarea> </td> <?php echo "<td>" . "<a href=Edit_Form.php?UniqueIdentifier=$row[UniqueIdentifier]> Edit </a></td>"; echo "</tr>"; } echo "</table>"; echo "</div>"; mysql_close($con); ?> <br /> <meta name="GENERATOR" content="Arachnophilia 4.0"> <meta name="FORMATTER" content="Arachnophilia 4.0"> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <center> </body> </html> The first IF statement is what i am trying to do but just dont know how to code it. I know its kind hard to understand but any help is appreciated. Can someone write me some simple code to check to see if the url has the word "soundcloud" in them. This is what I want to do.... This is my code now... Code: [Select] echo " <h3> $title - $author</h3> </br> <iframe width='640' height='360' src='$link' frameborder='0' allowfullscreen></iframe> </br> </br> $message </br> <font color='#8b8d9b' size='1'>Posted By: $username $date</font> </br></br></br></br></br> "; However I want to pull the link value out of the database and see if it contains the word "soundcloud" and if it does do this...(note the height is changed) Code: [Select] echo " <h3> $title - $author</h3> </br> <iframe width='640' height='100' src='$link' frameborder='0' allowfullscreen></iframe> </br> </br> $message </br> <font color='#8b8d9b' size='1'>Posted By: $username $date</font> </br></br></br></br></br> "; Any help would be greatly appreciated. I have a simple if statment issue. Here is the code <?php $address = $User['address_l1']; if (empty($address)) { echo "You have not entered an address";} else {echo "You Have entered an address";} ?> The variable $address in this case is not empty so it should echo you HAVE entered an address but its echoing NOT. Can somebody please explain why this is not working? need a little of help if i click on a users profile and they are on the freinds list i need to echo profile with the send message link if not echo the profile with the contact request link. this my code so far but i get an Parse error: syntax error, unexpected T_ELSE Code: [Select] <?php session_start(); $myusername=$_SESSION['myusername']; $getuname=$_POST['to_user']; $amessage =" is Checking you out "; $message=$_POST['message']; require "database.php"; $queryuser=mysql_query("SELECT * FROM freinds WHERE username='$myusername' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0){ if (!isset($_GET['username'])) { $data = mysql_query("SELECT * FROM users LEFT JOIN status ON status.username=users.username WHERE status.username = '".$_SESSION['myusername']."' ORDER BY id DESC LIMIT 1;") or die(mysql_error()); } else { $getuname = mysql_real_escape_string($_GET['username']); $data = mysql_query("SELECT * FROM users LEFT JOIN status ON status.username=users.username WHERE status.username = '".$getuname."' ORDER BY id DESC LIMIT 1;") or die(mysql_error()); } while($info = mysql_fetch_array( $data )) { ?> <!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> <link href="css/main.css" rel="stylesheet" type="text/css"> </head> <body> <div class="header"> <img name="Untitled1" src="Untitled-1.gif" width="1000" height="40" border="0" id="Untitled1" usemap="#m_Untitled1" alt="" /><map name="m_Untitled1" id="m_Untitled1"> <area shape="rect" coords="874,0,931,40" href="eurochat.php" alt="" title="Euro Chat"/> <area shape="rect" coords="828,0,865,40" href="englandchat.php" alt="" title="UK Chat"/> <area shape="rect" coords="754,0,822,40" href="usachat.php" alt="" title="USA Chat"/> <area shape="rect" coords="201,21,242,40" href="search.php" alt="" title="Profile Search" /> <area shape="rect" coords="697,0,747,40" href="http://datenight.netne.net/ausnz.php" alt="" title="AU n NZ Chat" /> <area shape="rect" coords="167,20,201,40" href="http://datenight.netne.net/inbox.php" alt="" title="Inbox" /> <area shape="rect" coords="119,21,164,40" href="http://datenight.netne.net/login_success.php" alt="" title="Home"/></map> </div> <div class="profile"> <? //Outputs the image and other data Echo '<a href="freinds.php?username=' . "$getuname" . '">Contact request</a>'; Echo '<a href="new_message.php?username=' . "$getuname" . '">send meesage</a>'; Echo "<img src='http://datenight.netne.net/images/".$info['img'] ."' width='150' height='150''> <br>"; Echo "<b>Name:</b> ".$info['username'] . "<br> <hr>"; Echo "<b>Sex:</b> ".$info['sex'] . " <br><hr>"; Echo "<b>Intrested in</b>" . "<br><hr>"; Echo "".$info['rel'] . " "; Echo "".$info['frwb'] . " "; Echo "".$info['ons'] . " "; Echo "".$info['fr'] . "<br><hr>"; Echo "<b>About me:</b> ".$info['aboutme'] . "<br><hr> "; Echo "<b>Looking for:</b> ".$info['looking'] . " <br><hr>"; Echo "<a href='login_success.php'>'Back'</a>"; else { Echo '<a href="freinds.php?username=' . "$getuname" . '">Contact request</a>'; Echo '<a href="new_message.php?username=' . "$getuname" . '">send meesage</a>'; Echo "<img src='http://datenight.netne.net/images/".$info['img'] ."' width='150' height='150''> <br>"; Echo "<b>Name:</b> ".$info['username'] . "<br> <hr>"; Echo "<b>Sex:</b> ".$info['sex'] . " <br><hr>"; Echo "<b>Intrested in</b>" . "<br><hr>"; Echo "".$info['rel'] . " "; Echo "".$info['frwb'] . " "; Echo "".$info['ons'] . " "; Echo "".$info['fr'] . "<br><hr>"; Echo "<b>About me:</b> ".$info['aboutme'] . "<br><hr> "; Echo "<b>Looking for:</b> ".$info['looking'] . " <br><hr>"; Echo "<a href='login_success.php'>'Back'</a>"; } } mysql_query("INSERT INTO alog (from_user, to_user, message ) VALUES ('$myusername', '$getuname','$amessage')") OR die("A log error <br>".mysql_error()); ?> </div> </body> </html> hi how do u do a if statement so that if <a href="TaxiEntry1.php?Quote_ID='.$qid.'">Accept</a> is clicked then update this field in this table } thanks I'm just trying something new out here and wanted to know how it looked AND I'm having a hard time figuring out how to accomplish this with the else statement. Obviously on the else it would mean that there was already a template with the same name existing in the database table so I want the user to be sent back to the original form and I'll implement a jquery dialog box telling the user that there is already an existing template with that name. if (isset($_POST['edittemplate'])) { $templatename = mysqli_real_escape_string($dbc, $_POST['templatename']); $headercode = mysqli_real_escape_string($dbc, $_POST['headercode']); $footercode = mysqli_real_escape_string($dbc, $_POST['footercode']); $templateID = (int)$_POST['templateID']; $query = "SELECT * FROM `templates` WHERE `templatename` = $templatename"; $result = mysqli_query ( $dbc, $query ); // Run The Query $rows = mysqli_num_rows($result); if ($rows == 0) { $query = "UPDATE `templates` SET `templatename` = '$templatename', `headercode`='".$headercode."', `footercode`='".$footercode."' WHERE `id` = '$templateID'"; mysqli_query($dbc,$query); } else { } } hi all I am trying to process a result from a query but cant use a echo in a while statement Here is the code I am trying to get the result from each row in the table and then display them I get the error Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\blackrain\Resources\read.php on line 13 <?php $link = mysql_connect('localhost', 'root', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("php"); $rs = "SELECT `id`, `title`, `author`, `date`, `imageUrl`, `text` FROM `items` "; $rs_return = mysql_query($rs) or trigger_error($rs . ' has encountered an error: <br />'. mysql_error()); while($obj = mysql_fetch_array($rs_return, MYSQL_ASSOC)) {" <h1>"+ echo $obj['title']; +"</h1> <div id="+"wrapper"+"> <div id="text"> <h4>Posted:"+ echo $obj['author'];+"By:"+ echo $obj['date'] +"</h4> <p class="p3"> <span> <img class="+"alignright"+"src="+ echo $obj['imageUrl'];+"> </img>"+ echo $obj['text'];+"</span></p>" } ?> Hello I'm hoping someone here can help me with this. I know very little PHP I'm afraid but I think what I want to do is fairly basic and should be relatively simple. I have a footer which is referenced on each page of the site with <?php include($DOCUMENT_ROOT."/includes/php/footer.php"); ?> Within the footer I want it so that if it's the home page (default.php) it displays just the footer but for any other page I want it to display a Div and then the footer. Here is what I have so far but it isn't working: <?php if ($_SERVER['REQUEST_URI'] == "default.php") { ?> <!--Home Page Footer--> <div class="footer"> <div class="footer1"> </div> <div class="footer2"> </div> <div class="footer3"> </div> <div class="footerLinks"> <?php include($DOCUMENT_ROOT."/includes/php/bottomlinks.php"); ?> </div> <div class="footer4"> </div> </div> <?php } else { ?> <!--Blue Footer Image--> <div class="footer2"> </div> <!--Footer--> <div class="footer"> <div class="footer1"> </div> <div class="footer2"> </div> <div class="footer3"> </div> <div class="footerLinks"> <?php include($DOCUMENT_ROOT."/includes/php/bottomlinks.php"); ?> </div> <div class="footer4"> </div> </div> <?php } ?> I don't know that the request uri address is correct but when I've tried to use 'echo $_SERVER['REQUEST_URI']' to find out what it should be I can't get that to work either. I'm new here, this is my first post. Sorry if it's too basic or I've made a forum faux pas. Any help would be extremely appreciated. |