Jump to content

fluteflute

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

fluteflute's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I wrote the following functions to get data from a database. In particular they return data as an array.The first works fine but the second gives me errors about allowed memory size. I googled this and found how to increase the available memory. However this is a small table with around eight columns and only four rows so far. I am concerned for far bigger tables I would need lots of memory. Is there a better way of doing this? Code causing message: $data = database_getAllRows('users'); Functions: function database_getRow($table, $column, $searchValue) { include('settings.php'); $cxn = mysqli_connect($database_host, $database_user, $database_password, $database_name) or die ("Coudn't connect to server."); $query = "SELECT * FROM $table WHERE $column='$searchValue'"; $result = mysqli_query($cxn, $query) or die ("<p>Couldn't execute query."); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { return $row; // returns array of row from database } } function database_getAllRows($table) { include('settings.php'); $cxn = mysqli_connect($database_host, $database_user, $database_password, $database_name) or die ("Coudn't connect to server."); $query = "SELECT * FROM $table"; $result = mysqli_query($cxn, $query) or die ("<p>Couldn't execute query."); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)!=='NULL') { $array[] = $row; // creates multidimesnional array of all rows from database } return $array; }
  2. Thanks people! Seems odd that a unexpected { message actually requires me to add a ) !
  3. I was playing with my upload script when I got the error: faultCode0faultStringParse error:syntax error, unexpected '{' in /path/htdocs/upload.php on line 59 And I can't see where that unexpected '{' is! <?php if(!isset($_POST['Upload'])) { echo "No File Selected<p>"; echo "<form action='upload.php' method='POST' enctype='multipart/form-data'> <input type='hidden' name='MAX_FILE_SIZE' value='300000' /> <input type='file' name='pix' /><br /> <input type='submit' value='Add Stamps' name='Upload'></form>"; } else { $filename = $_FILES['pix']['name']; $ext = strrchr($filename, "."); if($_FILES['pix']['tmp_name'] == "none") { echo "<b>File did not successfully upload. Check the file size. File must be less than 500K.<br>"; exit(); } if($ext !== (".gif") { echo "<b>File is not a .gif. Please try another file.</b><br>"; exit(); } else { echo "Would have uploaded"; /* $destination = "images/".$_FILES['pix']['name']; $temp_file = $_FILES['pix']['tmp_name']; move_uploaded_file($temp_file,$destination); echo "<p><b>The file has successfully uploaded:</b> {$_FILES['pix']['name']} ({$_FILES['pix']['size']})</p>"; */ } } ?>
  4. Thanks, that was really obvious that bit! Fixed, for now, the code I used was: <?php extract($_POST); $tn = 1; $NEWstampName = $stampName[$tn]; echo $NEWstampName; ?>
  5. Oh and I forgot error messages might be turned off.
  6. OK so how to I now add this to a database? This fails: extract($_POST); $tn = 1; $stampName = $stampname[$tn]; echo $stampname;
  7. Also be aware most free hosts disable the mail function.
  8. I have a program to add 'stamps' to sets of stamps. First you enter the number of stamps in the set(addStamp.php). Then it displays that many sets of forms (addStamp.php?do=input). Finally these are all inputted to a database (addStamp.php?do=database). The problem is processing the multiple sets of data. I've tried something (see the $tn 's in the code) but can't get it to work. Can anyone help me out? <html> <head> <title>Add Stamps to a Set</title> <link rel='stylesheet' type='text/css' href='/stylesheet.css' title='Stylesheet'> </head> <body background='marble.jpg'> <center> <?php if ($_GET['do']=="") { echo "<p class='headertext'>Add a New Set to the Site<p> <form action='addStamp.php?do=input' method='POST'> <table> <tr><th>No of Stamps in Set :</th><td><input type='text' name='numberinset'></td></tr> </table> <input type='submit' value='Continue'> </form>"; die(); } elseif ($_GET['do']=="input") { echo "<p class='headertext'>Add a New Set to the Site<p> <form action='addStamp.php?do=database' method='POST' enctype='multipart/form-data'>"; for($tn=1;$tn<=$_POST['numberinset'];$tn++) { echo "<table><tr><th colspan=2>$tn:</th></tr> <tr><th>Stamp Name:</th><td><input type='text' name='{$tn}stampName'></td></tr> <tr><th>Face Value (pence):</th><td><input type='text' name='{$tn}stampFace'></td></tr> <tr><th>Stanley Gibbons Number:</th><td><input type='text' name='{$tn}stampSG'></td></tr> <tr><th>Image:</th><td> <input type='hidden' name='MAX_FILE_SIZE' value='300000' /> <input type='file' name='{$tn}pix' /><br /> </td></tr> <tr><th>Copyright(optional):</th><td><input type='text' name='{$tn}stampCopyright'></td></tr> </table>"; } echo "<input type='submit' value='Add Stamps' name='Upload'></form>"; die(); } elseif ($_GET['do']=="database") { include("misc2.inc.php"); $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("Coudn't connect to server."); // Code to help with upload - use later $obvious = 3; if($obvious == 4) { if(!isset($_POST['Upload'])) { echo "No File Selected"; } else { if($_FILES['pix']['tmp_name'] == "none") { echo "<b>File did not successfully upload. Check the file size. File must be less than 500K.<br>"; include("form_upload.inc"); exit(); } if(!ereg("image",$_FILES['pix']['type'])) { echo "<b>File is not a picture. Please try another file.</b><br>"; include("form_upload.inc"); exit(); } else { $destination = $_FILES['pix']['name']; $temp_file = $_FILES['pix']['tmp_name']; move_uploaded_file($temp_file,$destination); echo "<p><b>The file has successfully uploaded:</b> {$_FILES['pix']['name']} ({$_FILES['pix']['size']})</p>"; } } } // End of upload helping code } // Below this point not applicable (reference for building database part of app) else { $setYear = $_POST['year']; $setMonth = $_POST['month']; $setDay = $_POST['day']; $setName = $_POST['name']; $noStamps = $_POST['noStamps']; $setIllustration = $_POST['illustration']; $setDesign = $_POST['design']; $setFormat = $_POST['shape']; $setWidth = $_POST['width']; $setHeight = $_POST['height']; $setPrinter = $_POST['printer']; $setPrintProcess = $_POST['process']; $setPerfsWidth = $_POST['perfswide']; $setPerfsHeight = $_POST['perfstall']; $setGum = $_POST['gum']; $noSheet = $_POST['nopersheet']; include("misc2.inc.php"); $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("Coudn't connect to server."); $query = "INSERT INTO sets (setYear,setMonth,setDay,setName,noStamps,setIllustration,setDesign,setFormat,setWidth,setHeight,setPrinter,setPrintProcess,setPerfsWidth,setPerfsHeight,setGum,noSheet) VALUES ('$setYear','$setMonth','$setDay','$setName','$noStamps','$setIllustration','$setDesign','$setFormat','$setWidth','$setHeight','$setPrinter','$setPrintProcess','$setPerfsWidth','$setPerfsHeight','$setGum','$noSheet')"; $result = mysqli_query($cxn,$query) or die ("Couldn't execute query."); echo "Set Added"; echo "<p class='sitelinks'><a href='addSet.php'>Add another!</a><p><a href='sets.php'>View all Sets!</a>"; } // End of non applicable code ?> </center> </body> </html>
×
×
  • 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.