PHP - Create New Window In Js With Php Code
Hello,
I would like to create a window through JavaScript with PHP code that would insert data into a database, but I don't know if it's possible, because I tried everything I could so far and had no results at all.
The code I am using is
<script language="JavaScript"> <!-- top.consoleRef = new Object(); top.consoleRef.closed = true; function writeConsole(content) { top.consoleRef=window.open('em_branco.php','myconsole','width=350,height=250') top.consoleRef.document.writeln( '<html><head><title>página nova</title></head><body><?php $db = pg_connect("host=localhost dbname=dpf_db user=postgres password=asdasd"); $query = "INSERT INTO tbl_dummy(nome) VALUES(' + '´treco´' + ')"; $result = pg_query($query); if (!$result) { $errormessage = pg_last_error(); echo "Error with query: " . $errormessage; exit(); } printf ("These values were inserted into the database"); pg_close(); ?></body></html>' ) //top.consoleRef.document.close() } //--> </script>Note that line 13 has a sort of aberration, because I'd need three kinds of quotes, and not only two (the +'´treco´' stuff). And I don't know how to circumvent this, because escaping didn't work either. Any help is most welcome, and thank you in advance for your attention. Nicole Similar TutorialsI have a Php application that already has 2 buttons with input on the index page that perform some functions and output to different Php pages. Works good. How do I add a button with no input that would just perform a function and then just display a popup window showing the contents of a text file? I want to add several of these buttons for different functions and just display the contents of the resulting text files in popup windows. Any help would be greatly appreciated. Thanks in advance. I'm just starting out with mysqli and php. Actually I more or less know how to create/connect/populate mysqli databases through php. But I can only do so by using a separate php page for each objective. Anyway, I learning with the kindle version of Joy of Php. The code though isn't very good...I had to edit it just to make it conform to php/mysqli syntax. Programmer's Notebook was a big help actually.
Anyway, I just wanted to point out my experience level. Below is the code, I haven't run it through wamp (Phpmyadmi) yet, only because it probably won't run and I'll be crushed...side note: it took me a while to figure out that tables and databases require the use ` and not '. The book doesn't even mention the difference!!!!
Anyway, can someone tell me if this edited code is viable? I'm concerned about line 4: $mysqli.... since this is wamp, and I log into phpmyadmin via -u root -p , -p NULL in the code is correct yes?
<?php /*Joy of PHP sample code*/ $mysqli = new mysqli('localhost', 'root', NULL ); if (mysqli_connect_error()) { die('Could not connect: ' . mysqli_connect_error()); } echo 'Connected successfully to mySQL.'; /* Create table doesn't return a resultset */ if ($mysqli->query("CREATE DATABASE Cars") === TRUE) { echo "Database Cars created"; } else { echo "Error creating Cars database: " . $mysqli->error."<br>"; } $mysqli->select_db("Cars"); Echo ("Selected the Cars database"); $query= " CREATE TABLE INVENTORY (VIN varchar(17) PRIMARY KEY, YEAR INT, Make varch(50), Model varchar(100))"; //echo "<p>*****</p>"; //echo $query; //echo "<p>*****</p>"; if ($mysqli->query ($query) === TRUE) { echo "<p>Database table 'INVENTORY' CREATED</p>"; } else { echo "<p> ERROR: </p>" . mysqli_error($mysqli); } $query = "INSERT INTO `cars` . `inventory` (`VIN`, `YEAR`, `Make`, `Model`) VALUES '5FNYF4H91CB054036', '2012', 'Honda', Pilot')"; if ($mysqli->query($query) === TRUE) { echo "<p>Honda Pilot inserted into inventory table. </p>"; } else { echo "<p>Error inserting Honda Pilot:</p>" . mysqli_error($mysqli); echo "<p>*****</p>"; echo $query; echo "<p>*****</p>"; } //Insert a Dodge Durango $query= "INSERT INTO `cars` . `inventory` ('VIN', 'YEAR', 'Make', 'Model') VALUES ('LAKSDFJ234LASKRF2', '2009', 'Dodge', 'Durango')"; if ($mysqli->query($query) ===TRUE) { echo "<p>Dodge Durango inserted into inventory table </p>"; } else { echo "<p>Error inserting Dodge: </p>" . mysqli_error($mysqli); echo "<p>*****</p>"; echo $query; echo "<p>*****</p>"; } $mysqli->close(); ?>Thank you, I apologize if I seem critical of the book but it really skips over A LOT of stuff that newbies don't necessarily know (example: -u something -p = username something and password is blank) Edited by baltar, 17 May 2014 - 05:59 PM. Rules: 1) It has to be legit and actually work and have a useful function in society/web world. 2) The code cannot be minimized into one line. It has to have line breaks. (Not necessarily for each new function or short hand property, but so it's partly readable) 3) It has to be written in PHP or Javascript. For example, (Not my original code) but I'll start: A time_ago function: function timeago($tm,$rcs = 0) { $cur_tm = time(); $dif = $cur_tm-$tm; $pds = array('second','minute','hour','day','week','month','year','decade'); $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600); for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]); $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x = sprintf("%d %s ",$no,$pds[$v]); if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm); return $x; }Your turn! Edited by Monkuar, 24 January 2015 - 05:06 PM. Hey php developers. I'm Brent from Beanstream. We just recently opened up some code bounties to create a PHP SDK that uses our payment gateway API. Each bounty is around 1-5 hours work and their reward is between $150 and $400. The SDK is open source (MIT license) and will be hosted on GitHub. There are already 2 other SDKs written in Java and C# that use the same RESTful payments API, so a lot of the code and functionality can be copied over to the PHP SDK. If you are interested in helping out you can sign up here. You can also check out Beanstream's Payments API to see what the SDK will be implementing: http://developer.beanstream.com Feel free to message me if you have questions. Cheers, Brent Beanstream Internet Commerce Hello, I am novice in PHP, I read book and try to write some PHP code, but I don't have success in that my attempt. Do someone can to help me? I think that this what I work isn't hard, but I don't know to do. I need to create in PHP some code which will: 1. In text field I enter some words in 2-3 rows, example word11 word12 word13 word21 word22 word23 word31 word32 word33 and click to button Convert, 2. After click on that button php script will take that words and convert into this mode: word11-word12-word13(TAB here without space)word11 word12 word23 word21-word22-word23(TAB here without space)word21 word22 word23 word31-word32-word33(TAB here without space)word31 word32 word33 (spaces between words will convert into - and between first and second mode with TAB) 3. On that way converted text to be saved into new file which will be with name of first line "word11 word12 word13". I know procedure to make this, but I don't know syntax very well Can someone write me code or part of code, to give me idea how I to make this? Thank you very much, Mladen This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=317523.0 Scenario :
I would like to open the main program window and at the same time, if a condition is met, open a second - popup window to alert the user of previous information stored in the database.
This is an easy exercise if I use a hyperlink to open th second (popup) window but this is not the process required .
Can someone point me in the right direction ?
Cheers and thanks
Hello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> I'm wondering what makes a pop-up login window run differently than inside a webpage. I can't seem to get my login system to bring the user back to the page (brings them to a page can't be found) when clicking a form submit button when it is included in the webpage. But if your in the popup page that I'm trying to include, it works no problem so I was wondering if it changes anything. Or if there is some sort of work around (such as embedding a popup window into the webpage). Thanks a lot! I have the following code in html: <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://VARIABLEVALUE.mysite.com" } //--> </script> <title>Redirecting ...</title> </head> <body onLoad="setTimeout('delayer()', 1000)"> <script type="text/javascript"> var sc_project=71304545; var sc_invisible=1; var sc_security="9c433fretre"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript> <div class="statcounter"><a title="vBulletin statistics" href="http://statcounter.com/vbulletin/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/71304545/0/9c433fretre/1/" alt="vBulletin statistics" ></a></div></noscript> </body> </html> Is a basic html webpage with a timer redirect script and a stascounter code. I know a bit about html and javascript, but almost nothing about php. My question is: How a can convert this html code into a php file, in order to send a variable value using GET Method and display this variable value inside the javascript code where says VARIABLEVALUE. Thanks in adavance for your help. Hi, I have some code which displays my blog post in a foreach loop, and I want to add some social sharing code(FB like button, share on Twitter etc.), but the problem is the way I have my code now, creates 3 instances of the sharing buttons, but if you like one post, all three are liked and any thing you do affects all of the blog post. How can I fix this? <?php include ("includes/includes.php"); $blogPosts = GetBlogPosts(); foreach ($blogPosts as $post) { echo "<div class='post'>"; echo "<h2>" . $post->title . "</h2>"; echo "<p class='postnote'>" . $post->post . "</p"; echo "<span class='footer'>Posted By: " . $post->author . "</span>"; echo "<span class='footer'>Posted On: " . $post->datePosted . "</span>"; echo "<span class='footer'>Tags: " . $post->tags . "</span>"; echo ' <div class="addthis_toolbox addthis_default_style "> <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a> <a class="addthis_button_tweet"></a> <a class="addthis_counter addthis_pill_style"></a> </div> <script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script> <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=webguync"></script>'; echo "</div>"; } ?> Hi, I need to insert some code into my current form code which will check to see if a username exist and if so will display an echo message. If it does not exist will post the form (assuming everything else is filled in correctly). I have tried some code in a few places but it doesn't work correctly as I get the username message exist no matter what. I think I am inserting the code into the wrong area, so need assistance as to how to incorporate the username check code. $sql="select * from Profile where username = '$username'; $result = mysql_query( $sql, $conn ) or die( "ERR: SQL 1" ); if(mysql_num_rows($result)!=0) { process form } else { echo "That username already exist!"; } the current code of the form <?PHP //session_start(); require_once "formvalidator.php"; $show_form=true; if (!isset($_POST['Submit'])) { $human_number1 = rand(1, 12); $human_number2 = rand(1, 38); $human_answer = $human_number1 + $human_number2; $_SESSION['check_answer'] = $human_answer; } if(isset($_POST['Submit'])) { if (!isset($_SESSION['check_answer'])) { echo "<p>Error: Answer session not set</p>"; } if($_POST['math'] != $_SESSION['check_answer']) { echo "<p>You did not pass the human check.</p>"; exit(); } $validator = new FormValidator(); $validator->addValidation("FirstName","req","Please fill in FirstName"); $validator->addValidation("LastName","req","Please fill in LastName"); $validator->addValidation("UserName","req","Please fill in UserName"); $validator->addValidation("Password","req","Please fill in a Password"); $validator->addValidation("Password2","req","Please re-enter your password"); $validator->addValidation("Password2","eqelmnt=Password","Your passwords do not match!"); $validator->addValidation("email","email","The input for Email should be a valid email value"); $validator->addValidation("email","req","Please fill in Email"); $validator->addValidation("Zip","req","Please fill in your Zip Code"); $validator->addValidation("Security","req","Please fill in your Security Question"); $validator->addValidation("Security2","req","Please fill in your Security Answer"); if($validator->ValidateForm()) { $con = mysql_connect("localhost","uname","pw") or die('Could not connect: ' . mysql_error()); mysql_select_db("beatthis_beatthis") or die(mysql_error()); $FirstName=mysql_real_escape_string($_POST['FirstName']); //This value has to be the same as in the HTML form file $LastName=mysql_real_escape_string($_POST['LastName']); //This value has to be the same as in the HTML form file $UserName=mysql_real_escape_string($_POST['UserName']); //This value has to be the same as in the HTML form file $Password= md5($_POST['Password']); //This value has to be the same as in the HTML form file $Password2= md5($_POST['Password2']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $Zip=mysql_real_escape_string($_POST['Zip']); //This value has to be the same as in the HTML form file $Birthday=mysql_real_escape_string($_POST['Birthday']); //This value has to be the same as in the HTML form file $Security=mysql_real_escape_string($_POST['Security']); //This value has to be the same as in the HTML form file $Security2=mysql_real_escape_string($_POST['Security2']); //This value has to be the same as in the HTML form file $sql="INSERT INTO Profile (`FirstName`,`LastName`,`Username`,`Password`,`Password2`,`email`,`Zip`,`Birthday`,`Security`,`Security2`) VALUES ('$FirstName','$LastName','$UserName','$Password','$Password2','$email','$Zip','$Birthday','$Security','$Security2')"; //echo $sql; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else{ mail('email@gmail.com','A profile has been submitted!',$FirstName.' has submitted their profile',$body); echo "<h3>Your profile information has been submitted successfully.</h3>"; } mysql_close($con); $show_form=false; } else { echo "<h3 class='ErrorTitle'>Validation Errors:</h3>"; $error_hash = $validator->GetErrors(); foreach($error_hash as $inpname => $inp_err) { echo "<p class='errors'>$inpname : $inp_err</p>\n"; } } } if(true == $show_form) { ?> hey gurus, i am a newbie php coder.. i am learning by example. what i am trying to do is write a piece of code which will alter 3 tables (user, bonus_credit, bonus_credit_usage) ---------------------------------------------------------------- the table structure that will be used is as follows: user.bonus_credit user.ID bonus_credit.bonusCode bonus_credit.qty bonus_credit.value bonus_credit_usage.bonusCode bonus_credit_usage.usedBy ---------------------------------------------------------------- so lets say, in bonus_credit i have the following bonusCode = 'facebook' (this is the code they have to type to redeem the bonus qty = '10' ( number of times the bonusCode can be redeemed, but same person can't redeem it more than once) value = '5' (this is the amount of bonus_credit for each qty) Now, I need to write a code that check to see if the code has been redeemed in the bonus_credit_usage table and if the user.ID exists in this table as bonus_code_usage.usedBy, then give an error that its already been used and if it hasn't been used, then subtract 1 from qty, add ID to usedBy and then add the value to the bonus_credit ----------------------- i have started the steps just to create a simple textbox and entering a numeric value to bonus_credit, and that works.. but now i have to use JOIN and IF and ELSE.. which is a little too advanced for me.. so i'd appreciate a guide as i write the code. if(isset($_REQUEST['btnBonus'])) { $bonus_credit = addslashes($_REQUEST['bonusCode']); $query = "update user set bonus_credit=bonus_credit+'".$bonus_credit."' where id='".$_SESSION['SESS_USERID']."'"; echo "<script>window.location='myreferrals.php?msgs=2';</script>"; mysql_query($query) or die(mysql_error()); } Advance thank you. Can you help please. The error..... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\wamp\www\test_dabase.php on line 24 code. Code: [Select] <?php //database connection. $DB = mysql_connect("localhost","root") or die(mysql_error()); if($DB){ //database name. $DB_NAME="mysql"; //select database and name. $CON=mysql_select_db($DB_NAME,$DB)or die(mysql_error()."\nPlease change database name"); // if connection. }if($CON){ //show tables. $mysql_show="SHOW TABLES"; //select show and show. $mysql_select2="mysql_query(".$mysql_show.") or die(mysql_error())"; } //if allowed to show. if($mysql_select2){ //while it and while($data=mysql_fetch_assoc($mysql_select2)){ //show it. echo $data; } } ?> hi, I'm currently trying to resize and create pictures and .jpg/jpeg & .gif works perfectly but .png just creates an empty 0bit image, why?! Code: [Select] $ = imagecreatefrompng(); imagecopyresampled(); imagepng(); I'm doing something like that and it - as said - works great with .jpg and gif but at png it just fucks up. :/ HOw to create this header?
I give +. thx
http://i.snag.gy/15Ep4.jpg
Hii i want to create an api of the short url site ( http://torrentz.0fees.net ). In the api page it is says that Code: [Select] API Our API allows you to provide short url functionality to any of your existing websites. Url Only To generate a url via the API, send a POST or GET request to the site in the following format: - http://torrentz.0fees.net/index.php?api=1&return_url_text=1&longUrl={URL} This site will then generate the short url and return it as plain text. i.e: - http://torrentz.0fees.net/a1 I have created an form but not able to use it. The form script is shown below. Code: [Select] <form name="input" action="html_form_action.asp" method="get"> Username: <input type="text" name="user" /> <input type="submit" value="Submit" /> </form> Whenever i'm putting the ( http://torrentz.0fees.net/index.php?api=1&return_url_text=1&longUrl={URL} ) it shows an error. I know that the input url must be used in the ( {URL} ) section but how can i do that using php Can anyone help me with code... Hello all That forum is my last desperate attemp to do what i want to do. Ok here is the story I want to create a simple rss feed in conjuction with php and mysql. I dont want admin areas ect , i just want when i insert a new listing to my database to be able shown up to my (future) rss subscribers. To be more technically specific i want to show to my surfers updates about 2 tables in my database not all the tables. The example i found so far were about only 1 table, plus i was encounting errors to my script. I would like some ideas, directions if someone is kind enough to help a sad developer Thanks in advance! I would like to create something like foursquare badges. When ppl upload files, the most downloaded files will have a new badge, how do i create that? Hi, How could I make a php script that creates a new folder (with the name as the date) every day automatically? Cheers, George |