-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
No. Not sure why but you have changed from mysqli to to mysql_* database library. Stick with one database library throughout your code. You also have an error in your SQL query. I think you mis-understood my reply here str, agi and range are not PHP variables they are MySQL column names. For each of these columns it will add 5 to their current value. You do not need to get the current value and add 5 with PHP, MySQL can do this itself within the update query. Reverting your code back to a function (with mac_gyver suggestions) you'll code it like this <?php include_once '../includes/db_connect.php'; include_once '../includes/functions.php'; // define the function first. Maybe move to functions.php function getIns($mysqli) { if ($stmt = $mysqli->prepare("UPDATE members SET str = str+5, agi = agi+5, `range` = `range`+5 WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); // check if the query did execute and that it affected a row if ($stmt->execute() && $mysqli->affected_rows > 0) { return true; // success return true } } return false; // all other cases return false. Something went wrong. Logging an error at this stage would be recommended. } sec_session_start(); if(isset($_POST['add5'])) { // call getIns function when $_POST['add5'] exists if(getIns($mysqli)) { // getIns will return TRUE when record has been updated. // redirect to register_success.php header('Location: ../register_success.php'); } else { // on failure it will return false. header('Location: ../error.php?err=Registration failure: INSERT'); } } ?>
-
I have an error in my code, change $apiUrl to $apiParamsUrl
-
You cannot call PHP functions on an onlick event - or any any event that happens within the browser for that matter. A http request will need to be made in order for PHP to do an action. For PHP to call to the getIns function you'll need to create a submit button <form action="page.php" method="post"> <input type="submit" name="add5" value="Add +5" /> </form> Now in your PHP code, you'd call the functin when $_POST['add5'] exits // call getIns when $_POST['add5'] exists if(isset($_POST['add5'])) getIns($mysqli); Also you can add 5 to a fields value within the SQL query itself. You dont need to retrieve the old value and then add 5 UPDATE members SET str = str+5, agi = agi+5, `range` = `range`+5 WHERE id = ? LIMIT 1
-
To see how easily it is to do this, open any webpage with a drop down menu and paste this in to the browsers console (usually via F12) document.getElementsByTagName('select')[0].options[0].text = 'bad'; document.getElementsByTagName('select')[0].options[0].value = 'bad'; it will find the first dropdown on the page and override the first option. When the dropdown is submitted this value will now be submitted, not the value you defined in the html.
-
No, fetchAll will return all records in a multiple dimension array, Each set of records will be in a separate array eg $row = $stmt->fetchAll();// get all results // first record $row[0] // will contain an array of values for first result, eg echo 'First name for first result: ' . $row[0]['firstname']; // second secound $row[1] //will contain an array of values for second result echo 'First name for second result: ' . $row[1]['firstname']; So your query will return the contact/address details of each user assigned to a carer. And you want to display two forms for updating each users contact/address details?
-
If you know the exact dates, then pass them to DateTime:diff This can return the difference in days between the two dates. You'll multiply this by your daily charge rate. Example code // dates given in year-month-day hour:min:sec format $datetime1 = new DateTime('2009-10-11 00:00:00'); // date 1 $datetime2 = new DateTime('2009-10-19 12:00:00'); // date 2 $interval = $datetime1->diff($datetime2); $totalDays = $interval->format('%a'); $hourDiff = $interval->format('%h'); // divide hour difference and by 24, adding this to total days if($hourDiff > 0) $totalDays += ($hourDiff / 24); // daily charge rate $chareRate = 12.50; // charge for 1 day. if($totalDays == 1) { $total = $chareRate; $perioid = 'day'; } // charge for a week, when total days is greater than 1 day (noon) till 7 days elseif($totalDays >= 1.5 && $totalDays <= 7) { $total = $chareRate * 7; $period = 'week'; } // charge for 1 week and a day for 8 days elseif(floor($totalDays) == { $total = $totalDays * $chareRate; $period = 'week +1 day'; } // charge for two weeks if total days is greater than 8 days elseif($totalDays > { $total = $chareRate * 14; $period = 'fortnight'; } echo "Rental costs for $totalDays days @ $chareRate = $total (Rental Period $period)";
-
If you want specific lines, then you could do $html = file("airport.html"); $targetData =''; // start at line 75 and loop till line 100 for($i = 74; $i <= 99; $i++) { $targetData .= $html[$i]; // add html to variable } echo $targetData; // echo html
-
I have issue with my regex pattern, change it to preg_match('~<a name="ops"></a>(.*?)</table>~is', $html, $matches); $targetDate will contain <H3>Airport Operations</H3> <TABLE cellpadding=0 cellspacing=0 border=0> <TR><TD nowrap valign=top align=right>Airport use: </TD><TD valign=top>Open to the public</TD></TR> <TR><TD nowrap align=right>Activation date: </TD><TD>04/1966</TD></TR> <TR><TD nowrap valign=top align=right>Sectional chart: </TD><TD valign=top><A href="/sectionals">CHICAGO</A></TD></TR> <TR><TD nowrap align=right>Control tower: </TD><TD>yes</TD></TR> <TR><TD valign=top align=right>ARTCC: </TD><TD valign=top>CHICAGO CENTER</TD></TR> <TR><TD valign=top align=right>FSS: </TD><TD valign=top>KANKAKEE FLIGHT SERVICE STATION</TD></TR> <TR><TD nowrap valign=top align=right>NOTAMs facility: </TD><TD valign=top>ARR (NOTAM-D service available)</TD></TR> <TR><TD align=right>Attendance: </TD><TD>0600-2400</TD></TR> <TR><TD nowrap align=right>Wind indicator: </TD><TD>lighted</TD></TR> <TR><TD nowrap align=right>Segmented circle: </TD><TD>no</TD></TR> <TR><TD valign=top align=right>Lights: </TD><TD valign=top>WHEN ATCT CLSD HIRL RYS 15/33 & 09/27 & MIRL RY 18/36 PRESET LOW INTST; TO INCR INTST & ACTVT MALSR RYS 09, 33; REIL RYS 18;36,15,33 & 27, AND TWY LGTS - CTAF.</TD></TR> <TR><TD valign=top align=right>Beacon: </TD><TD valign=top>white-green (lighted land airport)<BR>Operates sunset to sunrise.</TD></TR>
-
I dont follow. This is the method you need to do in order loop over the results returned form a query. Your code for displaying the record needs to go into the while loop with the variables. My code example expanded while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $myfirstname = $row['firstname']; $mysurname = $row['surname']; $myaddress1 = $row['address1']; $myaddress2 = $row['address2']; $mytown = $row['town']; $mycounty = $row['county']; $mypostcode = $row['postcode']; $myhome = $row['landline']; $mymobile = $row['mobile']; $myemail = $row['email']; $myecontact = $row['econtact']; $myephone = $row['ephone']; // code for displaying record here // displayes the name, address and town for each record in the result echo " <p>Your name: $myfirstname</p> <p>Address: $myadddress1<br>$myaddress2<br>$myaddress3</p> <p>Town: $mytown<p> ..etc... "; } This will loop over the results displaying the information for each user. If you used fetchAll you still need to use some form of loop, // loop over all the results foreach($stmt->fetchALL(PDO::FETCH_ASSOC) as $row) { $myfirstname = $row['firstname']; $mysurname = $row['surname']; $myaddress1 = $row['address1']; $myaddress2 = $row['address2']; $mytown = $row['town']; $mycounty = $row['county']; $mypostcode = $row['postcode']; $myhome = $row['landline']; $mymobile = $row['mobile']; $myemail = $row['email']; $myecontact = $row['econtact']; $myephone = $row['ephone']; // code for displaying record here // displayes the name, address and town for each record in the result echo " <p>Your name: $myfirstname</p> <p>Address: $myadddress1<br>$myaddress2<br>$myaddress3</p> <p>Town: $mytown<p> ..etc... "; } This will have the same out come as the while loop
-
Find what you are looking for using regex $html = file_get_contents("http://www.airnav.com/airport/KARR"); preg_match('~<a name="ops"></a>.+</h3>(.*?)</table>~is', $html, $matches); $targetData = trim($matches[1]); echo $targetData; If you dont want the html included then apply strip_tags to $targetData;
-
You will need to use a while loop to loop over the results of the from the query while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $myfirstname = $row['firstname']; $mysurname = $row['surname']; $myaddress1 = $row['address1']; $myaddress2 = $row['address2']; $mytown = $row['town']; $mycounty = $row['county']; $mypostcode = $row['postcode']; $myhome = $row['landline']; $mymobile = $row['mobile']; $myemail = $row['email']; $myecontact = $row['econtact']; $myephone = $row['ephone']; // code for displaying record here }
-
You'll need to add extra logic to your while loop so it only displays the service and name once, and then lists the images,
-
The end of the regex should read bmp)$/i" the )$ should be before /i
-
The query could be failing due you using a reserved keyword as a column name. Range is a reserved keyword in MySQL. WHen using this column name in queries add backticks when you reference it in your query if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt, Race, health, level, str, agi, `range`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
-
Yes you can do what ever you want with it. To write data to a file use file_put_contents
-
Open/close the <tr> (table rows) outside of the while loop?
-
The function will return false when the prepared statement fails or the query did not return a result. It will only return the value of $thing when a result is returned from the query. You can add an else if you want, but it is optional in this case. Another way to code the function if ($stmt = $mysqli->prepare("SELECT Thing FROM members WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { $stmt->bind_result( $Thing); $stmt->fetch(); return $Thing; } else { return false; // query did not return 1 row } } else { return false; // prepared statement failed } Outcome will still be the same
-
I cant answer that. So far you providing a form so users can select items and provide options for a raffle. When the Create Raffle button is clicked you are submitting the data to PHP using ajax. When PHP retrieves the POST data you are json encoding it. What is the next step you are wanting to do?
-
Yes.
-
Try setting the iframe src attribute to an absolute url path. <script type="text/javascript">document.write(unescape(... src\"http://site.com/papatientInfoForm.php\" ... ... <iframe ... src="http://mysite.com/patientInfoForm/patientInfoForm.php" ...>
-
Yes. Do it in another function. Your code for the function is almost there, a few changes are required. First you need to get the user_id from $_SESSION['user_id'] not $Thingy $stmt->bind_param('i', $_SESSION['user_id']); // pass users id to query Now change $stmt->fetch(); to $stmt->fetch(); return $Thing; # return users Thing value } # close if for $stmt->num_rows } # close if for $stmt = $mysqli->prepare return false; # return false When you call getThing() you'd do $usersThing = getThing($mysqli); // get the users thing
-
MuphN Yes, however with your code as-is (with the changes I suggested) $thing will only be accessible from within the login_check() function. You wont be able to use this variable outside of this function. This is due to variable scope.
-
There already is a query that is using the users_id to get the password. You can change this query so it gets both the password and Thing To do this change $mysqli->prepare("SELECT password to $mysqli->prepare("SELECT password, Thing Not to assign Thing to a variable change $stmt->bind_result($password); to $stmt->bind_result($password, $thing); $thing now holds the value in the Thing column for current logged in user.
-
Using mysqli with prepared queries would be better.
-
Oh, change bind_param('ssss', to bind_param('sssss', ^ add 5th s I forgot to mention that earlier. The s stands for string it defines that data type for the input.