Jump to content

illuz1on

Members
  • Posts

    114
  • Joined

  • Last visited

    Never

Everything posted by illuz1on

  1. Hey, This is a form I use to add information to a database, and upload an image to images/ ... I'm trying to get the INSERT statement to get the name of the newly uploaded picture and save it as 'picture' field in the table... At the moment I fill in all the fields, click "Submit" and it doesn't show any errors or a success display, it just shows the form again, blank. Thanks alot, will be so thankful if someone can help me out here <? } elseif( $_GET["action"] == "add2" ){ echo"<form name=\"newad\" method=\"post\" enctype=\"multipart/form-data\" action=\"?action=add2\"> <table width=\"\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"11%\">Name:</td> <td width=\"89%\"><INPUT TYPE=\"TEXT\" NAME=\"name\" SIZE=36></td> </tr> <tr> <td>Beach Image:</td> <td><input type=\"file\" name=\"image\" SIZE=\"36\"></td> </tr> <tr> <td>Rating:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"rating\" SIZE=36></td> </tr> <tr> <td>Short Desc:</td> <td><TEXTAREA NAME=\"sdesc\" ROWS=10 COLS=30></TEXTAREA></td> </tr> <tr> <td>Long Desc:</td> <td><TEXTAREA NAME=\"ldesc\" ROWS=10 COLS=30></TEXTAREA></td> </tr> <tr> <td>Ocean:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"ocean\" SIZE=36></td> </tr> <tr> <td>Surfing Info:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"surfing\" SIZE=36></td> </tr> <tr> <td>Directions:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"directions\" SIZE=36></td> </tr> </table> <input type=\"submit\" value=\"Add Beach\" /> </form>"; define ("MAX_SIZE","10000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo 'You have exceeded the size limit!'; $errors=1; } $image_name=time().'.'.$extension; $newname="images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo 'Copy unsuccessfull!'; $errors=1; }}}} if(isset($_POST['Submit']) && !$errors) { $picins = "$newname"; $sql="INSERT INTO beaches (picture, rating, name, sdesc, ldesc, ocean, surfing, directions) VALUES ('$picins','$_GET[rating]','$_GET[name]', '$_GET[sdesc]', '$_GET[ldesc]', '$_GET[ocean]', '$_GET[surfing]', '$_GET[directions]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Beach Added - Check to see if it is valid!"; echo "Beach Image Uploaded Successfully!"; echo "$picins"; } ?>
  2. At the moment I fill in all the fields, click "Submit" and it doesnt show any errors or a success display, it just shows the form again, blank. And sorry here is the code properly: <? } elseif( $_GET["action"] == "add2" ){ echo"<form name=\"newad\" method=\"post\" enctype=\"multipart/form-data\" action=\"?action=add2\"> <table width=\"\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"11%\">Name:</td> <td width=\"89%\"><INPUT TYPE=\"TEXT\" NAME=\"name\" SIZE=36></td> </tr> <tr> <td>Beach Image:</td> <td><input type=\"file\" name=\"image\" SIZE=\"36\"></td> </tr> <tr> <td>Rating:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"rating\" SIZE=36></td> </tr> <tr> <td>Short Desc:</td> <td><TEXTAREA NAME=\"sdesc\" ROWS=10 COLS=30></TEXTAREA></td> </tr> <tr> <td>Long Desc:</td> <td><TEXTAREA NAME=\"ldesc\" ROWS=10 COLS=30></TEXTAREA></td> </tr> <tr> <td>Ocean:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"ocean\" SIZE=36></td> </tr> <tr> <td>Surfing Info:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"surfing\" SIZE=36></td> </tr> <tr> <td>Directions:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"directions\" SIZE=36></td> </tr> </table> <input type=\"submit\" value=\"Add Beach\" /> </form>"; define ("MAX_SIZE","10000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo 'You have exceeded the size limit!'; $errors=1; } $image_name=time().'.'.$extension; $newname="images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo 'Copy unsuccessfull!'; $errors=1; }}}} if(isset($_POST['Submit']) && !$errors) { $picins = "$newname"; $sql="INSERT INTO beaches (picture, rating, name, sdesc, ldesc, ocean, surfing, directions) VALUES ('$picins','$_GET[rating]','$_GET[name]', '$_GET[sdesc]', '$_GET[ldesc]', '$_GET[ocean]', '$_GET[surfing]', '$_GET[directions]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Beach Added - Check to see if it is valid!"; echo "Beach Image Uploaded Successfully!"; echo "$picins"; } ?>
  3. Hey, This is a form I use to add information to a database, and upload an image to images/ ... Im trying to get the INSERT statement to get the name of the newly uploaded picture and save it as 'picture' field in the table... Thanks alot, will be so thankful if someone can help me out here } elseif( $_GET["action"] == "add2" ){ echo"<form name=\"newad\" method=\"post\" enctype=\"multipart/form-data\" action=\"?action=add2\"> <table width=\"\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"11%\">Name:</td> <td width=\"89%\"><INPUT TYPE=\"TEXT\" NAME=\"name\" SIZE=36></td> </tr> <tr> <td>Beach Image:</td> <td><input type=\"file\" name=\"image\" SIZE=\"36\"></td> </tr> <tr> <td>Rating:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"rating\" SIZE=36></td> </tr> <tr> <td>Short Desc:</td> <td><TEXTAREA NAME=\"sdesc\" ROWS=10 COLS=30></TEXTAREA></td> </tr> <tr> <td>Long Desc:</td> <td><TEXTAREA NAME=\"ldesc\" ROWS=10 COLS=30></TEXTAREA></td> </tr> <tr> <td>Ocean:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"ocean\" SIZE=36></td> </tr> <tr> <td>Surfing Info:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"surfing\" SIZE=36></td> </tr> <tr> <td>Directions:</td> <td><INPUT TYPE=\"TEXT\" NAME=\"directions\" SIZE=36></td> </tr> </table> <input type=\"submit\" value=\"Add Beach\" /> </form>"; define ("MAX_SIZE","10000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo 'You have exceeded the size limit!'; $errors=1; } $image_name=time().'.'.$extension; $newname="images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo 'Copy unsuccessfull!'; $errors=1; }}}} if(isset($_POST['Submit']) && !$errors) { $picins = "$newname"; $sql="INSERT INTO beaches (picture, rating, name, sdesc, ldesc, ocean, surfing, directions) VALUES ('$picins','$_GET[rating]','$_GET[name]', '$_GET[sdesc]', '$_GET[ldesc]', '$_GET[ocean]', '$_GET[surfing]', '$_GET[directions]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Beach Added - Check to see if it is valid!"; echo "Beach Image Uploaded Successfully!"; echo "$picins"; }
  4. Hey, Im looking for a bit of advice here... if I want to add password protection or a admin login to this piece of code, can anyone advise on how or point me to a good tutorial? <?php /* Created on: 4/23/2007 */ ?> <? include("db-a.php"); ?> <html> <body> <center>Cape Town Beaches Administration</center><br> <center>Please select administration function</center> <br> <center><a href="beachesadmin.php?action=add">Add</a> | <a href="beachesadmin.php?action=view">View Entries</a><br></center> <br> <hr> </body> </html> <? if( $_GET["action"] == "insert" ){ // INSERT ACTION /////////////////////////////////// // Code Goes Here } elseif( $_GET["action"] == "add" ){ // ADD ACTION /////////////////////////////////// // Code Goes Here } elseif( $_GET["action"] == "editpro" ){ // EDIT ACTION ////////////////////////////////////////////// // Code Goes Here } elseif( $_GET["action"] == "edit" ){ // EDIT /////////////////////////////////// // Code Goes Here } elseif( $_GET["action"] == "delete" ){ // LIST ONLY THE GALLERY /////////////////////////////////// // Code Goes Here } elseif( $_GET["action"] == "view" ){ // LIST ALL RECORDS IN THE BEACH DATABASE /////////////////////////////////// // Code Goes Here } } ?>
  5. Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
  6. Hey, I try to add a record with the action "script.php?action=add" ... and then I try to insert it with the action "script.php?action=insert".. The problem is it inserts a row into the database, but of empty fields, just blanks? Can anyone see the problem? if( $_GET["action"] == "insert" ){ // INSERT ACTION /////////////////////////////////// $sql="INSERT INTO beaches (picture, rating, name, sdesc, ldesc, ocean, surfing, directions) VALUES ('$_GET[picture]', '$_GET[rating]','$_GET[name]', '$_GET[sdesc]', '$_GET[ldesc]', '$_GET[ocean]', '$_GET[surfing]', '$_GET[directions]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Beach added to database! - Check to see if it is valid!"; } elseif( $_GET["action"] == "add" ){ // ADD ACTION /////////////////////////////////// echo "<b>Beach Administration - Add Beach</b><br>"; echo "<br>"; echo "<br>"; echo "<form action=\"?action=insert\" method=\"post\"> Name:<INPUT TYPE=\"TEXT\" NAME=\"name\" SIZE=30><br> Picture:<INPUT TYPE=\"TEXT\" NAME=\"picture\" SIZE=30><br> Rating:<INPUT TYPE=\"TEXT\" NAME=\"rating\" SIZE=30><br> Short Desc:<TEXTAREA NAME=\"sdesc\" ROWS=10 COLS=30></TEXTAREA><br> Long Desc:<TEXTAREA NAME=\"ldesc\" ROWS=10 COLS=30></TEXTAREA><br> Ocean:<INPUT TYPE=\"TEXT\" NAME=\"ocean\" SIZE=30><br> Surfing Info:<INPUT TYPE=\"TEXT\" NAME=\"surfing\" SIZE=30><br> Directions:<INPUT TYPE=\"TEXT\" NAME=\"directions\" SIZE=30><br> <input type=\"submit\" value=\"Add Beach\" /> </p> </form>";
  7. Thanks alot - that worked out but again, I have run into another problem: This is the whole pages code, it loads and does everything - but doesnt display the beaches when either Atlantic or Indian is selected - just shows nothing.. <?php /* Created on: 4/23/2007 */ ?> <? include("db.php"); ?> <html> <body> Cape Town Beaches<br> <br> <a href="beaches.php?action=atlantic">Atlantic Ocean</a> | <a href="beaches.php?action=indian">Indian Ocean</a> | <a href="beaches.php?action=all">All Beaches</a><br> <br> Show me the Cape Town Alive guide to a going to the right beach! <a href="beaches.php?action=guide">click here</a><br> <hr> </body> </html> <?php $action = mysql_real_escape_string($_GET['action']); if (isset($_GET["action"])) { if ($result = mysql_query("SELECT * FROM beaches WHERE ocean=$action")) { if (mysql_num_rows($result)) { while($row = mysql_fetch_array($result)) { extract($row); echo "$action <table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td><table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"> <tr> <td class=\"header\">$name - <img src=\"images/rating$rating.gif\"></td> <td> </td> </tr> <tr> <td colspan=\"2\"><hr></td> </tr> <tr> <td colspan=\"2\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"> <tr> <td width=\"10%\"><img src=\"images/beaches/$picture.jpg\" width=\"87\" height=\"87\"></td> <td width=\"90%\" valign=\"top\" class=\"content_text\">$sdesc</td> </tr> </table></td> </tr> <tr align=\"right\"> <td colspan=\"2\" class=\"read_more_text\"><hr></td> </tr> <tr align=\"right\"> <td colspan=\"2\" class=\"read_more_text\"><a href=\"morebeach.php?id=$id\">show more information</a> | <a href=\"addshort.php?id=$id\">add to shortlist</a> | <a href=\"gallery.php?id=$id\">gallery</a></td> </tr> </table></td> </tr> </table>"; } } } } else { echo "This is where a nice writeup of the beaches would go!"; } ?> </body> </html>
  8. ok worse than i thought... getting Parse error: parse error, unexpected '{' in /home/capetown/public_html/dev/beaches.php on line 19 <?php $action = mysql_real_escape_string($_GET['action']); if (isset($_GET["action"])) { if ($result = mysql_query("SELECT * FROM beaches WHERE ocean=$action"); if (mysql_num_rows($result)) { while($row = mysql_fetch_array($result)) { extract($row); echo ""; } } } } else { echo ""; } ?>
  9. if ($result = mysql_query(SELECT * FROM beaches WHERE ocean='mysql_real_escape_string($_GET['action']')); Pls can someone help me fix that line of code.. Thanks
  10. ok i see what you saying, and tried to look for the } and not there ... Parse error: parse error, unexpected ')' in /home/capetown/public_html/dev/edit.php on line 33
  11. ok now I tried making a different one, a simpler one without complication/// edit2.php is the form page <? require_once("db.php"); $id = $_GET['id']; $sql = "SELECT * FROM specialoffer WHERE id='$id'"; $data = mysql_query($sql); while($record = mysql_fetch_assoc($data)) { $title = $record['title']; $dur1 = $record['dur1']; $price = $record['price']; $description = $record['description']; } ?> <form action="edit1.php" method="post"> <input type="hidden" name="id" value="$id"> Title: <input type="text" name="title" value="<? echo "$title"; ?>"><br> Duration: <input type="text" name="dur1" value="<? echo "$dur1"; ?>"><br> Price: <input type="text" name="price" value="<? echo "$price"; ?>"><br> Description: <input type="text" name="description" value="<? echo "$description"; ?>"><br> <input type="Submit" value="Update"> </form> edit1.php is the processing page <?php require_once("db.php"); $id = $_POST['id']; $ntitle = $_POST['title']; $ndur1 = $_POST['dur1']; $nprice = $_POST['price']; $ndescription = $_POST['description']; $result = mysql_query("UPDATE specialoffer SET title='$ntitle', dur1='$ndur1', price='$nprice', description='$ndescription' WHERE id='$id'") or die(mysql_error()); echo "Record Updated"; ?> pls guys dieing to get this working ?
  12. Thanks guys, ok I tried changing the ID to GET instead of POST and it still has a blank display..
  13. Hey I have always had a problem with updating rows in SQL, and now this is the best piece of update code I have and it wont work?!? Please help me spot the error here its killing me I send the url like this edit.php?id=$id and this is my code, which just brings up a blank page weather ID is posted or even just edit.php <?php include("db.php"); if($submit) { $title = $_POST['title']; $dur1 = $_POST['dur1']; $description = $_POST['description']; $price = $_POST['price']; $id = $_POST['id']; $result = mysql_query("UPDATE specialoffer SET title='$title', dur1='$dur1', price='$price', description='$description' WHERE id='$id' ",$con); echo "<b>Offer UPDATED Successfully!<br>You'll be redirected to admin page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=admin.php>"; } elseif($id) { $result = mysql_query("SELECT * FROM specialoffer WHERE id='$id' ",$con); while($myrow = mysql_fetch_assoc($result)) { $id = $myrow["id"]; $title = $myrow["title"]; $price = $myrow["price"]; $dur1 = $myrow["dur1"]; $description = $myrow["description"]; ?> <br> <h3>::Edit News</h3> <form method="post" action="<?php echo $PHP_SELF; ?>"> <input type="hidden" name="id" value="<? echo $myrow['id']; ?>"> Title: <input name="title" size="40" maxlength="255" value="<? echo $title; ?>"> <br> Duration: <input name="dur1" size="40" maxlength="255" value="<? echo $dur1; ?>"> <br> Price Range: <input name="price" size="40" maxlength="255" value="<? echo $price; ?>"> <br> Description: <textarea name="description" rows="7" cols="30"><? echo $description; ?></textarea> <br> <input type="submit" name="submit" value="Update Offer"> </form> <? }//end of while loop }//end else ?>
  14. great thanks alot, will keep in mind to move to ID if i encounter problems
  15. awesome yea I think thats what im looking for, but how would I adapt that to get from the title in db?
  16. Hey ive just started storing images in a mysql database, but now I want to try and make a function that gets the image out the DB by the TITLE and prints it - like <? printimage(this.would.be.image.title); ?> How would I go about this?? This is my table structure: create table pics ( pid int primary key not null auto_increment, title text, imgdata longblob) Thanks alot
  17. Hey I have this piece of code which is supposed to just add a guide into a database, but it doesnt ADD it it just reloads the page and doesnt send any error/confirmation... please guide me to where I am wrong Thanks guys <?php include("db.php"); ?> <html> <body> Add Guide <form action="<?php echo $PHP_SELF ?>" method="post"> <b> Guide Name</b> <BR /> <input type="text" name="name" size="40" maxlength="80" value="" /> <br /> <b>Link</b> <BR /> <input type="text" name="link" size="40" maxlength="80" value="" /> <br /> <input type="submit" value="Add Guide" /> <input type="reset" value="Reset" /> </form> <? if($submit) { $name = $_POST["name"]; $link = $_POST["link"]; $addnews =MYSQL_QUERY("INSERT INTO guides (id,name,link)". "VALUES ('NULL', '$name', '$link')"); echo("Guide on: $name - Added!<br>No errors were encountered!<br>"); echo("<a href=\"guidesoverview.php\">Guides Overview</a> | <a href=\"admin.php\">Back to Admin</a>"); } ?> </body> </html>
  18. good to know that thanks alot mate
  19. hey I have a listbox called "I want to..." and people select in the listbox what they want to do and then the selection links to x.php ... This code only shows 1 entry in the listbox while the database has more <?php include("db.php"); ?> <html> <body> <?php //select statement example ok all book entry's lol. $sql = "SELECT * FROM guides"; $data = mysql_query($sql); while($record = mysql_fetch_assoc($data)) { $id = $record['id']; $name = $record['name']; $link = $record['link']; } echo "<form name=\"guideform\" id=\"guideform\" action=\"#\"> <select name=\"guidelinks\" id=\"guidelinks\" onChange=\"window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value\"> <option selected value=\"#\">I want a</option> <option value=\"$link.php\">$name</option> </select> </form> "; ?> </body> </html>
  20. Hey can anyone spot the error in here? I want it to make it so that if q="" then it doesnt execute the SQL query <? if( $_GET["action"] == "clubs" ){ $q1 = "clubs"; } elseif( $_GET["action"] == "bars" ){ $q1 = "bars"; } elseif( $_GET["action"] == "lounges" ){ $q1 = "lounges"; } elseif( $_GET["action"] == "events" ){ $q1 = "events"; }else { $q1 = ""; echo "Click on one of the above links to see a listing of some of the hottest places in town!"; } ?> <? if ( !q ) { echo "Click on one of the above links to see a listing of some of the hottest places in town!"; } else { $getnews = mysql_query("select * from $q1"); while($r=mysql_fetch_array($getnews)){ extract($r); echo("<div class=\"blue\"><b>$name - $id</b></div> <div class=\"sdesc\">$music</div> <hr>"); } ?>
  21. I have this piece of code which will show what I intend on doing... <? $selection = $_POST["selection"]; if( $_GET["action"] == "clubs" ){ echo "CLUUUBS!"; } elseif( $_GET["action"] == "bars" ){ echo "BARRRS!"; } elseif( $_GET["lounges"] == "lounges" ){ echo "Lounges!"; } elseif( $_GET["events"] == "events" ){ echo "EVENTS"; }else { echo "No selection Made"; } ?> How can I make that work? the last 2 if's wont work Thanks guys
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.