PHP - Moved: Integrating Php With Html Page To Execute Sql Query
This topic has been moved to Third Party PHP Scripts.
http://www.phpfreaks.com/forums/index.php?topic=355955.0 Similar TutorialsThis topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=358814.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=354184.0 Unable to execute query (SELECT * FROM lb-players) in the database : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-players' at line 1 I don't know why i am getting this error. All i can think of that is taking away lb from "lb-players" when you add a " - "? Code: [Select] [m]<?php $conn = mysql_connect("23.23.23.23", "unknown", "itsAsecertxD");//ignore this xD if (!$conn) { echo "Unable to connect to the database : " . mysql_error(); exit; } if (!mysql_select_db("minecraft-rc")) { echo "Unable to select database mydbname : " . mysql_error(); exit; } $sql = 'SELECT * FROM lb-players'; $result = mysql_query($sql); if (!$result) { echo "Unable to execute query ($sql) in the database : " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to display."; exit; } while ($row = mysql_fetch_assoc($result)) { echo $row["playername"]; } mysql_free_result($result); ?>[/m] tell me if i posted this in the wrong place its been forever since i last been on this site :$ Hi. I have a query that determines if user is online/offline. Works perfectly when page loads. I want to change to auto run query every X seconds. NOTES: - The query is on a .php page with multiple other queries. -IF it is possible to still run the query with-in this page? or make a separate file and include in an iframe? i would like to avoid the iframe and just $output the result of query every X seconds. Here is my $query code: $query = "SELECT `manager_id` FROM #__profiles_xref WHERE profileid = '$profid'"; $onofflineid=doSelectSql($query,1); foreach ($onofflineid as $isonoffline){ $profmanagerid=$isonoffline->manager_id; } $query = "SELECT `session_id` FROM table_session WHERE userid = '$propmanagerid'"; $onofflinestatus=doSelectSql($query,1); if (count($onofflinestatus)>0) { $output['PROPSTATUS']='Online'; } else { $output['PROPSTATUS']='Offline'; } Hi, Im starting to write a simple (so I thought! ) project at work, I have no problems with the HTML, CSS or even the php mysql setup, but I am struggling with a simple piece of code! I have a list box, that populates from a table column using the following code: Code: [Select] <?php function select(){ $query="SELECT appname FROM kpe_apps"; $result = mysql_query($query); echo '<select name="item" onchange="this.form.submit()">'; while($nt=mysql_fetch_array($result)){ echo '<option value="' . $nt['id'] . '">' . $nt['appname'] . '</option>'; } echo '</select>'; } ?> I then called the function on the page I needed. which works fine, now all I need is whatever is selected in the listbox other columns in the same table relating to the selected item are seen. I just cant seem to do it, loads of people are using jquery and other code, surely this can be done in php? any help would really be appreciated.. Many Thanks MOD EDIT: code tags fixed, linefeeds and indenting added. This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=353608.0 Hi all ! The following code has two similar queries. Query 1 and Query 2. While Query 1 works just fine, Query 2 simply fails persistently. I have not been able to figure out why?
I have checked every single variable and field names but found no discrepancy of any sort or any mismatch of spelling with the fields in the database.
I would be grateful if anybody can point out what is preventing the second query from returning a valid mysqli object as the first one does. Here is the code for the two.
<?php $db_host = "localhost"; $db_user ="root"; $db_pass =""; $db_database ="allscores"; //////////////// CHECKING VARIABLE FILEDS IN A UPDATE QUERY ////////////////////////////////// //////////////// QUERY 1 ///////////////////////////////////////////////////////////////////// /* $db_database ="test"; $db_table ="users"; $RecNo = 1; $field1 = 'name'; $field2 = 'password'; $field3 = 'email'; $field4 = 'id'; $val1 = "Ajay"; $val2 = "howzatt"; $val3 = "me@mymail.com"; $con = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection'); $query = "UPDATE $db_table SET $field1 = ?, $field2 = ?, $field3 = ? WHERE $field4 = ? "; // session terminated by setting the sessionstatus as 1 $stmt = $con->prepare($query); var_dump($stmt); $stmt->bind_param('sssi',$val1,$val2,$val3,$RecNo); if($stmt->execute()) { $count = $stmt->affected_rows; echo $count; } //////////////// QUERY 1 END ///////////////////////////////////////////////////////////////////// */ //////////////// QUERY 2 ///////////////////////////////////////////////////////////////////// $con = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection'); $table = 'scores'; $date = date('Y-m-d H:i:s'); /* $prestr = "Mrt_M_"; $STATUS = $prestr."Status"; $S_R1 = $prestr."Scr_1"; $S_R2 = $prestr."Scr_2"; $PCT = $prestr."PPT"; $DPM = $prestr."DSP"; $TIMETAKEN = $prestr."TimeTaken"; */ $STATUS = "Mrt_M_Status"; $S_R1 = "Mrt_M_Scr_1"; $S_R2 = "Mrt_M_Scr_2"; $PPT = "Mrt_M_PPT"; $DSP = "Mrt_M_DSP"; $TIMETAKEN = "Mrt_M_TimeTaken"; $TimeOfLogin = $date; $no_of_logins = 10; $time_of_nLogin = $date; $m_scr_row1 = 5; $m_scr_row2 = 5; $m_ppt = 20; $m_dsp = 60; $m_time = 120; $date = $date; $RecNo = 24; $query = "UPDATE $table SET TimeOfLogin = ?, no_of_logins = ?, time_of_nLogin = ?, $S_R1 = ?, $S_R2 = ?, $PPT = ?, $DSP = ?, $TIMETAKEN = ?, $STATUS = '1', TimeOfLogout = ?, WHERE RecNo = ?"; $stmt = $con->prepare($query); var_dump($stmt); $stmt->bind_param('sisiiddssi',$TimeOfLogin,$no_of_logins,$time_of_nLogin,$m_scr_row1 $m_scr_row2,$m_ppt,$m_dsp,$m_time,$date,$RecNo); if($stmt->execute()) echo " DONE !"; ?>Thanks to all I have this piece of code: Code: [Select] if (isset($_POST['type1'])) { mysql_query("UPDATE tabke SET status = 1 WHERE id = $rid", $c2) or die(mysql_error()); } if (isset($_POST['type2'])) { mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error()); } if (isset($_POST['type3'])) { mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error()); } ?> <br /> <form method="post" action=""> <input type="hidden" name="pageid" value="plyrmgmt"> <input type="hidden" name="action" value="changeBan"> <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>"> <input type="hidden" name="repid" value="<?php echo $rid; ?>"> <input type="submit" name="type1" value="Choice1" onClick="this.form.submit()"> </form> <form method="post" action=""> <input type="hidden" name="pageid" value="plyrmgmt"> <input type="hidden" name="action" value="changeMute"> <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>"> <input type="hidden" name="repid" value="<?php echo $rid; ?>"> <input type="submit" name="type2" value="Choice2" onClick="this.form.submit()"> </form> <form method="post" action=""> <input type="hidden" name="pageid" value="plyrmgmt"> <input type="hidden" name="action" value="changeLock"> <input type="hidden" name="uid" value="<?php echo $hr_uid; ?>"> <input type="hidden" name="repid" value="<?php echo $rid; ?>"> <input type="submit" name="type3" value="Choice3" onClick="this.form.submit()"> </form> Now, for some reason when I click on Choice1, the query doesn't execute. Also, when I click on Choice2 or Choice3, the URL in my browser doesn't change for some odd reason...it stays the same as it was prior to clicking the Submit Button. Can anyone point out some errors I have? Thanks, Mark. So I am trying to execute an sql query by clicking a button or a link. Ultimately I want users to be able to click the "Fav" button and it then fades into "Added to favorites!" (I am building a favorite system which first collects data on page load like userid and itemid and then it needs to send it to the DB after a button is clicked) The fade and stuff is not the most important part now (although a tip on doing that would be awesome) but the most important part is how to get this functional: PHP Code: <?php // Start Favorite System! $user =& JFactory::getUser(); $userid = $user->id; if ($userid == 62) { echo "userID: ".$userid."<p />"; if ($user->guest) {echo "You are a guest<p />";} $itemid = $this->item->id; echo "itemID: ".$itemid."<p />"; $catid= $this->item->category->id; echo "catID: ".$catid."<p />"; $query = "INSERT INTO jos_k2_fav_xref (userID, itemID, catID) VALUES ('$userid', '$itemid', '$catid')"; // Need a way to make this into a button $run = mysql_query($query) or die(mysql_error()); } else {} ?> Currently all the values get stored in the DB as the page is loaded. I however want to be able to click on something to execute that query how do i do that? I read a bunch of stuff on javascript and ajax but it got me nowhere... Help is greatly appreciated! This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=323045.0 This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=352264.0 This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=333614.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=345218.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=351266.0 Hello, I need to execute a remote web page (distant server) every X seconds. How is it possible and is there any way to make it look exactly like a normal user request through a standard browser like Firefox, Chrome, etc. ? I've heard of cURL, but it seems that servers may block it, so there must be somehow a difference between a usual user request and a cURL execution. Thank you for any help ! :-) Matthew Hi,
In reference to my first attached image, I have a form which displays two SELECT/drop-down fields (labeled "Store Name" and "Item Description".....and both of which pull-in values from two separate lookup/master tables, in addition to providing an additional option each for "NEW STORE" and "NEW ITEM").
Now, when first-run, and/or if "NEW STORE" and "NEW ITEM" are not selected from the drop-down's then the two fields in green ("New Store Name" and "New Item Name" are hidden, by means of the following code:
<div class="new-store-container" id="new-store-container" name="new-store-container" style="display:none;"> <div class="control-group"> <div class="other-store" id="new_store_name"> <?php echo standardInputField('New Store Name', 'new_store_name', '', $errors); ?> </div> </div> </div>Conversely, if "NEW STORE" and/or "NEW ITEM" are selected from the two drop-down's then one (or both) of the "New Name" fields are unhidden by means of the following two pieces of code, one PHP and the second JS: <select class="store-name" name="store_id" id="store_id" onclick="toggle_visibility('store_id','new-store-container')"> <?php echo $store_options; ?> <?php if($values['store_id'] == "OTH") { echo "<option value='OTH' selected> <<<--- NEW STORE --->>> </option>"; } else { echo '<OPTION VALUE="OTH"> <<<--- NEW STORE --->>> </OPTION>'; } ?> </select> function toggle_visibility(fieldName, containerName) { var e = document.getElementById(fieldName); var g = document.getElementById(containerName); if (e.value == 'OTH') { if(g.style.display == 'none') g.style.display = 'block'; else g.style.display = 'none'; } }All of that is working just fine. The problem I'm having is that when I click the "Create" button, after having left any one of the form fields blank, the two "New Name" fields are hidden again, which I don't want to happen i.e. I want them to remain visible (since the values of "store_id" and/or "item_id" are "OTH"), so that the user can enter values into one or both of them, without havng to click on the drop-down a second time in order to execute the "on-click" code. The second attached image shows how the fields are hidden, after clicking "Create". How can I achieve that? It would be greate if someone could cobble-up the required code and provide it to me, since I'm relatively new to this. Thanks much. Snap1.png 26.14KB 0 downloads Snap2.png 149.47KB 0 downloads This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=344191.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=329559.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=311010.0 Hi, hope I have posted this in the right place, I have the following code which contains PHP and javascript, where both work on there own but when I try putting them together I keep getting errors: Code: [Select] <?php include 'config.php'; include 'opendb.php'; $var = 'Smith'; $query = "SELECT * FROM search_directory WHERE merchant LIKE \"%$var%\""; $result = mysql_query($query); $id = $row{"id"}; while($row = mysql_fetch_assoc($result)) { echo "Name: {$row['name']} <br>"; echo "Subject: {$row['title']} <br><br>"; } include 'closedb.php'; ?> <a href="javascript:;" onclick="document.getElementById('.....').style.display='block';window.open('http://www.google.co.uk');"><img src="../../graphics/Click here.png" border="0" /></a> <div id="....." style="display:none;"> ...your text here </div> What I have been trying to do is get $id variable from the php code to replace the '.....' in the javascript and div id. I have tried putting it into an echo statement which seemed to work with the div id but the brought up errors when i tried with the javascript. If anyone knows how to solve this it would be very much appreciated. Thanks in advance. |