PHP - Changing Code Passed On By Url
Hi
I use Dreamweaver to do a lot of my work on a php/mysql database. I have two tables - applications and contacts and they are linked by the id appid. When I view a page with all of the application and contact details the url contains the appid as a number at the end (eg .../Summary.php?appid=639) When I want to edit one of the contacts I go to the edit page but this is identified by a contact id so that url looks like: ../EditContact.php?contactid=32 When I update the contact's details I would like to return to the summary page but can't as the url gets muddled between the two different ids so I end up at a page with no info on it. How can I get round this? I'm sorry my explanation isn't very clear but any help is much appreciated. Similar TutorialsHi guys, i have a system and was asked to develop the site with the current system. These are sometimes a pain but it is an old system and i'm trying to change the url's which is seems to be hard to do with this kind of code. set_time_limit(60); include 'includes/config.php'; include 'includes/logfile.php'; include 'includes/databasefile.php'; include 'includes/templatefile.php'; $log = new cLog; $db = new cDatabase; //first run ssl check if necessary if ($_SERVER['SERVER_PORT'] == "80" && $sslredirect == 1) { header ("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?" . $_SERVER['QUERY_STRING']); exit(0); } //first, determine page requested list ($junk, $request) = split ("\?/", $_SERVER['REQUEST_URI']); list ($uri, $data) = split ("!", $request); $uriarray = split ("/", $uri); //check for login/logout request list ($junk, $request) = split ("\?", $_SERVER['REQUEST_URI']); if ($request == 'login') { header ("Location: login.php"); exit(0); } else if ($request == 'logout') { header ("Location: logout.php"); exit(0); } if ($data != "") { //parse internal variables $dataarray = split ("&", $data); foreach ($dataarray as $line) { list ($cmd, $val) = split ("=", $line); $arr_cmds[$cmd] = urldecode ($val); } } $pagename = $db->escape($uriarray[count($uriarray)-2]); $sectionname = $db->escape($uriarray[count($uriarray)-3]); if ($pagename == "") { $pagename = "home"; } if ($sectionname == "") { $sectionname = "home"; } $urlpagename = $pagename; $urlsectionname1 = $sectionname; $urlsectionname2 = $db->escape($uriarray[count($uriarray)-4]); //handle any commands, then redirect back to page $cmd = $_REQUEST['cmd']; if ($cmd == "-displayelement") { $elementid = $db->escape($_REQUEST['elementid']); if ($_REQUEST['surpresshtml'] == "") { echo "<html><head><link href='templates/css.css' rel='stylesheet' type='text/css'></head>\n"; } if ($_REQUEST['global'] == "1") { $query = $db->query("select ComponentName, Data from table_globalelements where (ElementID = '$elementid')"); } else { $query = $db->query("select ComponentName, Data from table_elements where (ElementID = '$elementid')"); } $r = $db->fetch_array($query); $currentcomponentname = $r['ComponentName']; $data = stripslashes($r['Data']); //find matching component and launch display function $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) { include "com/components/" . $file; echo call_user_func(array($currentcomponentname, 'display'), $data); break; } } if ($_REQUEST['surpresshtml'] == "") { echo "</body></html>\n"; } exit (0); } else if ($cmd == '-editelement') { $elementid = $db->escape($_REQUEST['elementid']); if (isset($_SESSION['UserID'])) { $query = $db->query("select UserID, AdminFlag from table_users where (UserID = '" . $_SESSION['UserID'] . "')"); $r = $db->fetch_array($query); $userid = $r['UserID']; $adminflag = $r['AdminFlag']; if ($adminflag != "1") { $query = $db->query ("select ComponentName, Data, PageID from table_elements where (ElementID = '$elementid' and UserID = '$userid')"); } else { $query = $db->query ("select ComponentName, Data, PageID from table_elements where (ElementID = '$elementid')"); } $r = $db->fetch_array($query); $currentcomponentname = $r['ComponentName']; $data = stripslashes($r['Data']); $pageid = $r['PageID']; //handle request $cmd = $_REQUEST['greyboxcmd']; if ($cmd == 'save') { $elementid = $db->escape($_REQUEST['ElementID']); $data = $db->escape($_REQUEST['Data']); //find matching component and launch save function $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; $data = call_user_func(array($currentcomponentname, 'save')); if ($adminflag != "1") { $query = $db->query("update table_elements set Data = '$data' where (ElementID = '$elementid' and UserID = '$userid')"); } else { $query = $db->query("update table_elements set Data = '$data' where (ElementID = '$elementid')"); } echo "<script type='text/javascript'>parent.location.reload(true); parent.GB_hide();</script>\n"; exit(0); } } echo "Error: component not found..."; } //find matching component and launch edit function echo "<html><head><link href='templates/css.css' rel='stylesheet' type='text/css'><script type='text/javascript' src='templates/openwysiwyg/wysiwyg.js'></script></head>\n"; echo "<body style='text-align: center;'><form name='Form0' enctype='multipart/form-data' method='post' action='" . $_SERVER['REQUEST_URI'] . "'>\n"; $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; echo call_user_func(array($currentcomponentname, 'edit'), $data); break; } } echo "<input type='hidden' name='ElementID' value='$elementid'><input type='submit' name='Save' value='Save' class='smallbutton'>\n"; echo "<input type='button' name='Cancel' value='Cancel' onclick='parent.GB_hide();' class='smallbutton'>\n"; echo "<input type='hidden' name='greyboxcmd' value='save'></form></body></html>\n"; exit (0); } else { echo "<script type='text/javascript'>parent.GB_hide();</script>\n"; exit (0); } } else if ($cmd == '-editglobalelement') { $elementid = $db->escape($_REQUEST['elementid']); if (isset($_SESSION['UserID'])) { $query = $db->query("select UserID, AdminFlag from table_users where (UserID = '" . $_SESSION['UserID'] . "')"); $r = $db->fetch_array($query); $userid = $r['UserID']; $adminflag = $r['AdminFlag']; if ($adminflag != "1") { echo "Security - Out of bounds"; exit(0); } $query = $db->query ("select ComponentName, Data from table_globalelements where (ElementID = '$elementid')"); $r = $db->fetch_array($query); $currentcomponentname = $r['ComponentName']; $data = stripslashes($r['Data']); //handle request $cmd = $_REQUEST['greyboxcmd']; if ($cmd == 'save') { $elementid = $db->escape($_REQUEST['ElementID']); $data = $db->escape($_REQUEST['Data']); //find matching component and launch save function $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; $data = call_user_func(array($currentcomponentname, 'save')); $query = $db->query("update table_globalelements set Data = '$data' where (ElementID = '$elementid')"); echo "<script type='text/javascript'>parent.location.reload(true); parent.GB_hide();</script>\n"; exit(0); } } echo "Error: component not found..."; } //find matching component and launch edit function echo "<html><head><link href='templates/css.css' rel='stylesheet' type='text/css'><script type='text/javascript' src='templates/openwysiwyg/wysiwyg.js'></script></head>\n"; echo "<body style='text-align: center;'><form name='Form0' enctype='multipart/form-data' method='post' action='" . $_SERVER['REQUEST_URI'] . "'>\n"; $dir_handle = opendir("com/components/"); while ($file = readdir($dir_handle)) { $filenoext = str_replace (".php", "", $file); if ($filenoext == $currentcomponentname) {; include "com/components/" . $file; echo call_user_func(array($currentcomponentname, 'edit'), $data); break; } } echo "<input type='hidden' name='ElementID' value='$elementid'><input type='submit' name='Save' value='Save' class='smallbutton'>\n"; echo "<input type='button' name='Cancel' value='Cancel' onclick='parent.GB_hide();' class='smallbutton'>\n"; echo "<input type='hidden' name='greyboxcmd' value='save'></form></body></html>\n"; exit (0); } else { echo "<script type='text/javascript'>parent.GB_hide();</script>\n"; exit (0); } } //lookup page details $query = $db->query("select p.PageID, p.PageTitle, p.SectionID, p.TemplateID, p.UserID, p.LastUpdate, p.SectionName, s.SectionTitle, s.GroupID, s.Protected, p.Keywords, p.PageName from table_pages as p left join table_sections as s on s.SectionName = p.SectionName where (p.PageName = '$pagename' and s.SectionName = '$sectionname') limit 1"); if (!$pagedetails = $db->fetch_array($query)) { echo "404"; exit(0); } //check for privileges section if ($pagedetails[8] != "" && $pagedetails[8] != "0") { $sectionname = stripslashes($pagedetails[6]); if (!isset($_SESSION['Username']) && !isset($_REQUEST['Username'])) { echo "This is a restricted area. Please login.<br/><br/>"; echo "<form action='index.php' method='get'>Username: <input type='text' name='Username'><br/>\n"; echo "Password: <input type='password' name='Password'><br/>\n"; echo "<input type='submit' name='Login' value='Login'></form><br/>\n"; exit; } else { $username = $db->escape ($_REQUEST['Username']); $password = $db->escape ($_REQUEST['Password']); if ($username == "") { $username = $db->escape ($_SESSION['Username']); } if ($password == "") { $password = $db->escape ($_SESSION['Password']); } $query = $db->query("select UserID, Password, RealName, Email, GroupID, AdminFlag from table_users where (Username = '$username')"); $r = $db->fetch_array($query); $dbpassword = $r['Password']; if ($password == $dbpassword) { $_SESSION['Username'] = $username; $_SESSION['UserID'] = $r['UserID']; $_SESSION['RealName'] = $r['RealName']; $_SESSION['Email'] = $r['Email']; $_SESSION['GroupID'] = $r['GroupID']; } } if ($_SESSION['GroupID'] != $pagedetails[8]) { echo "This is a restricted area. Please login.<br/><br/>"; echo "<form action='index.php' method='get'>Username: <input type='text' name='Username'><br/>\n"; echo "Password: <input type='password' name='Password'><br/>\n"; echo "<input type='submit' name='Login' value='Login'></form><br/>\n"; exit; } } else { //check login details if user appears to be already logged in if (isset($_SESSION['Username'])) { $username = $db->escape ($_SESSION['Username']); $password = $db->escape ($_SESSION['Password']); $query = $db->query("select UserID, Password, RealName, Email, GroupID, AdminFlag from table_users where (Username = '$username')"); $r = $db->fetch_array($query); $dbpassword = $r['Password']; if ($password == $dbpassword) { $_SESSION['Username'] = $username; $_SESSION['UserID'] = $r['UserID']; $_SESSION['RealName'] = $r['RealName']; $_SESSION['Email'] = $r['Email']; $_SESSION['GroupID'] = $r['GroupID']; } } } //load template $tplate = new cTemplate($pagedetails['TemplateID'], $pagedetails['PageID']); $tplate->loadtemplate(); //add logout button if (isset($_SESSION['UserID'])) { echo "<div align='center'><small><a href='index.php?logout'>logout</a></small></div>\n"; } //log request if (getenv(HTTP_X_FORWARDED_FOR)) { $ip = getenv(HTTP_X_FORWARDED_FOR); } else { $ip = getenv(REMOTE_ADDR); } $log->writelog("/$sectionname/$pagename", "Access"); In the includes/templatefile.php file the code is like: function parsetemplate($templatefile) { global $db, $pageid, $pagedetails, $fullbaseurl, $adminemail; //first, find internal metacodes $pagetitle = stripslashes($pagedetails[1]); $lastupdate = date('l dS \of F Y h:i:s A', $pagedetails[5]); $sectiontitle = stripslashes($pagedetails[7]); $sectionname = stripslashes($pagedetails[6]); $templatefile = str_replace ("!PAGETITLE!", $pagetitle, $templatefile); $templatefile = str_replace ("!ADMINEMAIL!", $adminemail, $templatefile); $templatefile = str_replace ("!REQUEST_DOCUMENTID!", $_REQUEST['DocumentID'], $templatefile); $templatefile = str_replace ("!SECTIONTITLE!", $sectiontitle, $templatefile); $templatefile = str_replace ("!LASTUPDATE!", $lastupdate, $templatefile); $templatefile = str_replace ("!URL!", $_SERVER['REQUEST_URI'], $templatefile); $templatefile = str_replace ("!FULLBASEURL!", $fullbaseurl, $templatefile); $templatefile = str_replace ("!KEYWORDS!", $pagedetails[10], $templatefile); if ($_SESSION['UserID'] != "") { $templatefile = str_replace ("!LOGINDETAILS!", "- You are logged in as " . $_SESSION['Username'], $templatefile); } else { $templatefile = str_replace ("!LOGINDETAILS!", "", $templatefile); } $templatefile = str_replace ("!SECTIONLINK!", $fullbaseurl . "?/" . $sectionname . "/Home/", $templatefile); What i am getting via the links a Code: [Select] http://www.mydomain.com/?/Shop/Home/ How do i get rid of the "?" mark and the "/Home/". The /Home/ is also stored in the Database. I have tried a number of solutions by getting rid of the "?" and "/Home/" but i get the 404 error as the code shows. Can you please help with this? Hey all, I am not familiar with php coding at all and was wondering if anyone could help me re-code the below to being php 7 compatible. After using a php testor, it says mysql_connect is deprecated and needs to use the alternative mysqli_connect instead. How would I rewrite the below to be in the mysqli_connect format? Thank you in advance <?php $db = "MyDatabaseName"; //set this to the name of your database $host = "localhost"; //set this to the name of your host $user = "MyUserName"; //set this to your db user name $pass = "MyPassword"; //set this to your db password $con = mysql_connect("$host","$user","$pass"); $table = "MyDatabaseTableName"; //set this to the name of the table that holds the card info. $con= mysql_connect("$host","$user","$pass"); if(!$con) { $connect_error = "Failed at mysql_connect. "; echo"error at db connect"; exit(); } $tablewidth = "490";//set the main table width on the spread pages with this. $imagedirectory = "images/"; //main image directory $largeimagedirectory = "images/medium/"; srand((double)microtime()*1000000); ?>
Hello, I have the following code, Code: [Select] $lc_align = ''; if(isset($HTTP_GET_VARS['language'])) { $env_language = $HTTP_GET_VARS['language']; $language_query = tep_db_query("select languages_id from ". TABLE_LANGUAGES . " where code ='" . $env_language . "'"); $language_arr = tep_db_fetch_array($language_query); $language_id = $language_arr['languages_id']; } else { $language_id = (int)$languages_id; } $products_to_catagories_query = tep_db_query("SELECT categories_name FROM ". TABLE_PRODUCTS_TO_CATEGORIES ." p2c, ". TABLE_CATEGORIES_DESCRIPTION ." cd WHERE p2c.products_id = " . (int)$listing[$x]['products_id'] . " and p2c.categories_id = cd.categories_id and language_id ='".(int)$language_id."'"); $category_list = " "; do { if($category_list != " ") $category_list .=" , "; else $products_to_categories_array = tep_db_fetch_array($products_to_catagories_query); $category_list .= $products_to_categories_array['categories_name']; } while($products_to_categories_array = tep_db_fetch_array($products_to_catagories_query)); $category_list .="<br>"; if (isset($HTTP_GET_VARS['manufacturers_id'])) { $lc_text = $category_list . '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing[$x]['products_id']) . '">' . $listing[$x]['products_name'] . '</a>'; } else { $lc_text = $category_list . '<B><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing[$x]['products_id']) . '">' . $listing[$x]['products_name'] . '</a></B> '; } break; and the output for this above code is, Output1,Output1,Output1,Output1,Output1,Output1,Output1,Output1, Brake Shoes For Cars Having trouble getting the code to output it this way, Brake Shoes For Cars Fits: Output1,Output1,Output1,Output1,Output1,Output1,Output1,Output1, Thanks for any help. JR This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319450.0 Hello! I want to be able to make a code that tells me how many saturdays have passed till today. I've tried a couple of things but nothing. Any help?! Thanks! In my main script I set $errorArray with values when required survey questions go unanswered. The ne code that checks for missing required values is working perfectly, and right before I pass $errorArray to a function which rebuilds the survey questions - this time with the error messages - I do a var_dump($errorArray) and that array has errors in it as expected. But while my function that re-builds the survey questions gets called and does indeed re-build the survey questions, the $errorArray isn't getting pased for some strange reason? (I'm not sure if i have ever passed an array to a function before.) In my function I have... function generateSurveyItem($dbc, $questionNo, $questionID, $surveyResponseArray=NULL, $errorArray=NULL){ }
When I var_dump($errorArray) at the top of the function, and submit a blank form, I end up with a blank page and a file path to my PHP script ending with... /public_html/utilities/function.php:3010:null
Questions: 1.) What is happening?
2.) I thought =NULL in the parameter list just meant that the argument is "optional"?
3.) I am able to successfully pass $surveyResponseArray to this function, so what is up with $errorArray?
P.S. When I run things, and submit an empty form - thus no "required" fields get completed - the survey gets re-displays, and any values chosen are "sticky", but my error messages should also be displayed to let the user know what is mising, and that is the part that isn't working? This has to be something silly stupid to fix... Edited February 16 by SaranacLake Hi, I want to update a row when 30sec are passed on a page. If not nothing happens(not updating row). Example: You go to example.php>> 30sec pass, update row>> 30sec not over, no update. it does not necessarily have to be second it can be minutes or hours. Who can help me? Hope its clear enough, Thanks. Good day freaks. I am pulling my hair out trying to figure this out. I am trying to pass patterns for preg_replace through $_GET and then apply them. The object is to highlight certain words in a chunk of text. Say I want to highlight bounded cases of 'foo' in the text. So here's what I'm doing: Code: [Select] $string = urldecode($_GET['highlight1']); // $string contains \\bfoo\\b $search = preg_replace('/\\\\b/','b',$string); // $search contains \bfoo\b as I want it to $replace = preg_replace('/\\\\b/','',$string); // $replace contains \foo\ >:-( $pattern = '/'.$search.'/i'; $text = preg_replace($pattern,'<span style="background-color:yellow;">'.$replace.'</span>',$text); The problem is that no matter what I try for the pattern for $replace, it winds up with backslashes around foo. How do I get rid of these? (I should say that I discovered the pattern/replace for the $search string by experimentation and I don't understand why the pattern doesn't pick off all the backslashes in that case--but at least it does what I want). TIA Steve I am trying to pass a php variable to javascript but it's not working. This is the "sketch" of my code. <?php $url="asset/go/"; ?>
<!DOCTYPE html> <html> <head> <title>Page Title</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head> <body> <script> var user="mayor"; var url ='<?php echo json_encode($url); ?>'; if(user=="mayor"){ alert(url); } </script> </body> </html> As it is now, it comes with the output below: <?php echo json_encode($url); ?> If I remove the quotation around the php in d jQuery, it throws an error in syntax. Also both codes are located in the same file named test.php Thanks in advance. Edited April 18 by Abel1416Hi all, How can I check in PHP if this date has already passed in the following format: 2012-12-12 Hi I am trying to get all variables passed in a url string and wondered how would i do it? I dont know what they are yet and i need to set key as value. Any help?
Hi All, I've been trying to access xml data from an API feed, but it needs a Variable to be passed to an include file without a form. the include is at the header of the page. in the code below, i'm trying to retrieve the variable $project_add from the $xml_2 feed. $proj_add_ID comes from another feed and is being passed ok. foreach ($projects_1 as $proj_1) { $job_no =$proj_1['job_no']; $job_name =$proj_1['job_name']; $job_status =$proj_1['job_status']; $job_staff =$proj_1['job_staff']; $job_due =$proj_1['job_due']; $clr_1 = $colors_1[$job_status]; if ($err_2) { echo "cURL Error #:" . $err_2; } else { $_POST['job_id']= $job_no; $xml_2=simplexml_load_string($response_2) or die("Error: Cannot create object"); $proj_add = $xml_2->xpath("CustomFields/CustomField[ID ='$proj_add_ID']"); foreach($proj_add as $item_2) { $project_add = "$item_2->Text"; } echo "<div class='row no-gutters'>"; echo "<div class='col-sm bg-white border rounded'><a href='managejob.php?job_id=$job_no' class='text-left ml-1'><strong>$job_no</strong></a></div>"; echo "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_name</p></div>"; echo "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'></p>$project_add</div>"; echo "<div class='col-sm-2 bg-white border rounded'>" . state_dropdown_1($job_no, $job_status, $clr_1) . "</div>"; echo "<div class='col-sm-2 bg-white border rounded'><p class='text-left ml-1'>$job_staff</p></div>"; echo "<div class='col-sm-2 bg-white border rounded'><form action='CALL_API_PUTTaskDate.php' method='POST'>" . "<input type='hidden' name='task_ID' value ='". $jdata['task_ID'] ."'>" . "<input type='hidden' name='est_min' value ='". $jdata['est_min'] ."'>" . "<input class ='form-control bg-white text-dark font-weight-bold' type='date' name='start_date' value='" . date('Y-m-d', strtotime( $jdata['display_date_1'] )) . "' onchange='this.form.submit()'>" . "</form></div>"; echo "<div class='col-sm bg-white border rounded'><p class='text-left ml-1 mt-1'><strong>" . date('d/m/Y', strtotime( $jdata['display_date'])) . "</strong></p></div></div>"; } The include file is like this / collect Custom Felds if ($_SERVER["REQUEST_METHOD"] == "POST") { // collect value of status input field $job_no = $_REQUEST['job_id']; } if (isset($_POST['job_id'])) { $job_no = $_POST['job_id']; } if (isset($_GET['job_id'])) { $job_no = $_GET['job_id']; } $curl_2 = curl_init(); curl_setopt_array($curl_2, array( CURLOPT_URL => "https://api.xxx.com/job.api/get/$job_no/customfield?apiKey=xxx&accountKey=xxx", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "Accept: */*", "Accept-Encoding: gzip, deflate", "Cache-Control: no-cache", "Connection: keep-alive", "Host: api.xxx.com", "Postman-Token: xxx", "User-Agent: PostmanRuntime/7.17.1", "cache-control: no-cache" ), )); $response_2 = curl_exec($curl_2); $err_2 = curl_error($curl_2); curl_close($curl_2); The problem is the variable $job_no isn't getting passed to CURLOPT_URL so it's not retrieving the data required. i need to be able to retrieve this data without submitting a form as it's in a foreach loop and the Id is specific to each iteration. is there a way to do this? I have been able to achieve this by putting the include within the div tags that it will be displayed but it just slows down everything too much and hangs. Any help will be much appreciated. Kind regards, Michael Bennington. I have a forum script I made that has thread bumping for the thread creator only. I am trying to limit the amout of time the creator can bump to be every 10 minutes. Here's my code. list($title, $creator, $locked, $hidden, $moved, $lastbump) = mysql_fetch_row(mysql_query('SELECT title, creator, locked, hidden, moved, lastbump FROM forum_threads WHERE id="'.$_GET['threadid'].'"')); if(($locked == 1 || $hidden == 1 || $moved == 1) && !$_SESSION['rights'] == 2){ header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } else { if($creator == $_SESSION['username']){ mysql_query("UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."'"); } else { header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } } Hey all, I'm very new to php and am having an issue writing to my database with a passed value and info taking from a form and am lost as to what to do. The $comm_id is the value I am getting from another php page that I am passing in the link from the other page. I need to insert that value, the session variable, and the $cmt value, which is taken from the user input from the form. As it stands now, when I run this, the $comm_id and $u_id insert and the $cmt is blank, BUT $cmt is echoing on the screen with the proper value. Any tips or direction would be great as i've been trying to sort this out for days now and i'm stumped. <?php $host='localhost'; $user='username'; $password='password'; $dbname='db_a'; session_start(); $id_link=mysql_connect($host,$user,$password); mysql_select_db($dbname, $id_link); $comm_id = $_GET['commId']; $u_id = $_SESSION['userId']; echo $comm_id; echo $u_id; $cmt = $_POST["comm"]; mysql_query("insert into Comments values($u_id, $comm_id,'$cmt');"); echo $cmt; ?> <FORM ACTION="test.php" METHOD="POST"> <input type="text" name="comm"> <input type="SUBMIT"> </FORM> <?php global $places; $comm = $GLOBALS["location"]; $comm=trim($comm); while(list($one,$two) = each($places)) { echo "<option value=\"$two\""; if ( $two == $comm)echo "selected "; echo ">$two</option>\n" ; } ?> Variable passed to each() is not an array or objectHi, my code works fine but it is giving the error message Please can anyone help? Thanks i've been programming in PHP for years, and have done a substantial amount of work on applications of this nature. this problem has me stumped, not because i can't fix it (i did), but because i have no idea what the problem is. there are hundreds of lines of code involved here, so i'll break it down into a post-friendly format. take this for example, and forgive any typos. it's late, and i've been beating my head against this for over two hours... =\ this is from my form: Code: [Select] /* ... numerous form fields being passed as $_REQUEST arrays */ <input type="hidden" name="option_id[]" value="<?php print $query_result->option_id; ?>" /> /* a couple hundred more lines */ here's the DB update handler: Code: [Select] if (!empty($_REQUEST['option_name'])) { foreach ($_REQUEST['option_name'] as $k => $v) { if ($v != '') { $option_id = $_REQUEST['option_id'][$k]; $option_name = $_REQUEST['option_name'][$k]; $option_price = $_REQUEST['option_price'][$k]; $option_desc = htmlentities($_REQUEST['option_desc'][$k], ENT_QUOTES); if (!$option_id = '') { $sql_options = "UPDATE table SET" . " option_name = '" . $option_name . "', option_price = '" . $option_price . "', option_desc = '" . $option_desc . "' WHERE option_id = '" . $option_id "'"; if (!$query_function($sql_options)) { $error = true; } } else { $sql_options = "INSERT INTO table (option_name, option_price, option_desc)" . " VALUES ('" . $option_name . "', '" . $option_price . "', '" . $option_desc . "')"; if (!$query_function($sql_options)) { $error = true; } } } } } the above code doesn't post to the database because the $option_id variable returns a null value. however, if i replace the $option_id variable where i build the query string with $_REQUEST['option_id'], it works just fine. Code: [Select] /* in relevant part */ $sql_options = "UPDATE table SET" . " option_name = '" . $option_name . "', option_price = '" . $option_price . "', option_desc = '" . $option_desc . "' WHERE option_id = '" . $_REQUEST['option_id'] . "'"; needless to say i was infuriated by having spent a couple of hours to come to this conclusion. i only used the variables in the first place because i need to expand the function that this lives inside and i don't want to have to type $_REQUESTs over and over. the only thing i can think is that it might be a type issue. the data is coming out of the mysql table from an INT field and being placed into the value for the hidden field straight from the row collection. would forcing a variant data type by not strongly typing my variable have caused this problem? i haven't tested the theory because i'm still too ticked off to open my code editor. i'm bouncing this off the community and posting my experience in the hope that it might help someone who comes after. hi there, this is a general question where i am confused over long time.. what is the used of passing big encrypted strings in the url? most of the time i see in big sites like google / yahoo. and what are the uses of this in real time .. or they are just made big to confuse hackers?. any explanation would be highly helpful!. example as below http://yahoo.com/_ylt=AsXHbMLeE2zV.1Tq082xTdiuitIF/SIG=11licq9d2/EXP=1283427670/**http%3A//mail.yahoo.com/%3F.intl=en http://click.email.microsoftemail.com?qs=06f2de8ca524e4650483090ed07957e8da3dbc0db662e7f97fa1b5d384b45a28800d5407dd3daa63 Hi, I am a beginner with php and I am having a hard time understanding a section in my code. The part I dont get is why we have to minus 1 from the number being passed into the array. For example, $FaceNamePlural[$die1-1] I tried looking at it over and over but I'm still very confused. Can anyone help me on this...Thanks. Code: [Select] <!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> </head> <body> <?php $FaceNameSingular = array("one", "two", "three", "four", "five", "six"); $FaceNamePlural = array("ones", "twos", "threes", "fours", "fives", "sixs"); function CheckForDoubles($die1, $die2) { global $FaceNameSingular; global $FaceNamePlural; if($die1 == $die2) // doubles echo "The roll was double ", $FaceNamePlural[$die1-1], "<br />"; if($die1 != $die2) //not doubles echo "The roll was a ", $FaceNameSingular[$die1-1], " and a ", $FaceNameSingular[$die2-1], ".<br />"; } function DisplayScoreText($Score) { if($Score == 2) echo "you roll snake eyes! <br />"; if($Score == 3) echo "you roll loose duece! <br />"; if($Score == 5) echo "you roll fever five! <br />"; if($Score == 7) echo "you roll natural! <br />"; if($Score == 9) echo "you roll nina! <br />"; if($Score == 11) echo "you roll yo! <br />"; if($Score == 12) echo "you roll boxcars! <br />"; } $dice = array(); $dice[0] = rand(1,6); $dice[1] = rand(1,6); $Score = $dice[0] + $dice[1] ; echo "<p>"; echo "The total score for the roll was $Score . <br />"; CheckForDoubles($dice[0],$dice[1]); DisplayScoreText($Score); echo "</p>"; ?> </body> </html> Folks, I am trying to grab the value selected in a Dropdown, with $_GET['q']. Then i am echoing the grabbed value. Funny thing is, when i select value from HTML dropdown (onchange="location=this.value"), and when a new value is selcted, it appaears in url like this: Quote http://www.abc.com/?search=selected-value.html But when i try to grab and echo the value of 'q' it gets passed only when i refresh the page and not when i change my selecting in dropdown. Am not sure whats happening, can someone help me on this? Cheers NT |