PHP - Inserting Variable Into Iframe
I'm having problem with this code. It's supposed to pull a link from a database and feed it into an iframe src to make the video display on screen. I'm getting a white box... It seems like the "address" variable is getting dropped or something, out of scope? here is the code:
<?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "root", "Mm62Tic8FH", "music"); $rand_num; $rowcount; // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Attempt select query execution $sql = "SELECT * FROM songs"; if($result = mysqli_query($link, $sql)){ // query results stored in "result" if(mysqli_num_rows($result) > 0){ $rowcount = mysqli_num_rows($result); $rand_num = rand(0,$rowcount - 1); $address = "5"; echo "<table>"; while($row = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td>" . $row['artist_name'] . "</td>"; echo "<td>" . $row['song_name'] . "</td>"; echo "<td>" . $row['url'] . "</td>"; echo "<td>" . $row['item_id'] . "</td>"; echo "<td>" . $rand_num; echo "</tr>"; if ($rand_num == $row['item_id']) { $address = "https://www.youtube.com/embed/". $row['url']; } echo "----".$address."----"; } echo "</table>"; // Free result set mysqli_free_result($result); } else{ echo "No records matching your query were found."; } } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); ?> <iframe width="420" height="315" src=<?php $address ?>> </iframe>
Similar TutorialsHey all Im working on an assignment for school and currently I am trying to inser the variable $uid which currently = 2.. But for someone reason when the post happens it inserts a 0 instead of a 2. Here is my insert Code: [Select] mysql_query( "INSERT INTO blog_posts (title, post, author_id, date_posted) ". "VALUES ('$btitle', '$bpost', '$uid', CURDATE())" ); I've been working to have it so users of a database can upload a few images. The images would be stored in an image directory and have the file name of username-pic1, username-pic2... The code I have below pulls the user name from a previous posted form. There are several echo statements that are there only so I can see that variables are being passed along. Right now all the variables are being held fine until the form is processed and then the username variable goes dead. So the echo shows that it will be uploading the file as "username-pic1" but instead it uploads it as "-pic1". I've been looking at this way too much and I've have tried a number of minor variations but with no luck. Here is the code. Code: [Select] <form enctype="multipart/form-data" action="" method="post"> First pictu <input name="userfile[]" type="file" /><br /> <input type="submit" value="Upload" /> </form> <?PHP session_start(); ?> <?php $user = $_POST['record']; echo "username = $user<br><BR>"; $success = 0; $fail = 0; for ($i=0;$i<1;$i++) { $loc1 = "images/" ; $loc2 = "pic1." ; $uploaddir = $loc1 . $user . "-" . $loc2 ; echo "new file name = ".$uploaddir.$loc2 ; if($_FILES['userfile']['name'][$i]) { $uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$i]); $ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3)); if (preg_match("/(jpg|gif|png|bmp)/",$ext)) { if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploaddir . $ext)) { $success++; echo "File $success uploaded successfully."; echo "uploadfile = "; echo $uploadfile; echo "<br /> user = "; echo $_POST['record']; echo "<br /> uploaddir = "; echo $uploaddir; echo "<br /> new file name = "; echo $uploaddir.$ext; } else { echo "Error Uploading the file. Please try again.\n"; $fail++; } } else { $fail++; } } } ?> Does anyone have any suggestions as to what I am missing here? Thanks, Jim I have limited php skills but I thought it would be easy to write a script that would allow a user to use a html form to go from one page to another. I thought I could do this by simply inserting a php variable into the function tag but after many attempts I've had to give up. Here is my most recent attempt. <?php print '<form action= "flash_card_'.$_POST['number'].'.php" method= "post">'; print '<input type= "text" name= "word" value= "'.$_POST['number'].'" />'; print '<input type= "submit" name="submit" value="enter"/>'; print '</form>'; ?> My html editor says the syntax here is OK and the variable in the value attribute of the first input tag does what I want it to do. But the variable in the form tag does nothing. (If the user enters "2" in the text box, for example, the script attempts to send the user to the nonexistent "flash_card_.php" rather than to "flash_card_2.php" which is what I want.) any advice would be much appreciated regards to all from Forrest Cant seem to get this to work. The variable does echo the url. What is the correct way to use the variable inside the iframe? $url = $db->loadResult(); <iframe src="<?php echo $url; ?>"width="450" height="259" frameborder="0" allowfullscreen></iframe> Is there a way of getting a variable from an iframe to the parent? There are many ways to pass a variable from the parent to the iframe, but I'm not sure if you can pass a variable from the iframe back to the parent. When i refresh/update the iframe, i want the updated/new variable "id_no" to be passed to the parent file (so I can put this value in a form field). I tried the code below, but have been unlucky. Code: [Select] document.getElementById("iframe").this.form.id_no.value; Any ideas? i need to pass the id called id from the maim page to an iframe, but it failes to send. i'm wondering if anyone knows why it fails. Code: [Select] <iframe src="details.php?ID=<?php echo $ID; ?>" width="700px" height="150px"> </iframe> Hello all. I am very new to PHP, and I am not sure where to look or what I'm looking for in my current assignment. My task is to take in two numbers between 0-100. Once I take in that number, it should state beside it "The __ was accepted." The program should not accept any numbers greater than 100 or any characters. Once I do this, I must take a second number and do a similar thing. Finally, I must have a statement show up at the bottom stating which number is greater. Essentially, I need help in determining what I should use to place parameters, and how I can keep the program from echo ing any statement until input has been taken and tested for parameters. Any help you can provide will be greatly appreciated! I am trying to allow the user to update a variable he chooses by radio buttons, which they will then input text into a box, and submit, to change some attributes. I really need some help here. It works just fine until I add the second layer of variables on top of it, and I can't find the answer to this question anywhere. <?PHP require('connect.php'); ?> <form action ='' method='post'> <select name="id"> <?php $extract = mysql_query("SELECT * FROM cars"); while($row=mysql_fetch_assoc($extract)){ $id = $row['id']; $make= $row['make']; $model= $row['model']; $year= $row['year']; $color= $row['color']; echo "<option value=$id>$color $year $make $model</option> ";}?> </select> Which attribute would you like to change?<br /> <input type="radio" name="getchanged" value="make"/>Make<br /> <input type="radio" name="getchanged" value="model"/>Model<br /> <input type="radio" name="getchanged" value="year" />Year<br /> <input type="radio" name="getchanged" value="color" />Color<br /><br /> <br /><input type='text' value='' name='tochange'> <input type='submit' value='Change' name='submit'> </form> //This is where I need help... <?PHP if(isset($_POST['submit'])&&($_POST['tochange'])){ mysql_query(" UPDATE cars SET '$_POST[getchanged]'='$_POST[tochange]' where id = '$_POST[id]' ");}?> My login script stores the user's login name as $_SESSION[ 'name'] on login. For some unapparent reason, i'm getting errors stating that $user and $priv are undefined variables, though I've attempted to define $user as being equal to $_SESSION['name'], using $user to look up the the user's privilege level (stored as the su column ) in the SQL table, and then where the result of the sql query is $priv which is then evaluated in an if statement. I can't seem to figure out why this might not be working. The code I'm using: <?php session_start(); function verify() { //verify that the user is logged in via the login page. Session_start has already been called. if (!isset($_SESSION['loggedin'])) { header('Location: /index.html'); exit; } //if user is logged in, we then lookup necessary privleges. $_SESSION['name'] was written with the login name upon login. Privleges // are written in db as a single-digit integer of of 0 for users, 1 for administrators, and 2 for special users. $user === $_SESSION['name']; //Connect to Databse $link = mysqli_connect("127.0.0.1", "database user", "password", "database"); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } //SQL Statement to lookup privlege information. if ($result = mysqli_query($link, "SELECT su FROM accounts WHERE username = $user", MYSQLI_STORE_RESULT)) { //LOOP TO CYCLE THROUGH SQL RESULTS AND STORE Privlege information as vairable $priv. while ($row = $result->fetch_assoc()) { $priv === $row["su"]; } } // close SQL connection. mysqli_close($link); // Verify privleges and take action. Only a privlege of "1" is allowed to view this page. A privlege of "2" indicates special //accounts used in other scripts that have certain indermediate additional functions, but are not trusted administrators. if ($priv !== 1) { echo $_SESSION['name']; echo "you have privlege level of $priv"; echo "<br>"; echo 'Your account does not have the privleges necessary to view this page'; exit; } } verify(); ?>
I have just re-installed Xampp and suddenly my sites are now displaying lots of: Notice: Use of undefined constant name - assumed 'name' in ... Notice: Use of undefined constant price - assumed 'price' in ... this is an example of the line its refering too: $defineProducts[1001] = array(name=>'This is a product', price=>123); I have a form that creates rows of data input textboxes depending on a user input number of things. I have a naming convention for all these textboxes that basically just keeps incrementing a number suffix for each row. All this is working fine. My problem is I need to get the data inserted into this table of textboxes into an array. Here's my code where I attempt to to this (it does not work): Code: [Select] $temp = $_SESSION['Num_Part']; $count = 1; while ($count <= $temp){ $temp2[$count] = "'Participant_P".$count."'"; //echo $temp2[$count]."<br/>"; $temp3[$count]=$_POST[$temp2[$count]]; //here's the problem $temp4[$count] = "'Result_P".$count."'"; $temp5[$count]=$_POST[$temp4[$count]]; //here's the problem //echo $temp4[$count]."<br/>"; $count++; } The problem is that the $_POST does not work with the variable in the argument position - even though the argument is formatted with single quotes. Can a variable be used in a POST argument and if so what is the correct syntax? If not, is there some other simple solution to harvest the data into an array. I understand I can harvest by explicitly accessing each key in the post assoc array. But this could be dozens of rows of input fields. Thanks in advance for your help here. I couldn't find anything online re this topic. I have a script that adds points together based upon the placing. This is the actual script: Code: [Select] <? $points = 0; if($place === '1st') {$points = $points + 50;} elseif($place === '2nd') {$points = $points + 45;} elseif($place === '3rd') {$points = $points + 40;} elseif($place === '4th') {$points = $points + 35;} elseif($place === '5th') {$points = $points + 30;} elseif($place === '6th') {$points = $points + 25;} elseif($place === '7th') {$points = $points + 20;} elseif($place === '8th') {$points = $points + 10;} elseif($place === '9th') {$points = $points + 10;} elseif($place === '10th') {$points = $points + 10;} elseif($place === 'CH') {$points = $points + 50;} elseif($place === 'RCH') {$points = $points + 40;} elseif($place === 'TT') {$points = $points + 30;} elseif($place === 'T5') {$points = $points + 30;} elseif($place === 'Champion') {$points = $points + 50;} elseif($place === 'Reserve Champion') {$points = $points + 40;} echo "Total HF Points: $points"; ?>What it *should* do (my friend's script works the same way and it works) it starts at points = 0, than if there is a first place, it adds 50, and so forth until it reaches the end. It is included into a file, in this area: Code: [Select] <div class="tabbertab"> <h2>Records</h2> <? $query92 = "SELECT * FROM THISTABLE WHERE VARIABLE='$id' OR VARIABLE = '$name' ORDER BY ABS(VARIABLE), VARIABLE"; $result92 = mysql_query($query92) or die (mysql_error()); echo "<table class='record'> <tr><th>Show</th> <th>Class</th> <th>Place</th></tr> "; while($row92 = mysql_fetch_array($result92)) { $class = $row92['class']; $place = $row92['place']; $entries = $row92['entries']; $race = $row92['show']; $purse = number_format($row92['purse'],2); echo "<tr><td>$race</td> <td>$class</td> <td>$place</td></tr>"; } ?> <tr><td colspan='3'><div align='right'><? include('includes/points.php'); ?></div></td></tr> </table> </div> This is the code that is relevant. When ended here, it echoes the last place that appears in the results (such as a 5th place echoing 30 points). When I move it to be included in the while loop, it shows Total Points: 50 Total Points: 25 Total Points: 10 (depending on the results displayed on that page). What am I doing wrong? Hello everyone, I can get Test 2 to successfully operate the if statement using a variable variable. But when I try the same method using a session variable (Test 1) the if statement is not executed. Please could you tell me why the if statement in Test 1 is not being executed? Code: [Select] <?php # TEST 1 $_SESSION[test_variable] = "abcd"; $session_variable_name = "_SESSION[test_variable]"; if ($$session_variable_name == "abcd") { echo "<br>line 373, abcd<br>"; } # TEST 2 $test_variable = "efgh"; $test_variable_name = "test_variable"; if ($$test_variable_name == "efgh") { echo "<br>line 379, efgh<br>"; } ?> Many thanks, Stu when i insert a new topic into the database its id is generated by the auto incrememnt field tid. but what i do next is insert the post for that new topic in the post table which has p_pid(post id) and p_tid(the topic id it is for). so how do i generate that p_tid when the topic has just been inserted. i used to do it by inserting the topic then running a query to pull the newest topic if from the database which would mean the post belonged to that topic. but what happens when people are posting several topics at the same time? Hey, Basically the script runs fine except for the fact its just inserting one user instead of multiple users, anyone have a clue as to why? would be a huge hand, Cheers Code: [Select] <?php if (isset($_POST["submit"]) && $_POST["submit"] == "Recall Selected Informants") { //Force POST values to be INTs $addIDs_ary = array_map('intval', $_POST['chkInv']); //Remove any 'false' value $addIDs_ary = array_filter($addIDs_ary); //Check that there was at least one valid value if(count($addIDs_ary)) { //Create comma separated string of the IDs $addIDs_str = implode(',', $addIDs_ary); //Create and run one query to perform all the adds (of the user) $query = "INSERT INTO hitlist SET hit_id = '($addIDs_str)' AND player_id = '$playerID'"; $sql = "UPDATE players SET Informants = Informants - 1 WHERE id = '$playerID'"; mysql_query($sql) or die(mysql_error()); if(mysql_query($query)) { $selectedCount = count($addIDs_ary); $adddCount = mysql_affected_rows(); echo "{$adddCount} of {$selectedCount} Investigated player(s) were successfully added."; }else{ echo "There was a problem running the query.<br>" . mysql_error(); } }else{ echo "Invalid ID data passed."; } } All the variables are set for sure, anyone have any clue why the following isnt inserting anything into the db? Code: [Select] //### Query to insert new item into the database table "items" $query = "INSERT INTO `items`(`name`,`image`,`description`,`description2`,`description3`,`ItemType`,`cash_price `,`credit_price `,`GrowAmount`,`SellAmount`,`MaxOff`,`MaxDef`,`MaxHoes`,`Attack`,`Defense`,`Prestige`,`SafeLimit`,`ProductionQuality`,`ProductionWeight`,`HoDrugUsage`,`HoIncome`,`PurchaseDiscount`,`Informants`,`Pimpness`,`SalesPrice`,`SalesWeight`,`TroopDiscount`,`NotoReq`,`SCReq`,`PRReq`,`Buyable`,`ClassSpecific`,`Sellable`,`Multiple`) VALUES('{$name}','{$image}','{$description}','{$description2}','{$description3}','{$ItemType}','{$price}','{$creditprice}','{$GrowAmount}','{$SellAmount}','{$MaxOff}','{$MaxDef}','{$MaxHoes}','{$Attack}','{$Defense}','{$Prestige}','{$SafeLimit}','{$ProductionQuality}','{$ProductionWeight}','{$HoDrugUsage}','{$HoIncome}','{$PurchaseDiscount}','{$Informants}','{$Pimpness}','{$SalesPrice}','{$TroopDiscount}','{$NotoReq}','{$SCReq}','{$PRReq}','{$Buyable}','{$ClassSpecific}','{$Sellable}','{$Multiple}'"; //### Execute the above query mysql_query($query); I am still having issues with getting the second part of this function to work right. It inserts fine into the first table but after that it's not performing the second insert. Code: [Select] function sendMessage($recipients, $bcc, $subject, $message, $sender) { $data = array( 'subject' => $subject, 'senderID' => $sender, 'message' => $message ); $this->db->insert('usersPersonalMessages', $data); $insertID = $this->db->insert_id(); foreach ($recipients AS $recipient) { $recipientData = array( 'usersPersonalMessagesID' => $insertID, 'userID' => $recipient ); } if ($bcc) { foreach ($bcc AS $userID) { $recipientData['userID'] = $userID; $recipientData['bcc'] = 1; } } $this->db->insert('usersPersonalMessagesRecipients', $recipientData); } Hello guys, im wonder if ca i syntax the insert so i can insert some fields with alphabeticly shorting by name field Thanks hi i'm trying to insert this text just "we're pleased to announce etc........ect" but I can only insert "We" i believe its because single quotation mark. I've tried using addslashes, mysqli_real_escape_string and htmlspecialchars, strp_tags and applied it to my variable $s. But what ever i seem to try and insert still results in "we" being inserted. Cant see for the life of me why??? appreciate any help if (isset($_POST['submitted'])) { $errors = array(); if (empty($_POST['title'])) { $errors[] = '<p class="error">Either you haven\'t filled in the title or story for this news</p>'; } else { $t = mysqli_real_escape_string($dbc, $_POST['title']); } if (empty($_POST['story'])) { $errors[] = '<p class="error">Either you haven\'t filled in the title or story for this news</p>'; } else { $s = $_POST['story']; } echo $s; if(empty($errors)) { // No errors $q = "INSERT INTO news (title, story, date_added) values ('$t', '$s', NOW() )"; $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows == !1) { // It didnt run ok $errors[] = '<p class="error">An error occured with your upload<a href="loggedin.php"> Admin</a></p>'; } else { echo 'Your news story has been added, visit <a href="news.php">News</a>'; } //if mysqli_affected rows } else { echo '<p class="error">The following errors occured<br />'; foreach ($errors as $msg) { echo " - $msg<br>"; } echo 'Please try again'; } // end of $errors } // End of submitted This is my code i'm using :-) as you an see i'm posting the variable $s which is ($_POST['story'] with no functions and it still only inserts "we" nothing more????? |