PHP - Php Script Double Posting To Mysql
Please help !
Hi guys, I am literally at my wits end with this and I am almost positive its in my code. This code is from a blackberry app that sends the infor into PHP, that part works flawlessy and was working just fine until I added the code to get the supervisor email from a different table based off a query. What happens is the information gets posted three times, The first time the emails are triggered and the post happens succefully, both the user and the supervisor get the properly formatted emails. This happens almost immediately, works great. Then almost immediately, the supervisor will get two more emails, with the same information except missing the orignal users email, presumably the user would have gotten two more emails as well if the email address was available. The mysql DB gets all 3 records with the second two missing the user email. Here is my code: <?php $dbServer1='contractor.emcee.tv'; $dbUser1='******'; $dbPass1='******'; $dbName1='purchaseorders'; $link = mysqli_connect("$dbServer1", "$dbUser1", "$dbPass1") or die("Could not connect post"); mysqli_select_db($link,"$dbName1") or die("Could not select database your_db_name1"); $job = $_GET['jobnumber']; $vend = $_GET['vendor']; $cat = $_GET['category']; $amt = $_GET['amount']; $note = $_GET['note']; $email = $_SERVER['HTTP_RIM_DEVICE_EMAIL']; $sql = mysqli_query($link,"insert po (job,vend,cat,amount,user,notes,date) values ('$job','$vend','$cat','$amt','$email','$note',NOW())"); if (!$sql){ print("FAILED"); } else { print("SUCCESS"); $query = "SELECT MAX(id) AS PO from po"; $result = mysqli_query($link, $query) Or die(mysqli_error($link)) ; while ($row = mysqli_fetch_assoc($result)) { $po = $row['PO']; } $query2 = "SELECT supervisoremail FROM job WHERE jobnum = $job"; $result2 = mysqli_query($link, $query2)Or die(mysqli_error($link)); while ($row2 =mysqli_fetch_assoc($result2)){ $sup = $row2['supervisoremail']; } $subject = "Purchase Order Request"; $supsubject = "FYI Purchase Order Completion"; $body = "Your purchase order request has been completed. \n \n Your PO number is: $po \n \n Job Number:$job \n Vendor:$vend \n Category:$cat \n Amount:$amt \n Items: \n $note \n \n A copy of this email has been sent to your supervisor."; $supbody = "A purchase order request has been completed. \n \n PO number $po was issued to $email for the following: \n \n Job Number:$job \n Vendor:$vend \n Category:$cat \n Amount:$amt \n Items: \n $note \n \n Please address this if this request is in error."; mail($email, $subject, $body); mail($sup, $supsubject, $supbody); } ?> Similar Tutorials$day = $_POST['day']; $month = $_POST['month']; $year = $_POST['year']; $date = date("Y-m-d", time(0,0,0,$month, $day, $year)); $sql="INSERT INTO child_info (first_name,middle_name,first_family_name,second_family_name, gender,birthdate,mother_living,father_living,brothers,sisters,resident_time,dorm,school,grade_level,school_subject,speak_english,food,medical_allergies,physical_limits,future,instrument,work,social,special_people,hobby,sponsor) VALUES ('$_POST[first_name]','$_POST[middle_name]','$_POST[first_family_name]','$_POST[second_family_name]','$_POST[gender]','$_POST[date]','$_POST[mother_living]','$_POST[father_living]','$_POST[brothers]','$_POST[sisters]','$_POST[resident_time]','$_POST[dorm]','$_POST[school]','$_POST[grade_level]','$_POST[school_subject]','$_POST[speak_english]','$_POST[food]','$_POST[medical_allergies]','$_POST[physical_limits]','$_POST[future]','$_POST[instrument]','$_POST[work]','$_POST[social]','$_POST[special_people]','$_POST[hobby]','$_POST[sponsor]')"; Hi, I got this form which passes hidden values as well as a select menu. The only thing is, it doesnt seem to post the form data to the script.
Here is the form
echo '<form action="regsale.php" method="POST">'; echo '<input type="hidden" name="username" value="<?php echo $username ?>"'; echo '<input type="hidden" name="listing_title" value="<?php echo $listing_title ?>"'; echo '<input type="hidden" name="speciesCommon" value="<?php echo $speciesCommon ?>"'; echo '<input type="hidden" name="cost" value="<?php echo $cost ?>"'; echo '<input type="hidden" name="business" value="<?php echo $business ?>"'; echo '<input type="hidden" name="postage_cost" value="<?php echo $postage_cost ?>"'; echo '<input type="hidden" name="multipostage" value="<?php echo $multipostage ?>"'; echo "<ul class='results'>"; echo '<li>Quantity:</li>'; echo '<select name="quantity">'; echo "<option value='$quantity'>Maximum of $quantity available</option>"; for ($q=1; $q<=$quantity; $q++) { echo "<option value='$q'>$q</option>"; } echo '</select>'; echo' </ul><br>'; echo '<div align="center">'; echo '<br>'; echo '<input type="submit" value="Confirm Purchase"><br>'; echo '</form><br>';And here is the script that the form is posted to <?php include 'init.php'; include 'includes/overall/header.php'; include 'includes/logo.php'; if (!isset($_SESSION['loggedin'])) { die("You must be logged in to submit care guides"); //this causes to script to stop executing and lets the user know there is a problem /* Note: instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave. */ } //else { //logged in elseif (isset($_SESSION['loggedin']) ){ //logged in $username = $_SESSION['loggedinuser']; if (isset($_POST['listing_title'], $_POST['speciesCommon'], $_POST['cost'], $_POST['business'], $_POST['postage_cost'], $_POST['multipostage'], $_POST['quantity'] ) ) { if( $_POST['listing_title'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['speciesCommon'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['cost'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['business'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['postage_cost'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['multipostage'] == "" ) { echo "Error: Please go back and try again"; } elseif( $_POST['quantity'] == "" ) { echo "Error: Please go back and try again"; } else { $listing_title = mysqli_real_escape_string($con, $_POST['listing_title']); $speciesCommon = mysqli_real_escape_string($con, $_POST['speciesCommon']); $cost = mysqli_real_escape_string($con, $_POST['cost']); $business = mysqli_real_escape_string($con, $_POST['business']); $postage_cost = mysqli_real_escape_string($con, $_POST['postage_cost']); $multipostage = mysqli_real_escape_string($con, $_POST['multipostage'] ); $quantity = mysqli_real_escape_string($con, $_POST['quantity'] ); if( $multipostage == "per item" ) { $postage_cost = $quantity * $postage_cost; } elseif( $multipostage == "Combined Postage" ) { $postage_cost; } $total = $cost + $postage_costage; // Writes customer_sales information to the MySQL database $sqlCustomerSales = "INSERT INTO customer_sales(username, listing_title, speciesCommon, total, business, postage_cost, multipostage ) VALUES ( '". $username ."', '". $listing_title ."', '". $speciesCommon ."', '". $total ."', '". $business ."', '". $postage_cost ."', '". $multipostage."' )"; $result1 = mysqli_query($con, $sqlCustomerSales); // This writes the transaction to the MySQL database $memo = $listing_title; $datetime = date("Y-m-d H:i:s"); $regCustomerTransaction = "INSERT INTO customer_transactions(username, datetime, cost, postage_cost, memo) VALUES ( '". $username ."', '". $datetime ."', '". $cost ."', '". $postage_cost ."', '". $memo."' )"; // Query the database $result2 = mysqli_query($con, $regCustomerTransaction); } // This writes the user_stats to the MySQL database $total_items_sold = $quantity; $regUserStats = "INSERT INTO user_stats(username, datetime, total, items_listed, bonus_credits, last_credit_purchase, total_care_guides, total_items_sold, total_currently_listed_items, total_items_purchased, total_diary_entries, feedback ) VALUES ( '". $username ."', '". $datetime ."', '". $total ."', '". $quantity ."', '". $subtotal ."', '". $last_credit_purchase ."', '". $total_care_guides ."', '". $total_items_sold ."', '". $total_currently_listed_items ."', '". $total_items_purchased ."', '". $total_diary_entries ."', '". $feedback."' )"; // Query the database $result3 = mysqli_query($con, $regUserStats); } ?> <h1>Payment to <?php echo $username ?></h1><br> <?php echo '<strong>Thank you for confirming you would like to purchase $speciesCommon; </strong>'; echo '<br>'; echo '<strong>Your payment comes to a total of $total; </strong></h2>'; echo '<br>'; echo '<br>'; echo 'Please complete payment using the PayPal button<br>'; echo '<br>'; echo '<br>'; ?> <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="shipping" value="<?php echo $postage_cost ?>"> <input type="hidden" name="business" value="<?php echo $business ?>"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="item_name" value="<?php echo $speciesCommon ?>"> <input type="hidden" name="amount" value="<?php echo $cost ?>"> <input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" onclick="OnButton1(); OnButton2();" alt="PayPal – The safer, easier way to pay online." > <img alt="" align="center" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"></form> <?php } else { echo 'Sorry we were unable to process your listing. Please contact <a href="mailto:helpdesk@aquapetcentre.com?Subject=Listing%20error">helpdesk@aquapetcentre.com'; die(); include('includes/overall/footer.php'); } // Close the connection mysqli_close($con); ?><h1>Payment to <?php echo $username ?></h1><br> works, but I think that is because it is passed in the SESSION. Any other $variable such as those below echo '<strong>Thank you for confirming you would like to purchase $speciesCommon; </strong>'; echo '<br>'; echo '<strong>Your payment comes to a total of $total; </strong></h2>';does not work. Why is the form not posting the values to the database. Just in case it helps, the form gets its values from the database, and the values are displayed in the sales page on which the form is contained. Here is the page containing the form. <?php include 'init.php'; include 'includes/overall/header.php'; include 'includes/logo.php'; if (!isset($_SESSION['loggedin'])) { die("You must be logged in to view this page!"); //this causes to script to stop executing and lets the user know there is a problem /* Note: instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave. */ } //else { //logged in elseif (isset($_SESSION['loggedin']) ){ //logged in $username = $_SESSION['loggedinuser']; $results = $con->query("SELECT * FROM user WHERE username = '$username';"); while($row = $results->fetch_array()) { $business = $row['paypal_email']; $user_id = $_GET['user_id']; $results1 = $con->query("SELECT * FROM live_sales WHERE user_id = '$user_id';"); while($row = $results1->fetch_array()) { $username = $row['username']; $fishtype = $row['fishtype']; $speciesCommon = $row['speciesCommon']; $speciesScientific = $row['speciesScientific']; $listing_title = $row['listing_title']; $age = $row['age']; $quantity = $row['quantity']; $origin = $row['origin']; $size = $row['size']; $environment = $row['environment']; $waterChemistry = $row['waterChemistry']; $temperature = $row['temperature']; $feeding = $row['feeding']; $sexing = $row['sexing']; $compatability = $row['compatability']; $temperament = $row['temperament']; $breeding = $row['breeding']; $comments = $row['comments']; $postage_type = $row['postage_type']; $postage_cost = $row['postage_cost']; $multipostage = $row['multipostage']; $cost = $row['cost']; echo "<div class='result'>"; echo "<h3>$speciesCommon</h3>"; echo "<h2>$listing_title</h2>"; echo "<ul class='results'>"; echo "<li>Species</li>" . str_replace("_"," "," $fishtype") . "<br>"; echo "<li>Common Name:</li> $speciesCommon<br>"; echo "<li>Scientific Name:</li> $speciesScientific<br>"; echo "<li>Age:</li> $age<br>"; echo "<li>Quantity:</li> $quantity<br>"; echo "<li>Price per item:</li> £$cost<br>"; echo "<li>Origin:</li> $origin<br>"; echo "<li>Size:</li>$size<br>"; echo "<li>Environment:</li> $environment<br>"; echo "<li>Water Chemistry</li> $waterChemistry<br>"; echo "<li>Temperatu </li> $temperature<br>"; echo "<li>Feeding:</li> $feeding<br>"; echo "<li>Sexing:</li> $sexing<br>"; echo "<li>Compatability:</li> $compatability<br>"; echo "<li>Temperament:</li> $temperament<br>"; echo "<li>Breeding:</li>$breeding<br>"; echo "<li>Comments:</li> $comments<br>"; echo "<li>Postage Type:</li>$postage_type<br>"; echo "<li>Postage Cost:</li> £$postage_cost $multipostage<br>"; echo '<form action="regsale.php" method="POST">'; echo '<input type="hidden" name="username" value="<?php echo $username ?>"'; echo '<input type="hidden" name="listing_title" value="<?php echo $listing_title ?>"'; echo '<input type="hidden" name="speciesCommon" value="<?php echo $speciesCommon ?>"'; echo '<input type="hidden" name="cost" value="<?php echo $cost ?>"'; echo '<input type="hidden" name="business" value="<?php echo $business ?>"'; echo '<input type="hidden" name="postage_cost" value="<?php echo $postage_cost ?>"'; echo '<input type="hidden" name="multipostage" value="<?php echo $multipostage ?>"'; echo "<ul class='results'>"; echo '<li>Quantity:</li>'; echo '<select name="quantity">'; echo "<option value='$quantity'>Maximum of $quantity available</option>"; for ($q=1; $q<=$quantity; $q++) { echo "<option value='$q'>$q</option>"; } echo '</select>'; echo' </ul><br>'; echo '<div align="center">'; echo '<br>'; echo '<input type="submit" value="Confirm Purchase"><br>'; echo '</form><br>'; echo '<br><br> </div>'; exit(); } } echo 'Sorry but we could not find any results.'; } include 'includes/overall/footer.php'; ?>Any help is always appreciated. aquaman Hi Friends, I am suffering with very serious problem, We have a deal selling website--Problem is that when someone buy a deal , they are getting 2 vouchers on bahalf of one while they are getting charged ones only [I am using authorized.net payment gateway]. for some reason Entry is inserting TWICE in MYSQL but it is not happening on every purchase, it happens once in 20 purchase (for example).... I have tried every possible effort but it still happens, anybody can show me helping hand please ? this is my partial code where I am inserting the voucher info : for($i=0; $i<$_SESSION['quHidden']; $i++): if($_SESSION['RecName'][$i]!=''):$IsGist="t";$GRName=$_SESSION['RecName'][$i];else:$IsGist="f";$GRName="";endif; $coupon_code=str_makerand("12", "12", "false", "false", "false"); $NCCod="#".$coupon_code; $download_path="dealcoupon.php?id=".$sql_coupon['deal_id']."&CRANCode=".$coupon_code; $DLContent[]="<a href=\"".$download_path."\" target=\"_blank\" style=\"font-family: Helvetica,Arial,sans-serif; color: rgb(9, 129, 190);font-size: 14px;\">Download Voucher: ".$NCCod."</a>"; mysql_query("INSERT INTO `tbl_purchase` ( `fld_buyerid` , `fld_dealid` , `fld_amount` , `fld_purchaseid`, `fld_subdate`, `fld_expdate`, `fld_quantity`, `fld_cardno`, `isGift`, `fld_RecName`) VALUES ( '".$_SESSION['usr_id']."', '".$sql_coupon['deal_id']."', '".$sql_coupon['deal_price']."', '$NCCod', '".time()."', '".$sql_coupon[deal_edate]."', '1', '".$_SESSION['x_card_num']."','".$IsGist."','".$GRName."')"); $CoupanArr[]=$NCCod; endfor; //--------------------------------------------------------------------- mysql_query("insert into tbl_vouemails set fld_did='".$sql_coupon['deal_id']."', fld_uid='".$_SESSION['usr_id']."', fld_voucher='".implode(",",$CoupanArr)."', fld_etime='".getPATime($sql_coupon[deal_edate])."', fld_subdate='".time()."', fld_VReceiver='".implode(",",$_SESSION['RecName'])."'"); At the fear of bothering all you, I will post here hoping that I am in the write section. I am new to php and mysql. I am using such to develope a webpage for my new business. I do believe that my php scripting is turned on because I have one script that "works". However when I take the wheel and write a script of my own and try to view it all I get is a blank white page and no errors nor anything that I wanted to display. I have tried numerous attempts at tiring to get anything to show up all I can ever seem to do is "echo" something anything else is null in displaying. Please feel free to take a look. http://72.28.26.162/rc/ phpinfo.php is accessible if you insert it after the last / (http://72.28.26.162/rc/phpinfo.php) I am at a loss. I have spent hours looking for something I miss during set up or with my procedure. I thank whomever my help me in advance. I am running ubuntu server 10 Apache/2.2.16 port 80 (Please advise if you need anything else) thanks When I add a ' or " quotes in a textarea I get a sql error when it tries to insert the record.
I was told to use mysqli_real_escape_string but that didn't work.
Here's my code -
$blog= mysqli_real_escape_string($con, $_POST['blog']); $blog= $_POST['message']; $sql = "SELECT * FROM table WHERE `message` = '{$message}'"; $result = mysql_query($sql); if ( mysql_num_rows ( $result ) > 0 ) { $error = "Message Exists."; } else { $error = "This message does not exist. Insert it!!!"; $sql="INSERT INTO table (message) VALUES ('$_POST[message])"; } if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con) Edited by barkly, 26 October 2014 - 09:31 PM. I'm having problems posting date from my MYSQL database. The date in my database is this "2011-01-08 02:53:14" but the it only echo's "01.01.70" Could someone help me figure out why? Here is my code: Code: [Select] <?php $servername='localhost'; $dbusername='root'; $dbpassword=''; $dbname='store'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } // Get all the data from the "example" table $result = mysql_query("SELECT * FROM henvendelser WHERE status = 'Ubehandlet' ORDER by id desc ") or die(mysql_error()); echo "<table cellspacing='12px' cellpaddomg='5px' align='center'>"; echo "<tr> <th>ID</th> <th> Opprettet </th> <th>Navn</th> <th>Telefon</th> <th>Emne</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array($result)) { $postTime = $row['date']; $thisTime = time(); $timeDiff = $thisTime-$postTime; if($timeDiff <= 604800) { // Less than 7 days[60*60*24*7] $color = '#D1180A'; } else if($timeDiff > 604800 && $timeDiff <= 1209600) { // Greater than 7 days[60*60*24*7], less than 14 days[60*60*24*14] $color = '#D1B30A'; } else if($timeDiff > 1209600) { // Greater than 14 days[60*60*24*14] $color = '#08C90F'; } echo '<tr style="color: '.$color.';">'; echo '<td>'. $row['id'] .'</td>'; echo '<td>'. date('d.m.y', $postTime) .'</td>'; echo '<td><a href="detaljer.php?view='. $row['id'] .'">'. $row['Navn'] .'</a></td>'; echo '<td>'. $row['Telefon'] .'</td>'; echo '<td>'. $row['Emne'] .'</td>'; echo '</tr>'; } echo '</table>'; ?> Hi everyone, First off thank you very kindly to anyone who can provide some enlightenment to this total php/mysql newb. I am creating my first database and while I have been able to connect to the database within my php script (or so I believe), the form data does not appear to be actually getting sent. I have development experience in other languages but this is completely new to me so if I've missed something that appears painfully obvious like a parse error of some sort, I do apologize. I am creating a website using Godaddy as the hosting account, and attempting to connect to the mysql database at the following URL (maybe this is where I'm going wrong): "pnmailinglist.db.4662743.hostedresource.com" Below is my very simple code: <?php //Verify successful connection to database. $connect = mysql_connect("pnmailinglist.db.4662743.hostedresource.com", "*********", "*********"); if(!$connect) {die("Could not connect!"); } //Initialize variables with form data. $firstname = $_POST['FirstName']; $lastname = $_POST['LastName']; $email = $_POST['Email']; $howfound = $_POST['HowFound']; //Post data to database, or return error. mysql_select_db("pnmailinglist", $connect); mysql_query("INSERT INTO mailinglist (First, Last, Email, How_Found) VALUES ($firstname,$lastname,$email,$howfound)"); mysql_close($connect); echo "Thank you for joining our mailing list! We will contact you soon with the dates and times of our upcoming events."; ?> Thank you again very much for any pointers or hints as to where I'm screwing up. I get no runtime errors, no syntax errors, and the echo message does display fine at the end -- just no data when I go to check my database! Best Regards, CL Hi, Can anyone help me with a script, I have tried a if statement but I cannot get it to work and its driving me mad. Basically I have a string my website uses to get if the user is logged in what their username is and I want it so when they click a certain link it checks to see if a table all ready exists called their username, if it does it displays a message, if it doesnt it creates the table and if the username is "anonymous" is displays a message. So in short: if $username is the same as a table display "Table all ready exists" if $username="anonymous" display "You must be logged int" if $username not the same as a table then create table. Many thanks in advance Jay TRUNCATE TABLE CubeCart_cats_idx; INSERT INTO CubeCart_cats_idx (productid, cat_id) SELECT productid, cat_id FROM CubeCart_inventory; I an running the following in MyPHPAdmin, but need this to be automated in a PHP script, how would I do it ? all help is appreciated, still new to PHP & MySQL many thanks D hi i am having a problem with a php script. i have 3 files index.php, home.html.php, form.html.php. home.html.php is working fine, if has a form that is submitting fine but when it submits i get a problem. maybe someone can help me out please i would be grateful as i am new. the is nothing wrong with anything else mysql database is running fine and there is no problem with connection. index.php (you can ignore what is commented out) <?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; //$_GET['id'] is categoryid if (isset($_GET['id'])) { include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_GET['id']); $sql = "SELECT businessid FROM businesscategory WHERE categoryid LIKE '$id'"; $result = mysqli_query($link, $sql); if ($result !='') { $businessid = mysqli_fetch_array($result); $sql = "SELECT content FROM business WHERE id LIKE '$businessid'"; $result = mysqli_query($link, $sql); } if ($result !='') { $content = mysqli_fetch_array($result); include 'form.html.php'; exit(); } } /* // The basic SELECT statement $select = 'SELECT content'; $from = ' FROM business'; $where = ' WHERE TRUE'; $id = mysqli_real_escape_string($link, $_GET['id']); if ($category != '') // An owner is selected { $where .= " AND categoryid='$categoryid"; } $categoryid = mysqli_real_escape_string($link, $_GET['category']); if ($categoryid != '') // A category is selected { $from .= ' INNER JOIN businesscategory ON id = business'; $where .= " AND categoryid='$categoryid'"; } $text = mysqli_real_escape_string($link, $_GET['text']); if ($text != '') // Some search text was specified { $where .= " AND content LIKE '%$text%'"; } $result = mysqli_query($link, $select . $from . $where); if (!$result) { $error = 'Error fetching businesses.'; include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $businesses[] = array('id' => $row['id'], 'text' => $row['content']); } include 'form.html.php'; exit(); } */ $result = mysqli_query($link, 'SELECT id, name FROM category ORDER BY name'); if (!$result) { $error = 'Error fetching categories: ' . mysqli_error($link); include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $categories[] = array('id' => $row['id'], 'text' => $row['name']); } include 'home.html.php'; ?> form.html.php <?php include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/helpers.inc.php'; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="generator" content="PSPad editor, www.pspad.com"> <title>Business</title> </head> <body> it works <?php echo $content; ?> </body> </html> hello guys. i sitting here at my pc , have used alot days on google and forums. but i just cant seem to find what i am looking for so i hope that anyone here got a min to tell me what to do okai soo what i am looking for is a php / mysql script that can countdown for a user , when its finish add a number ( to usertabel[2]. and the problem is it need to do it also if the user closes the browser. i am total lost , have no ide to fix / wihte it Sorry for my spelling i am danish Hello, I'm new to this website so forgive me if I'm posting in the wrong section. I just need to know if there is a way that I can retrieve php script that is stored in a database? for example, in my database in table: <? echo"Hello World"; ?> and in my php file, I call that using: <? mysql_connect("asdas","asdas","asd"); mysql_select_db("asdasda"); $result = mysql_query("select * from somedatabse"); while($r=mysql_fetch_array($result)) { $table=$r["table"]; } echo"$table"; ?> i know its confusing, i just hope i made sense and that someone understands what im trying to do. any help will be appreciatedddd thank you : ) Hiya guys, I'm having problems with a code i have written, it seems that nor google or my own search engine is picking up the links? And i don't understand why. I know the following code has a div on click rule, but i have also added an a href. I tried the basic link which is also not picking up. Code: [Select] <?php $old_pattern = array("/[^a-zA-Z0-9]/", "/_+/", "/_$/"); $new_pattern = array("_", "_", ""); $i = '1'; while($row = mysql_fetch_array($result)) { ${videoData_.$i} = mysql_query("SELECT * FROM videoData WHERE qid=".$row['id']."") or die(mysql_error()); ${row_.$i} = mysql_fetch_array(${videoData_.$i}); ${vote_.$i} = mysql_query("SELECT SUM(votes) FROM answers WHERE qid=".$row['id']."")or die(mysql_error()); ${votes_.$i} = mysql_fetch_array(${vote_.$i}); $pagelink = strtolower(preg_replace($old_pattern, $new_pattern , $row['question'])); echo '<div class="NVP-div" '; echo 'onclick="location.href=\'http://www.thevideopoll.com/polls/'; echo $link = "".$row['id']."-_-".$pagelink.".php"; echo '\';" style="cursor: pointer;"'; echo '>'; echo '<img style="float:left; margin-left:25px;" src="http://img.youtube.com/vi/'.${row_.$i}['videoID'].'/default.jpg">'; echo '<p class="NVP-vote">'; echo ${votes_.$i}['SUM(votes)']; echo ' Votes'; echo '</p>'; echo '<br>'; echo '<a class="new-video-links" href="http://www.thevideopoll.com/polls/'; echo $link = "".$row['id']."-_-".$pagelink.".php"; echo '" title="'.$row['question'].'">'; echo "".$row['question'].""; echo "</a>"; echo '</div>'; $i++; } ?> Hey everyone, I'm currently working on a friends online script and i have a slight problem that i need help with. Basically the code first searches "TBL_Friends" to see if you have any friends added. If it returns results it then turns your friends ID's into a variable. It then searches "TBL_Users_Online" to see if any body is logged based on the friend's ID it returned before. The first bit of the code works and it retrieves all the friends i got added. The second half is odd, if i have one or two friends added it will show that one is online. If i have more then three friends added it returns no results. I know my code is a bit sloppy and probably not the best way of writing it, im still learning PHP. Anyways this is the code, any help is appreciated. Code: [Select] <?php $FriendsOnline = mysql_query("SELECT Sender_ID FROM TBL_User_Friends WHERE Reciever_ID = $UserID"); while($fo=mysql_fetch_array($FriendsOnline)) { $FriendsOnlineID = $fo[Sender_ID]; $FriendsOnlineNumber = mysql_query("SELECT * FROM TBL_Users_Online WHERE User_ID = $FriendsOnlineID"); $FriendsNumber = mysql_num_rows($FriendsOnlineNumber); echo $FriendsNumber; } ?> $SenderID = Friends ID $Reciever_ID = User ID $UserID = User ID Hi, I am trying to convert the register & login script from mysql to mysqli. I have converted the easy parts and have the connection to the database, but the following functions all need changing and I can't work out the correct solution mainly due to the deprecation of mysql_result() The code that needs updating is <?php function user_count() { return mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `active` = 1"), 0); } function users_online() { return mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `logged_in` = 1"), 0); } function change_profile_image($user_id, $file_temp, $file_extn) { $file_path = 'images/profile/' . substr(md5(time()), 0, 10) . '.' . $file_extn; move_uploaded_file($file_temp, $file_path); mysql_query("UPDATE `users` SET `profile` = '" . mysql_real_escape_string($file_path) . "' WHERE `user_id` = " . (int)$user_id); } function has_access($user_id, $type) { $user_id = (int)$user_id; $type = (int)$type; return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_id` = $user_id AND `type` = $type"), 0) == 1) ? true : false; } function activate($email, $email_code) { $email = mysql_real_escape_string($email); $email_code = mysql_real_escape_string($email_code); if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1) { mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'"); return true; } else { return false; } } function user_exists($username) { $username = sanitize($username); $query = mysql_query("SELECT COUNT('user_id') FROM `users` WHERE `username` = '$username'"); return (mysql_result($query, 0) == 1) ? true : false; } function email_exists($email) { $email = sanitize($email); return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email'"), 0) == 1) ? true : false; } function user_id_from_username($username) { $username = sanitize($username); return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, 'user_id'); } function user_id_from_email($email) { $email = sanitize($email); return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `email` = '$email'"), 0, 'user_id'); } function login($username, $password) { $user_id = user_id_from_username($username); mysql_query("UPDATE `users` SET `logged_in` = 1 WHERE `user_id` = $user_id"); $username = sanitize($username); $password = md5($password); return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) == 1) ? $user_id : false; } ?>And here is what the converter gave me: function user_count() { return mysql_result(mysqli_query($GLOBALS["___mysqli_ston"], "SELECT COUNT(`user_id`) FROM `users` WHERE `active` = 1"), 0); } function users_online() { return mysql_result(mysqli_query($GLOBALS["___mysqli_ston"], "SELECT COUNT(`user_id`) FROM `users` WHERE `logged_in` = 1"), 0); } function change_profile_image($user_id, $file_temp, $file_extn) { $file_path = 'images/profile/' . substr(md5(time()), 0, 10) . '.' . $file_extn; move_uploaded_file($file_temp, $file_path); mysql_query("UPDATE `users` SET `profile` = '" . mysql_real_escape_string($file_path) . "' WHERE `user_id` = " . (int)$user_id); } function has_access($user_id, $type) { $user_id = (int)$user_id; $type = (int)$type; return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_id` = $user_id AND `type` = $type"), 0) == 1) ? true : false; } function activate($email, $email_code) { $email = mysql_real_escape_string($email); $email_code = mysql_real_escape_string($email_code); if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1) { mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'"); return true; } else { return false; } } function user_exists($username) { $username = sanitize($username); $query = mysql_query("SELECT COUNT('user_id') FROM `users` WHERE `username` = '$username'"); return (mysql_result($query, 0) == 1) ? true : false; } function email_exists($email) { $email = sanitize($email); return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email'"), 0) == 1) ? true : false; } function user_id_from_username($username) { $username = sanitize($username); return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, 'user_id'); } function user_id_from_email($email) { $email = sanitize($email); return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `email` = '$email'"), 0, 'user_id'); } function login($username, $password) { $user_id = user_id_from_username($username); mysql_query("UPDATE `users` SET `logged_in` = 1 WHERE `user_id` = $user_id"); $username = sanitize($username); $password = md5($password); return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) == 1) ? $user_id : false; } ?>Please could someone point me in the right direction here? Also my site works perfectly well with MySQL, do I have to convert it to MySQLi? Many Thanks Paul If anyone knows how to solve this, it would be much appreciated. I already have a website template and would prefer to continue with mysqli instead of PDO. Many Thanks Paul Hey guys! I'm not that good with PHP, and I really need to finish this script. I'm having a hard time finding the problem..it keeps saying Error, query failed and I've also checked the database info, connectivity info and even tried a connection and database selection verification to see if that was working. Is there any other error you guys can find in the script that may be causing the message? Edit: The files I want to be able to upload should be pdf's, txts, docs, etc. Would that be possible with this script? Thanks!! Code: [Select] <form method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="104857600"></td> <td width="80"> </td> </tr> </table> <p>Archivo: <input name="userfile" type="file" id="userfile" /> </p> <p>Nomb <label for="name"></label> <input type="text" name="nombrelista" id="nombrelista" /> </p> <p>Password (para luego borrar si necesario): <input type="text" name="pass" id="pass" /> </p> <p> <input name="upload" type="submit" class="box" id="upload" value=" Upload " /> </p> <?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePass = $_POST['pass']; $nombreLista = $_POST['nombrelista']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); $host_db = "localhost"; $user_db = "melkien_rudesa"; $pass_db = "jorlan2407"; $base_db = "melkien_rudesa"; $link = mysql_connect($host_db, $user_db, $pass_db); if (!$link) { die('Could not connect: ' . mysql_error()); mysql_close($link); } mysql_select_db($base_db, $link) or die(mysql_error()); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $query = "INSERT INTO 'upload'('nombrelista', 'name', 'pass', 'size', 'type', 'content' ) VALUES ('$nombreLista', $fileName', '$filePass', $fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; mysql_close($link); } ?> </form> Hello, I am very new to both PHP and MYSQL but I am eager to learn. What I want to do is write a PHP script that will parse an XML file and insert the results into a MYSQL database. I've read a bunch of guides online and I think I have the parser structure down. I created a parser using xml_parser_create(). As I understand it, I need to create functions to handle each of the three events, startTag, endTag, and contents. This is where I am not sure what to do. What do I need to tell these functions to do when these events are triggered? I know I need to connect to the MYSQL database at some point but I do not know when. If anyone could point me in the right direction, I'd appreciate it. Hi, Im just in the middle of creating an update script for my mysql database but don't know why it's not working. p.s. I'm a little new to PHP, but know quite a bit, it's probably something really small.. *facepalm* Here's the script: the form (update.php) <? // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $id = $_GET['id']; // Ask the database for the information from the links table $query="SELECT * FROM orders WHERE id='$id'"; $result = mysql_query("SELECT * FROM orders"); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $name=mysql_result($result,$i,"Name"); $location=mysql_result($result,$i,"Location"); $fault=mysql_result($result,$i,"Fault"); ?> <form action="updated.php" method="post"> <input type="hidden" name="ud_id" value="<? echo "$id";?>"> Name: <input type="text" name="ud_name" value="<? echo "$name"?>"><br> Location: <input type="text" name="ud_location" value="<? echo "$location"?>"><br> Fault: <input type="text" name="ud_fault" value="<? echo "$fault"?>"><br> <input type="Submit" value="Update"> </form> <? ++$i; } ?> ------------------------------------------------------ (processor) updated.php <?php // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $query="UPDATE orders SET Name='" . $_POST['ud_name'] . "', Location='" . $_POST['ud_location'] . "', Fault='" . $_POST['ud_fault'] . "' WHERE $id='" . $_POST['ud_id'] . "'"; echo $query; $checkresult = mysql_query($query); if ($checkresult) echo '<p>update query succeeded'; else echo '<p>update query failed'; mysql_close(); ?> ------------------------------------------------------ Every time I want to update, it comes up with: UPDATE orders SET Name='TEST', Location='TEST', fault='jbjh' WHERE ='' update query failed Any help would be appreciated. Hello, I know i'm new, i hope it wont stop you guys from putting 5 minutes of your time to help me out. I need a script to get some data from mysql and put this into a table. i have a mysql database called "denora" In there is a table called "chan" In table chan are the columns: chanid (unique number), channel, currentusers, mode_ls I would like the script to make a html table that lists the top10 channels (most "currentusers" on top) And when "mode_ls" is "Y" it must not be shown (secret channel) My knowledge of php and mysql arent that great so i really hope someone takes the time to help me uit Kind regards Stefan Hello. i am writing an API for lua... that sends POST requests to a php script. this php script is malfunctioning. below is the code and error. |