koop1koop Posted October 31, 2007 Share Posted October 31, 2007 Please can anybody help, I have the following script that works on php 4.4.7 but not with 5.2.3. it gives this error Notice: Undefined variable: submit <form name="search" method="post" action="<?= $_SERVER['PHP_SELF'] ?>"> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="Ingredients">Ingredients</option> <Option VALUE="Category">Category</option> <Option VALUE="Title">Title</option> </Select> <input type="hidden" name="searching" value="yes" /> <input name="submit" type="submit" id="submit" value="submit" /> </form> <? if ($submit) { echo "<h2>Results</h2><p>"; if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } include ('config.inc.php'); $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); $data = mysql_query("SELECT * FROM $table WHERE upper($field) LIKE'%$find%'"); while($result = mysql_fetch_array( $data )) { extract($result); echo" <table width='780' border='0' cellspacing='2' cellpadding='0'> </table> ";} $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } echo "<b>Searched For:</b> " .$find; } ?> Also another script with the following error Notice: Undefined index: userfile first part is add.php <? $uploaddir = "/uploads"; $fields = 1; $acceptfilter = 1; $acceptabletypes = array("image/jpeg", "image/pjpeg", "image/gif", "image/giff"); $limitsize = 0; $maxsize = 200; $overwriting = 0; $scandir = 0; $makelog = 0; $logfile = "uploadlog.txt"; $timeoffset = +0; include("uploader.php"); ?> and the 2nd part is uploader.php <? function get_files($dirstr) { $scanfiles = array(); $fh = opendir($dirstr); while (false !== ($filename = readdir($fh))) { if (is_file("$dirstr/$filename")) { array_push($scanfiles, $filename); } } closedir($fh); sort($scanfiles); return $scanfiles; } $count = count($_FILES['userfile']['name']); if ($count > 0) { $i=0; $f=0; while ($i < $count) { $kbsize = (round($_FILES['userfile']['size'][$i]/1024)); $date = date("j M Y g:ia", time()+($timeoffset*3600)); $userip = $_SERVER['REMOTE_ADDR']; if ($limitsize == 1) { if ($_FILES['userfile']['size'][$i] > (1024*$maxsize) ) { $toobig[$i] = "{$_FILES['userfile']['name'][$i]} is too large! the maximum file size is $maxsize kb."; } } if ($acceptfilter == 1) { if (!in_array($_FILES['userfile']['type'][$i], $acceptabletypes)) { $rejectstring = "{$_FILES['userfile']['name'][$i]} is not of the type "; foreach ($acceptabletypes as $acceptabletype) { $rejectstring .= "$acceptabletype or "; } $rejectstring = substr($rejectstring, 0, -4); $notacceptable[$i] = "$rejectstring."; } } if ($overwriting !== 1) { if(file_exists("$uploaddir/{$_FILES['userfile']['name'][$i]}")) { $alreadyexists[$i] = "a file of the name {$_FILES['userfile']['name'][$i]} already exists! overwriting is not permitted."; } } if (!isset($toobig[$i]) && !isset($notacceptable[$i]) && !isset($alreadyexists[$i])) { copy($_FILES['userfile']['tmp_name'][$i], "$uploaddir/{$_FILES['userfile']['name'][$i]}"); echo "{$_FILES['userfile']['name'][$i]} uploaded successfully!<br>"; $f++; $content .= "/{$_FILES['userfile']['name'][$i]}"; } elseif ($_FILES['userfile']['size'][$i] !== 0) { echo "$toobig[$i] $notacceptable[$i] $alreadyexists[$i]<br>"; $content .= "$date $userip fails to upload $uploaddir/{$_FILES['userfile']['name'][$i]} ($kbsize kb) - $toobig[$i] $notacceptable[$i] $alreadyexists[$i]\n"; } $i++; } echo "uploaded $f file(s)"; $user="user"; $host="host"; $password="password"; $database = "database"; $connection = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); $db = mysql_select_db($database,$connection) or die ("Couldn't select database"); $Ingredients = nl2br($Ingredients); $Method = nl2br($Method); $Notes = nl2br($Notes); if ($makelog == 0) { $query = "INSERT INTO $table (Title,Category,Dificulty,Serves,Prep,Time1,Cook,Time2,Calories,pic_score,WWPoints,Ingredients,Method,Notes) VALUES('$Title','$Category','$Dificulty','$Serves','$Prep','$Time1','$Cook','$Time2','$Calories','$content','$WWPoints','$Ingredients','$Method','$Notes')"; $result = mysql_query($query) or die ("Query failed: " . mysql_error() . " Actual query: " . $query); echo "<p>$Title Added,<br>"; } } ?> <link href="dvd.css" rel="stylesheet" type="text/css"> <form action="<?= $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>" method="post" name="Form1" enctype="multipart/form-data" id="Form1" onsubmit="return Form1_Validator(this)" language="JavaScript"> <table width="700" border="0" align="left" cellpadding="0" cellspacing="5"> <tr> <td width="92" align="center" valign="middle"><div align="left">Title</div></td> <td colspan="6" align="center" valign="middle"><div align="left"><strong> <input name="Title" type="text" id="Title" size="94" /> </strong></div></td> </tr> <tr> <td align="center" valign="middle"><div align="left">Category</div></td> <td width="115" align="left" valign="middle"><div align="left"> <select name="Category" size="1" id="Category"> <option value="" selected="selected">Please Select</option> <option value="Breakfast">Breakfast</option> <option value="Soup">Soup</option> <option value="Main Meals">Main Meals</option> <option value="Light Meals">Light Meals</option> <option value="Sandwiches">Sandwiches</option> <option value="Sides">Sides</option> <option value="Vegetarian">Vegetarian</option> <option value="Cakes">Cakes</option> <option value="Desserts">Desserts</option> </select> </div></td> <td width="73" align="left" valign="middle">Dificulty</td> <td width="100" align="left" valign="middle"><select name="Dificulty" size="1" id="Dificulty"> <option value="Easy" selected="selected">Easy</option> <option value="Moderate ">Moderate </option> <option value="Hard">Hard</option> </select></td> <td width="107" align="center" valign="middle"><div align="left">Prep Time</div></td> <td width="85" align="left" valign="middle"><div align="left"><strong> <input name="Prep" type="text" id="Prep" size="10" /> </strong></div></td> <td width="88" align="left" valign="middle"><select name="Time1" size="1" id="Time1"> <option value="Mins" selected="selected">Mins</option> <option value="Hour">Hour</option> <option value="Hours">Hours</option> </select></td> </tr> <tr> <td align="center" valign="middle"><div align="left">Serves</div></td> <td align="left" valign="middle"><div align="left"><strong> <input name="Serves" type="text" id="Serves" size="10" /> </strong></div></td> <td align="left" valign="middle">Calories</td> <td align="left" valign="middle"><strong> <input name="Calories" type="text" id="Calories" size="10" /> </strong></td> <td align="center" valign="middle"><div align="left">Cook Time</div></td> <td align="left" valign="middle"><div align="left"><strong> <input name="Cook" type="text" id="Cook" size="10" /> </strong></div></td> <td align="left" valign="middle"><select name="Time2" size="1" id="Time2"> <option value="Mins" selected="selected">Mins</option> <option value="Hour">Hour</option> <option value="Hours">Hours</option> </select></td> </tr> <tr> <td align="center" valign="middle"><div align="left">Image</div></td> <td colspan="3" align="left" valign="middle"><label> <strong> <? for($d=0; $d < $fields; $d++) { echo "<input name=\"userfile[]\" type=\"file\" size=\"25\"><br>"; } ?> </strong> </label></td> <td align="center" valign="middle"><div align="left">WW Points</div></td> <td colspan="2" align="left" valign="middle"><div align="left"><strong> <input name="WWPoints" type="text" id="WWPoints" size="10" /> </strong></div></td> </tr> <tr> <td align="center" valign="middle"><div align="left"></div></td> <td colspan="3" align="left" valign="middle"><div align="left"></div></td> <td align="center" valign="top"><div align="left"></div></td> <td colspan="2" align="left" valign="middle"><div align="left"></div></td> </tr> <tr> <td align="center" valign="middle"><div align="left">Ingredients</div></td> <td colspan="6" align="left" valign="middle"><div align="left"><strong> <textarea name="Ingredients" cols="70" rows="4" id="Ingredients"></textarea> </strong></div></td> </tr> <tr> <td align="center" valign="middle"><div align="left"></div></td> <td colspan="3" align="left" valign="middle"><div align="left"></div></td> <td align="center" valign="top"><div align="left"></div></td> <td colspan="2" align="left" valign="top"><div align="left"></div></td> </tr> <tr> <td align="center" valign="middle"><div align="left">Method </div></td> <td colspan="6" align="left" valign="middle"><div align="left"><strong> <textarea name="Method" cols="70" rows="4" id="Method"></textarea> </strong></div></td> </tr> <tr> <td align="center" valign="middle"><div align="left"></div></td> <td colspan="3" align="left" valign="middle"><div align="left"></div></td> <td align="center" valign="top"><div align="left"></div></td> <td colspan="2" align="left" valign="top"><div align="left"></div></td> </tr> <tr> <td align="center" valign="middle"><div align="left">Notes</div></td> <td colspan="6" align="left" valign="middle"><div align="left"><strong> <textarea name="Notes" cols="70" rows="4" id="Notes"></textarea> </strong></div></td> </tr> <tr> <td align="center" valign="middle"><div align="left"></div></td> <td colspan="3" align="left" valign="middle"><div align="left"></div></td> <td align="center" valign="middle"><div align="left"></div></td> <td colspan="2" align="center" valign="middle"> <div align="left"> <input type="submit" value="Send files"> <input name="Reset" type="reset" id="Reset" value="Reset"> </div></td> </tr> </table> <br> </form> <? echo "<ul>"; if ($makelog == 1) { echo "<li><b>All upload attempts are logged.</b></li>"; } if ($limitsize == 1) { echo "<li><b>The maximum file size is $maxsize kb.</b></li>"; } if ($overwriting == 1) { echo "<li><b>Overwriting is permitted.</b></li>"; } if ($scandir == 1) { echo "<li><b>The current files in this directory are:</b></li><br>"; $files = get_files($uploaddir); foreach ($files as $file) { echo "$file<br>"; } } echo "</ul>"; unset($count, $acceptabletypes, $handle, $content, $date, $kbsize); ?> Please can anyone help its eating at my brain Quote Link to comment https://forums.phpfreaks.com/topic/75573-solved-code-help-notice-undefined-variable-submit/ Share on other sites More sharing options...
kratsg Posted October 31, 2007 Share Posted October 31, 2007 First block: change from: if ($submit) to: if ($_POST) Second problem, I don't believe $_FILES['userfile'] exists as an array index, change 'userfile' to 'uploadedfile' instead. Quote Link to comment https://forums.phpfreaks.com/topic/75573-solved-code-help-notice-undefined-variable-submit/#findComment-382372 Share on other sites More sharing options...
pocobueno1388 Posted October 31, 2007 Share Posted October 31, 2007 Instead of if ($_POST) I would go with if (isset($_POST['submit'])) Quote Link to comment https://forums.phpfreaks.com/topic/75573-solved-code-help-notice-undefined-variable-submit/#findComment-382374 Share on other sites More sharing options...
koop1koop Posted November 1, 2007 Author Share Posted November 1, 2007 Thanks for you help I got it working, took a while to understand but with you guidence and a bit of the php manual I got it. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/75573-solved-code-help-notice-undefined-variable-submit/#findComment-382650 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.