PHP - If Statement To Overwrite An Image.
Hi,
I've got a FORM Setup. The form has a current image and an option to add a new image (In place of that image) The form fields in question are : Code: [Select] <input type="hidden" name="image_url" value="<?php echo $row_select_propertyimages['image_url']; ?>" /> <input type="file" name="new_image_url" class="inputfile" /> I've setup an IF Statement, to check that if new_image_url ISNT set, then to keep the current image. Otherwise, overwrite it with new_image_url. When I dont choose to upload a new file, The code works correctly. The code is as follows. Code: [Select] if(empty($_POST['new_image_url'])) { $image_url = $row_select_propertyimages['image_url']; } else { $image_url = $_FILES['new_image_url']; } The data then gets input to a Database. But at the moment, It is not overwriting what is currently there. Can anyone help me on this? My full code is : Code: [Select] <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_select_propertyimages = "-1"; if (isset($_GET['image_id'])) { $colname_select_propertyimages = $_GET['image_id']; } mysql_select_db($database_db_connect, $db_connect); $query_select_propertyimages = sprintf("SELECT * FROM image WHERE image_id = %s", GetSQLValueString($colname_select_propertyimages, "int")); $select_propertyimages = mysql_query($query_select_propertyimages, $db_connect) or die(mysql_error()); $row_select_propertyimages = mysql_fetch_assoc($select_propertyimages); $totalRows_select_propertyimages = mysql_num_rows($select_propertyimages); mysql_select_db($database_db_connect, $db_connect); $query_select_property = "SELECT property.property_id, property.property_name FROM property "; $select_property = mysql_query($query_select_property, $db_connect) or die(mysql_error()); $row_select_property = mysql_fetch_assoc($select_property); $totalRows_select_property = mysql_num_rows($select_property); $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "addproperty")) { if(empty($_POST['new_image_url'])) { $image_url = $row_select_propertyimages['image_url']; } else { $image_url = $_FILES['new_image_url']; } echo $image_url; $updateSQL = sprintf("UPDATE image SET image_url=%s, image_desc=%s, image_disphome=%s, image_property_id=%s WHERE image_id=%s", GetSQLValueString($image_url, "text"), GetSQLValueString($_POST['image_desc'], "text"), GetSQLValueString(isset($_POST['image_disphome']) ? "true" : "", "defined","'Y'","'N'"), GetSQLValueString($_POST['image_property_id'], "int"), GetSQLValueString($_POST['image_id'], "int")); mysql_select_db($database_db_connect, $db_connect); $Result1 = mysql_query($updateSQL, $db_connect) or die(mysql_error()); // $updateGoTo = "success_editproperty.php"; // if (isset($_SERVER['QUERY_STRING'])) { // $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; // $updateGoTo .= $_SERVER['QUERY_STRING']; // } // header(sprintf("Location: %s", $updateGoTo)); } ?> Many Thanks in advance. Similar TutorialsHello there, I have some code here which sends a number of variables from flash to SQL... I would simply like to add the functionality to overwrite records which have the same 'name' or 'pseudo'... can anyone help me please ? Thanks in advance Martin <?php $pseudo=$_POST['var1']; $score=$_POST['var2']; $table = $_POST['tab']; $dategame = $_POST['tempjoueur']; //$micro = microtime(); //$dategame = time()."".substr($micro, 2, 6); $_COOKIE['User'] = $_SERVER['REMOTE_ADDR']; $envoie = InsertDatas($table, "name, score, dategame", "'".$pseudo."','".$score."','".$dategame."'"); if ($envoie) { print_r("OK, $pseudo, $score, $dategame,$ipclient"); } else { echo "BAD, $pseudo, $score, $dategame,$ipclient"; } ?> hi all, i have written a seating plan page for my website which allows users to click on a seat and that seat is then allocated to there username, however theres nothing stopping a user changing the URL to a seat thats been taken and "taking" that seat from someone else. heres my code for my reserve_seat.php <?PHP session_start(); /* get user id */ $user_id = $_SESSION['username']; /* get the seat number */ $seat_id = $_GET['seat']; /* connect to data base */ require ('./secure/connect.php'); /* create query */ $query = "UPDATE seats_table set taken = FALSE, user_id = '0' WHERE user_id = '$user_id'"; $query2 = "UPDATE seats_table set taken = TRUE, user_id = '$user_id' WHERE id = '$seat_id'"; /* $query3 = "UPDATE users set signed_up = '3' WHERE username = '$user_id'"; */ /* execute the query */ $result = mysql_query($query); $result2 = mysql_query($query2); /* $result3 = mysql_query($query3); */ /* advise user their seat has been reserved */ include 'seating.php'; ?> so if a user reserves seat 28 the url is http://localhost/reserve_seat.php?seat=26, but theres nothing stopping another user typing this url and "stealing" this seat i need some kind of IF statement before the sql queries that checks to see if the seats "taken" column is 1 or 0 bearing in mind there is 49 seats but im lost at how to write it. any help would be great Lee Hello. i am building a facility for members of my website to upload profile pictures. It works, but what I want to do is have the below script check and overwrite the previous file if they want to update it. As you will see it enforces the image to be named after the username. Code: [Select] function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } $ext = findexts ($_FILES['uploaded']['name']); //$ran = rand () ; $ran2 = $eo_user_name."."; $target = "../images/eoprofile/"; //This assigns the subdirectory you want to save into... make sure it exists! $target = $target . $ran2.$ext; //This combines the directory, the random file name, and the extension if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file has been uploaded as ".$ran2.$ext; } else { echo "Sorry, there was a problem uploading your file."; } Help appreciated. Thanks... hey guys i have this code FILE NAME "index.php" Code: [Select] <?php // make a connection to the database mysql_connect ("localhost", "root", "vertrigo") or die ('Error: I Failed To Connect To The Database ' . mysql_error()); mysql_select_db ("test"); // Get Data $query = mysql_query("SELECT * FROM TestTable"); // display the data and loop while ($row = mysql_fetch_array($query)) { echo "<br /> ID: ".$row['ID']."<br /> First Name: ".$row['FName']."<br /> Last Name: ".$row['LName']."<br /> Contact Number: ".$row['CNumber']."<br />";} ?> <form method="post" action="update.php"> <table border="1" align="center"> <tr> <td align="right" width="220">ID: </td> <td align="left" width="220"> <input type="text" name="ID" size="30" /></td> </tr> <tr> <td align="right" width="220">First Name: </td> <td align="left" width="220"> <input type="text" name="FName" size="30" /></td> </tr> <tr> <td align="right" width="220">Last Name: </td> <td align="left" width="220"> <input type="text" name="LName" size="30" /></td> </tr> <tr> <td align="right" width="220">Contact Number: </td> <td align="left" width="220"> <input type="text" name="CNumber" size="30" /></td> </tr> <tr> <td align="right" width="220"><input type="reset" value="Reset" /> </td> <td align="left" width="220"> <input type="submit" value="Update Database" /></td> </tr> </table> </form> and i also have this code FILE NAME "update.php" Code: [Select] <?php $ID = $_POST['ID']; $FName = $_POST['FName']; $LName = $_POST['LName']; $CNumber = $_POST['CNumber']; mysql_connect ("localhost", "root", "vertrigo") or die ('Error: I Failed To Connect To The Database ' . mysql_error()); mysql_select_db ("test"); $query="INSERT INTO testtable (ID, FName, LName, CNumber)VALUES ('".$ID."','".$FName."', '".$LName."', '".$CNumber."')"; mysql_query($query) or die ('Error Updating Database'); echo "Database Updated Sucsessfully With: ".$ID." ".$FName." ".$LName." ".$CNumber ; ?> ok so the script is working like a charm its sending the data to the database as i want it to. the problem i have is that i want to be able to update the info that is already on the database lets say i want to change a phone/contact number i have typed the ID number into the ID text field and the same first and last name into there correct boxes and then typed in the new phone number i then click submit and i get the error ""Error Updating Database"" i have looked all over the forum and net to see what i have done wrong to not allow this code to update can anyone help me out here please im quite new to the php language and could really do with some pointers thanks Steve Hi every body.I'm new to php and this site.this code I've written is for uploading file and I want it to don't overwrite files with the same name.I thought I told it to with file exists.but doesn't work.can't figure out where the problem is.Sorry for my English and Thanks!
<?php function upload($file,$dest){ $a=explode('.', $file['name']); $filename=$a[0]; $ext=$a[1]; $add=microtime(); if (file_exists($file['name'])) { $filename=$add.$filename.$ext; } if(move_uploaded_file($file['tmp_name'],$dest.$file['name'])){ echo 'File Uploaded'; } print_r($file['name']); } /* Array ( [picture] => Array ( [name] => Chrysanthemum.jpg [type] => image/jpeg [tmp_name] => C:\Users\NOVINP~1\AppData\Local\Temp\php\upload\phpFA89.tmp [error] => 0 [size] => 879394 ) */ ?> <html> <head> <title>File Upload</title> </head> <body> <?php if($_FILES['picture']['name']){ upload($_FILES['picture'],'upload/'); } ?> <form action="" method="post" enctype="multipart/form-data"> <table width="500" align="center"> <tr> <td><input type="file" name="picture"></td> </tr> <tr> <td><input type="submit" value="Upload" name="submit"></td> </tr> <tr> <td><input type="hidden" name="form" value="1"></td> </tr> </table> </form> </body> </html> Hi, I have a page where a user can change his password what i want to acheive is a way of checking the database if the text the user has entered in the textboxes already exist in the db, and if it does exist change a certain part. for example the user goes to the address, types in the email, user name and password twice. if the username and email match in the db i would like the password to write over the old password that was in the db. i keep confusing myself when i think i know what im doing but i keep stumbling. i know this sounds a bit confusing so please ask if you need more understanding. so far ive got: Code: [Select] <?php $n=$_POST['uname']; $e=$_POST['email']; if( $_POST['submitted'] == 'yes' ) { if( $_POST['pass_1'] != $_POST['pass_2'] ) { // fields don't match, so do something to indicate the error . . . echo '<p>Passwords Do Not Match</p>'; } // connect to the db include('config.php'); $query="select * from user where uname='$n' and email='$e'"; $result=mysql_query($query); } ?> <form action="" method="post"> <input type="text" name="uname" id="uname" size="30"> <input type="text" name="email" id="email" size="30"> <input type="password" name="pass_1" /> <input type="password" name="pass_2" /> <input type="hidden" name="submitted" value ="yes" /> <input type="submit" name="submit" value="Change Password" /> </form> just by looking at my code again i think its not right at all, the first php bit is only checking the password textboxes. i think i need to remove my email and username out of that form and put them in another. am i right? sorry im not that good at php or mysql thanks in advance and sorry for such a long read This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=348130.0 I have a form where it will display the image that was uploaded but if there is no image uploaded I would like it to say "No Image" I have this Code: [Select] <img src="../<? echo $rows['imageurl6']; if(!empty($rows)){echo 'No Image';}?>" width="200" /> but it doesn't work. Can someone help me please? Thanks does anyone know how to do an if statement in the middle of a gd image so that if a dropdown box is selected it draws different lines... Code: [Select] <label for="height"></label> <select name="height" id="height"> <option value="2.4">2.4</option> <option value="2.7">2.7</option> </select> </form> <?php require_once('./include/connection.php'); ?> <?php header ("Content-type: image/png"); ?> <?php $x1=$_GET['x1']; $x2=$_GET['x2']; $y1=$_GET['y1']; $y2=$_GET['y2']; $im = @ImageCreate (800, 600) or die ("Cannot Initialize new GD image stream"); $background_color = ImageColorAllocate ($im, 255, 255, 255); $line_color = ImageColorAllocate ($im, 0, 0, 0); // imageline ($im,$x1,$y1,$x2,$y2,$text_color); //front base line if "height" = "2.4" imageline ($im,50,550,500,550,$line_color); else imageline ($im,50,200,500,200,$line_color); endif //front left vertical imageline ($im,50,550,50,200,$line_color); //front right vertical imageline ($im,500,550,500,200,$line_color); //bottom of apex imageline ($im,50,200,500,200,$line_color); //left roof line imageline ($im,50,200,275,100,$line_color); //right roof line imageline ($im,500,200,275,100,$line_color); ImagePng ($im); ?> I am still a novice, but I am working on an idea.
I have a table with a field: judges_ccpadv that contains only 3 possible characters = B, R, or N
My desire is to display a simple little icon for any of those 3 characters.
I tried:
if ($data['judges_ccpadv'] = "B") { echo "<img src='images/b.png'>\n"; } if ($data['judges_ccpadv'] = "R") { echo "<img src='images/r.png'>\n"; } if ($data['judges_ccpadv'] = "N") { echo "<img src='images/n.png'>\n"; } The output is any image that is not in the if statement. So if "B" is in field, r.png and n.png are both displayed. What am I doing wrong here? Assistance is greatly appreciated. Thanks! Hi,
I have the following script which displays a banner image based on a cookie. It also displays a banner if there is no cookie. What I would like to do is to display the banners based on cookies, but instead of displaying the "no-cookie.gif" image, I want to insert some HTML content.
What would be the best way to do this?
$( document ).ready(function() {Thanks! 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; } } }; 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> I need help with my if/else statement. Code: [Select] function show_list() { $query = "SELECT show_id,show_name,host,description_short,show_graphic1 FROM shows"; $result = mysql_query($query) or die(mysql_error()); echo "<table>"; while($row = mysql_fetch_array($result)) { echo "<tr> <td rowspan='3' width='155' class='show_image'> <a href='". $site ."show_page.php?show_id=". $row['show_id'] ."'> <img src='". $site ."images/". $row['show_graphic1'] ."' height='150' width='150'></img></a> </td> <td class='show_name'> <h1>"; if ($row['host'] == "") { echo $row['show_name']" with " $row['host']; } else { echo $row['show_name']; } echo " </h1> </td> </tr> <tr> <td height='100'>" . $row['description_short'] . "</td> </tr> <tr> <td align='right'> <a href='". $site ."show_page.php?show_id=". $row['show_id'] ."'>More Info</a> </td> </tr>"; } echo "</table>"; } This function is for a page showing a list of shows from a database. Not all shows have a host. So it does not need to show "with host name" for those shows. I tried if / else statement stating that if there "is" data in the row to display one thing and if there "is not" data in the row to display another. Here is that piece of code. Code: [Select] if ($row['host'] == "") { echo $row['show_name']" with " $row['host']; } else { echo $row['show_name']; } I keep getting this error "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/ansonb/lwr_config.php on line 46" What am I doing wrong ? I'm sure it is something simple, I just can't figure it out. 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 { } } Trying to code a first fit algorithm (explanation here). It doesn't output everything correctly at the end. There probably is an easier way to achieve this, but I need to do it using do and while statements. From the output I only get the first array, none of the others display. function first_fit(&$arr, &$max) { $bin = array(array(), array(), array(), array(), array(), array(), array(), array(), array() ,array() ); $i=0; $j=0; do { do { if (array_sum($bin[$j])+$arr[$i] <= $max) {$bin[$j][] = $arr[$i]; $k=1; } $j++; } while($k = 0); $i++; $j=0; } while($i<=9); outputarray($bin[0]); outputarray($bin[1]); outputarray($bin[2]); outputarray($bin[3]); outputarray($bin[4]); outputarray($bin[5]); outputarray($bin[6]); outputarray($bin[7]); outputarray($bin[8]); outputarray($bin[9]); } The function outputarray() just prints the array in a nicely formatted way. Any help would be much appreciated. 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 Hello all, I need your help. I have two pages. This is the 1st page: <?php include "include/dbc.php"; include "include/header.inc"; ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid[]" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']" value=""></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']" value ""></div></td>'; echo '<td><div><select name="metric[]"> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities" onClick="return confirm( 'Are you sure you want to submit the activities?');"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> This page contains a table that is pulling info from a database stored in phpmyadmin. The values entered in that table are passed to the second page: <?php include "include/dbc.php"; include "include/header.inc"; $exerciseid = $_POST["exerciseid"]; $duration = $_POST["duration"]; $distance = $_POST["distance"]; $metric = $_POST["metric"]; echo'<h1>Added Activities</h1>'; // name of array echo '<h1>Exercise</h1>'; if (is_array($exerciseid)) { foreach ($exerciseid as $key => $value) { echo $key .' : '. $value .'<br />'; } } echo '<h1>Duration</h1>'; if ($duration == ""){ echo "No value"; } // name of array echo '<h1>Distance</h1>'; if (is_array($distance)) { foreach ($distance as $key => $value) { echo $key .' : '. $value .'<br />'; } } // name of array echo '<h1>Metric</h1>'; if (is_array($metric)) { foreach ($metric as $key => $value) { echo $key .' : '. $value .'<br />'; } } ?> The problem is that ALL the values, empty or w/content, are being passed. So I was wondering if there was a way to pass only user input with an if/else statement. Something like: if ($duration == ""){ echo "No value"; else echo duration; } This, however, is not working and I would like to know what possibly could work that would be structured similarly. Thanks in advance. Hi there can anybody help me please? my if statement isnt working?? All i am trying to do is display an image if the session variable is == entered varialble "Empire" I get the error message "Parse error: syntax error, unexpected T_VARIABLE, expecting " Code: [Select] if $_SESSION['MM_Username'] == 'Empire'{ echo'<img src="Images/empicon.jpg" width="20" height="20" class="moncalimari"/>' ; } ?> I have checked and the session does == Empire Please help Thank you. |