PHP - Posting Variable From Hyperlink
Can someone tell me why this gives me undefined variables? The $id variable is showing up fine in this bit of code. When I click the link it is supposed to pull the data from the database related to the $id.
Code: [Select] <a href='javascript: window.document.Vids<?php echo $id; ?>.submit();'>Watch</a> <form name="Vids<?php echo $id; ?>" action="<?php echo $PHP_SELF; ?>" method="post"> <input value="<?php echo $id; ?>" type="hidden" name="Vids" /> </form> here is the code which is supposed to display the info. Code: [Select] if (isset($_POST['Vids'])) { $result = mysqli_query($link, "SELECT * FROM vidaud where id =".$_POST['Vids']); echo $id; the error i get is Quote Notice: Undefined variable: id in /services5/webpages/util/b/b/bbctech2.site.aplus.net/public/dbsite/a_newsite/sermons.php on line 32 I'm just not sure why the $id variable isn't being posted by my form and read by the code. Thanks. Similar TutorialsHello im wondering how i can make a hyperlinks adress be a set after a variable. this is my php: $result1 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1;"); $result2 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1,1;"); <html> <a href="???"> <p class="note-general"> The first link </p> <a href="???"> <p class="note-general"> The the second link </p> </html> The important thing is that the url from $result1 will link under "the first link" and url from $result2 link under "the second link". The $_SESSION['record_to_chage'] variable is set- I know this as I can echo it out. $openedfile = file("myfile.txt"); sort($openedfile); // foreach($openedfile as $key => $newpick) { echo "<a href=\"/editpage.php?request=$_SESSION['record_to_chgange']&newcat=$newpick\" target=\"_parent\">$newpick</a>"; echo "<br>"; } The Resulting error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in For the life of me I can not figure where I am going wrong. Going to get coffee and some fresh eyes. Cheers This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=347224.0 I have a php index page that includes a form page with a delete button for that row. When I hit the delete button nothing happens. I am not sure if the variable is not passing or if the index.php page is not processing it correctly. Here is the index page that includes the form page: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Welcome Page Test</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <?php if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); $_GET = array_map('stripslashes_deep', $_GET); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); $_REQUEST = array_map('stripslashes_deep', $_REQUEST); } if (isset($_GET['addjoke'])) { include 'form.html.php'; exit(); } $link = mysqli_connect('localhost', 'root', 'password'); if (!$link) { $output = 'Unable to connect to the database server.'; include 'output.html.php'; exit(); } if (!mysqli_set_charset($link, 'utf8')) { $output = 'Unable to set database connection encoding.'; include 'output.html.php'; exit(); } if (!mysqli_select_db($link, 'database')) { $output = 'Unable to locate the database.' . mysqli_error($link); include 'output.html.php'; exit(); } if (isset($_POST['joketext'])) { $joketext=mysqli_real_escape_string($link,$_POST['joketext']); $sql = "INSERT INTO jokes2 (joketext, jokedate) VALUES ('$joketext', CURDATE() )"; if (!mysqli_query($link,$sql)) { $error = 'Error adding submitted joke: ' . mysqli_error($link); include 'error.html.php'; exit(); } header('Location: .'); exit(); } if (isset ($_GET['deletejoke'])) { $id= mysqli_real_escape_string($link,$_POST['id']); $sql = "DELETE FROM jokes2 WHERE id='$id'"; if(!mysqli_query($link,$sql)) { $error= 'Error deleting actor: ' . mysqli_error($link); include 'error.html.php'; exit(); } header('Location: .'); exit(); } $result = mysqli_query($link, 'SELECT jokes2.id, joketext, name, email FROM jokes2 INNER JOIN author ON authorid = author.id'); if (!$result) { $error = 'Error retrieving data' . mysqli_error($link); include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $jokes[] = array('id'=>$row['id'], 'joketext'=>$row['joketext'], 'name'=>$row['name'], 'email'=>$row['email']); } include 'jokes.html.php'; ?> </body> </html> The $_GET array should be getting the variable id passed when the Delete button is pressed on the form, but nothing is happening when I press the button. Here is the form: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Welcome Page Test</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <p> <a href="?addjoke">Add Joke </a> </p> <p> Here are all the jokes: </p> <form action="?deletejoke" method="post"> <?php foreach($jokes as $joke): ?> <p> <?php echo htmlspecialchars($joke['id'], ENT_QUOTES, 'UTF-8'), htmlspecialchars($joke['joketext'], ENT_QUOTES, 'UTF-8'), htmlspecialchars($joke['name'], ENT_QUOTES, 'UTF-8'), htmlspecialchars($joke['email'], ENT_QUOTES, 'UTF-8'); ?> <input type="hidden" name="id" value="<?php echo $joke['id']; ?>" /> <input type="submit" value="Delete"/> </p> </form> <?php endforeach; ?> </p> </body> </html> All of my other variables seem to be passing just fine. Any ideas why this one is a problem? I'm new at PHP and have a problem. I have a MySql database with lists of students grouped into classrooms. A typical group is shown in the attached screenshot screenshot.docx. I want to be able to select one or more of the names by using the associated checkbox, and upgrade a student or students into a different group as defined in the radio button list also in the screenshot. I have the rudiments of the file attached, but I have absolutely no idea how I can post the array so that the records are updated. Each student has an individual record with a field name userGroup which holds a string nominated by their classroom teacher, such as "year7", "year 8" and so on while they are in one of the several classrooms, but when they leave school this is recorded in a field named noGroup with a value of 0 or 1. I can post further details as required, but it would be great if someone could help me. Hey guys Just a quick question: How to embed hyperlink into a database cell? Basically I echo out a table on the user interface of my site and there's an URL in one of the cells I want the user to access it by clicking on it, without copying and pasting the URL into the URL bar of the browser I tried updating the cell in phpmyadmin using <a href = http://www.example.com>http://www.example.com</a> but didn't work out, the resulting cell only had the text format Any help would be appreciated Thanks. i'm doing a form that posts values to XML, and i don't know how. can someone help me with a quick lesson in passing variables/XML data? i don't even know what question to ask, actually - the XML format i've been given is: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <lead> <innerNode></innerNode> <last_name>Smith</last_name> <first_name>John</first_name> </lead> and what i've come up with so far is this, but i don't even know if i'm on the right track: Code: [Select] $last_name = $_REQUEST['l_name']; $first_name = $_REQUEST['f_name']; $url = "http://url.com/leads"; $post_string = '<?xml version="1.0" encoding="UTF-8"?> <lead> <innerNode></innerNode> <last_name>'.$last_name.'</last_name> <first_name>'.$first_name.'</first_name> </lead>'; $header = "POST HTTP/1.0 \r\n"; $header .= "Content-type: text/xml \r\n"; $header .= "Content-length: ".strlen($post_string)." \r\n"; $header .= "Content-transfer-encoding: text \r\n"; $header .= "Connection: close \r\n\r\n"; $header = $post_string; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); $data = curl_exec($ch); if(curl_errno($ch)) { print curl_error($ch); } else { echo "yay"; curl_close($ch); } i'm being told "should return a response.xml with either a success or failure post status." which is confusing me can someone help a bit? thanks very much... GN Hello Everyone. Im new here, but hopefully you can help me I have designed a CMS using PHP and MySQL. Its fairly basic, I'll talk you thorugh the stages: 1.) The user inputs their product information into a form and the script uploads it to the database giving it a unique ID. 2.) The user is then asked to upload a big image for that product, the image is added to a folder on the server. 3.) Now the user must choose a thumbnail and it uploads in the same manner. My problem is linking the two together... So far I have this: <?php $images = "products/"; $big = "big/"; $cols = 2; if ($handle = opendir($images)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != rtrim($big,"/")) { $files[] = $file; } } closedir($handle); } $colCtr = 0; echo '<table width="212" cellpadding="2"><tr>'; foreach($files as $file) { if($colCtr %$cols == 0) echo '</tr><tr><td colspan="2"></td></tr><tr>'; echo '<td wdith=50% align="center"><a href="' . $images . $big . $file . '"><img border="0" class="gradualfader" src="' . $images . $file . '" /></a></td>'; $colCtr++; } echo '</table>' . "\r\n"; ?> This displays a lovely list of thumbnails, which when clicked opens the larger image. What i would like to do is insert a "ID" for each image so the product data can be grabbed from the database ? I think i've explained this well enough? reply if not and illl try and add more detail. To see it in action you can go to http://design.surreylabs.co.uk/parliament/2/products.php Thanks in Advance! I have searched this forum and haven't found a solution to my question. please don't flame... I am trying to send a table field from one page to another. the field i'm sending is id. I have managed to populate the field updateplayer.php?id=***** now i have a syntax error trying to get the field to show up on the update player form. Parse error: syntax error, unexpected T_VARIABLE in /home/netman13/public_html/bccsl.org/managers/updateplayer.php on line 7 The id field is supposed to get the id variable from the previous page ?id=***** Here is the update player code: Code: [Select] <?php include 'dbc.php'; $qP = "SELECT * FROM players WHERE id = '$_GET['$id']' "; $rsP = mysql_query($qP); $row = mysql_fetch_array($rsP); extract($row); $id = trim($id); $first = trim($first); $last = trim($last); $address = trim($address); $city = trim($city); $postal = trim($postal); $phone = trim($phone); $feet = trim($feet); $inches = trim($inches); $weight = trim($weight); $birth = trim($birth); $status = trim($status); $number = trim($number); mysql_close(); ?> <!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>Update Player</title> <link href="styles.css" rel="stylesheet" type="text/css"> <script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script> <script> $(document).ready(function(){ $.validator.addMethod("username", function(value, element) { return this.optional(element) || /^[a-z0-9\_]+$/i.test(value); }, "Username must contain only letters, numbers, or underscore."); $("#regForm").validate(); }); </script> </head> <body> <script language="JavaScript"> <!-- /*********************************************** * Required field(s) validation v1.10- By NavSurf * Visit Nav Surf at http://navsurf.com * Visit http://www.dynamicdrive.com/ for full source code ***********************************************/ function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("first", "last", "address", "city", "postal", "phone", "hft", "hinch", "weight", "birthdate", "status"); // Enter field description to appear in the dialog box var fieldDescription = Array("First Name", "Last Name", "Address", "City", "Postal Code", "Phone Number", "Feet", "Inches", "Weight", "Birthdate YYYY/MM/DD", "Player Status"); // dialog message var alertMsg = "Please complete the following fields:\n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script> <table width="100%" border="0" cellpadding="5" cellspacing="0"class="main" > <tr> <td colspan="1"><p></p></td> </tr> <tr> <td width="17%"><? //Call Menu include 'menu.php'; ?></td> <td width="3%"> </td> <td width="80%"><p align="center">Update Player Information</p> <p align="center"><? if (isset($_GET['msg'])) { echo "<div class=\"msg\">$_GET[msg]</div>"; } ?></p> <p align="center"> </p> <form action="playerupdate.php" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return formCheck(this);"> <table width="653" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="148" height="29">First Name</td> <td width="153"><label> <input name="first" type="text" disabled="disabled" class="required" id="first" value="<?=$first ?>" /> </label></td> <td width="91" height="30">Last Name</td> <td width="261"><label> <input name="last" type="text" class="required" id="last" value="<?=$last ?>" readonly="readonly" /> </label></td> </tr> <tr> <td height="30">Address</td> <td><input name="address" type="text" class="required" id="address" value="<?=$address ?>" /></td> <td>City</td> <td><label> <input name="city" type="text" class="required" id="city" value="<?=$city ?>" /> </label></td> </tr> <tr> <td height="28">Postal Code</td> <td><label> <input name="postal" type="text" class="required" id="postal" value="<?=$postal ?>" size="12" /> </label></td> <td>Phone Number</td> <td><label> <input name="phone" type="text" class="required" id="phone" value="<?=$phone ?>" size="13" /> </label></td> </tr> <tr> <td height="29">Height <strong>(ft / in)</strong></td> <td><label> <input name="feet" type="text" class="required" id="feet" value="<?=$feet ?>" size="3" /> / <input name="inches" type="text" class="required" id="inches" value="<?=$inches ?>" size="3" /> </label></td> <td>Weight (lbs)</td> <td><input name="weight" type="text" class="required" id="weight" value="<?=$weight ?>" size="5" /></td> </tr> <tr> <td height="35">Birthdate <strong>(yyyy/mm/dd)</strong></td> <td><label> <input name="birth" type="text" class="required" id="birth" value="<?=$birth ?>" size="13" readonly="readonly" /> </label></td> <td><label>Player Type:</label></td> <td><p> <label> <input name="status" type="radio" id="type_0" value="1" checked="checked" /> Church</label> <br /> <label> <input type="radio" name="status" value="2" id="type_1" /> Import</label> <br /> <label> <input type="radio" name="status" value="3" id="type_2" /> Witness</label> <br /> </p> <label></label></td> </tr> <tr> <td height="35">Player ID:</td> <td><input name="id" type="text" id="id" value="<?=$id ?>" readonly="readonly" /></td> <td>Player Number:</td> <td><input name="number" type="text" class="required" id="number" value="<?=$number ?>" size="5" /></td> </tr> <tr> <td height="29"> </td> <td><label></label></td> <td><p> <input name="teamid" type="hidden" id="teamid" value="<? echo $_SESSION['teamid'];?>" /> <input name="division" type="hidden" id="division" value="<? echo $_SESSION['divisionid'];?>" /> <input type="hidden" name="currentdate" size=11 > </p> <p> <input name="teamname" type="hidden" id="teamname" value="<? echo $_SESSION['team_name'];?>" /> </p> <p> <script> /*Current date in form credit: JavaScript Kit (www.javascriptkit.com) Over 200+ free scripts here! */ var mydate=new Date() var theyear=mydate.getYear() if (theyear < 1000) theyear+=1900 var theday=mydate.getDay() var themonth=mydate.getMonth()+1 if (themonth<10) themonth="0"+themonth var theday=mydate.getDate() if (theday<10) theday="0"+theday //////EDIT below three variable to customize the format of the date///// var displayfirst=theyear var displaysecond=themonth var displaythird=theday //////////////////////////////////// document.form.currentdate.value=displayfirst+"/"+displaysecond+"/"+displaythird </script> <input name="approved" type="hidden" id="approved" value="0" /> </p></td> <td> </td> </tr> </table> <p align="center"> <label> <input type="submit" name="submit2" id="submit2" value="Submit" /> </label> <label> <input type="reset" name="reset2" id="reset2" value="Clear" /> </label> </p> </form> <p align="center"> </p> <p align="center"> <label></label> </p></td> </tr> <tr> <td colspan="3"> </td> </tr> </table> <p> </p> </body> </html> Thanks for your help. This forum has been an awesome resource for me. I am using xampp. <a href="/">Home Page</a>The above code (when clicked in browser) takes me to the localhost instead of localhost/website How can i clear this issue? Hi there, im trying to echo a hyperlink and parse a url parameter. Its not quite working as iam getting T-string error. If someone with fresh eyes could quickly glance for me that would be ace. Code: [Select] <?php if ($row_ship['PlayerName'] == '$_SESSION['MM_Username']'){ echo '<a href="ship_edit.php?recordID='.$row_Ship['ShipID'].'">Edit</a>';} ?> Thank You I am having problems with a line of code. This is what I have so far. I am missing a "," according to my error message. Im trading in deep water with this line of code. I am trying to use the data from my echo state to be a hyperlink... If that makes sense. Code: [Select] echo "\t" . '<td><a href="' . APP_ROOT . 'onlinebanking/viewtransactions.php">. $account['BankAccountID'] . </a>' '</td>' . "\n"; hello, i have a while loop that displays multiple tables of data depending on how many are in the database... i have a link if you click it will redirect to another page that prompts you to save an xls file with the table data... this was all working for me before when i had the while loop display rows of data in one table...well i decided that i would like the while loop to display a separate table each time... when i changed it... the xls file only shows one table of data... how can i set up so it will export all tables of data... is there some kind of loop i can set up for it to append the tables?? i have the table data all in a variable $table which i put into a hidden form field that redirects to the xls export page.... any help is appreciated... <!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>Admin</title> </head> <body> <?php $sql= mysql_query("SELECT * FROM programs") or die (mysql_error()); while($row = mysql_fetch_array($sql)){ $table = "<table border='1' width='600' style='border-collapse:collapse;'>" . "<th colspan='4'>Programs</th>" . "<tr>" . "<td>ID</td>" . "<td>Views</td>" . "<td>Enabled</td>" . "</tr>"; $prog_titles = $row['titles']; $prog_titles = explode(',' , $prog_titles); $table .= "<tr>" . "<td>".$row['id']. "</td>" . "<td>".$row['views']. "</td>" . "<td>".$row['enabled']. "</td>" . "<td></td>" . "</tr>" . "<tr>" . "<td>Title ID</td>" . "<td>Name</td>" . "<td>Description</td>" . "<td>Image</td>" . "</tr>" ; foreach ( $prog_titles as $title ) { $sql2= mysql_query("SELECT * FROM titles WHERE title = '$title' "); $row2 = mysql_fetch_array($sql2); $table .= "<tr>" . "<td>" . $row2['id'] . "</td>" . "<td>" . $row2['title'] . "</td>" . "<td>" . $row2['description'] . "</td>" . "<td>". "<img width='50px' src='images/" . $row2['img'] . "'/></td>" . "</tr>" ; } // close foreach $table .= "</table>"; echo $table; echo "<br /><br /><br />"; } // close while ?> <br /> <br /> <FORM action="export.php"> <INPUT type="submit" value="Export to XLS"> <INPUT type="hidden" value="<?php print $table;?>" name="export"> </FORM> </body> </html> Is there anyway to do this: my form is posting to self, then checking login creds. if they are incorrect it spits out "invaild bla bla" but if they are correct send them to a different page? here is the short version of what I have. if(isset($_POST['submit'])) { //check inputs vs db if ($check) { header("Location: http://". $_SERVER['SERVER_NAME']."/include/process_renew.php"); } else { echo "<font color='red'>Username or Password did not match.</font> <br /><br />"; } } } I tested it using echo first and it worked fine then replaced the echo with header and now when I submit it just refreshes the page. is this not possible? i am basically trying to retrieve the response of a chatbot from mysql database with query below. As i run script i don't get any error from the server but it seems the post doesn't take $data2 which is an array that includes the keys "user_id" and "text" that are normally accepted (eg: $dmessage->post('direct_messages/new/wrap_links=true', 'text'->'example', '12345'); As result of the above i can't post to Twitter the chatobot response as the recipient (my other twitter account) doesn't get the answer...what do you think? Code: [Select] include_once ('connect.php'); connect_to_database(); $query2 = mysql_query ("SELECT response FROM conversation_log WHERE id = (SELECT MAX(id) FROM conversation_log)") or die (mysql_error()); $row = mysql_fetch_row($query2); $response = $row[0]; //this is the array with the parameters to be used to send bot responses via Twitter API. It normally takes $data2 = array("text"=>"$response" , "user_id"=> "$userid"); //this modifies the array values with response e userid fields $data2["text"] = "$response"; $data2["user_id"] = "$userid"; require_once('config_oauth.php'); // includes the applications Oauth keys require_once($_SERVER['DOCUMENT_ROOT'].'Program-O/gui/xml/oauth/twitteroauth.php'); //Full path to twitteroauth.php library $dmessage = new TwitterOAuth($consumer_key,$consumer_secret, $oAuthToken, $oAuthSecret); // create new instance with the credentials //sends the bot response via Twitter API by going through the array $data2 $dmessage->post('direct_messages/new/wrap_links=true', $data2); the code is in a form whose method = "post". i have failed to echo $r_in. i eed help on this. $lowest_time = 30 - 14; $adder = 2*5*9; echo '<table width="526" border="0"><tr> <td width="169"> <input type="text" name="$r_in" value="'.$lowest_time.'" style="width:169px" readonly="readonly" class="text_non_color"/></td> <td width="169"> <input type="text" name="$r_out" value="'.$adder.'" style="width:169px" readonly="readonly" class="text_non_color"/></td> </tr></table>'; might have it nevermind. I have this code with clears the input box onclick... Code: [Select] <input type="text" name="username" value="Username" onclick="value=''"/> however is there any way to use php to get the value of username, before its posted? that way i can make it so it only clears if the value of username is "username" TWO questions: I haven't actually CONNECTED and POSTED. My form has two input fields that combine in a TOTAL field. I notice that the address bar is carrying TOTAL=input1+input2 when it TRIES to connect. Do I need to include the TOTAL field in the database if the info is NOT relavant data? the strg and chick TOTALS? Will the database accept PARTIAL data from a form that has 25 field with only 6 being populated for testing? |