PHP - Php Newbie: Problem With A Function, Easy Solution?
hello,
I'm a beginner when it comes to PHP: I'm working on a log in system but i keep on getting the same errors which makes my system unreliable. this is the function I'm trying to use: if(pg_numrows($q) == 1){ echo "<p>Someone took that username</p>"; include "signup.php"; exit; } --> I'm using a postgresql database this is the warning I keep on getting: Code: [Select] Warning: pg_numrows(): supplied argument is not a valid PostgreSQL result resource in /var/ftpdirs/512544/PHP/login/adduser.php on line 13 I have the same problem when I try to look if an username is taken or not... when people try to register this is my adduser.php file: <?php session_start(); include "connectie_db.php"; $User_name = $_POST['user_name'] ; $User_pass = $_POST['user_pass'] ; $User_pass2 = $_POST['user_pass2'] ; $checkUsername= "SELECT user_name from tovanu.users where user_name = '$User_name';"; $q = $db->exec($checkUsername); if(MDB2::isError($q)){ echo "code: ".$q->getUserInfo(); exit(); } if(pg_numrows($q) == 1){ echo "<p>Someone took that username</p>"; include "signup.php"; exit; } If(strlen($User_name > 32)){ echo "<p>The username is too long</p>"; include "signup.php"; exit; } if($User_pass != $User_pass2){ echo "<p>Both passwords must be the same</p>"; include "signup.php"; exit; } $password = md5($User_pass); $add = "INSERT INTO tovanu.users (user_name,user_pass,user_email,user_date,user_level,naam,adres,plaats,postcode) VALUES ('$User_name','$password','email',current_date,1,'jef','jonhstraat','maaseik','3687')"; $execute = $db->exec($add) ; if(MDB2::isError($execute)){ echo "code: ".$q->getUserInfo(); exit(); } $_SESSION['user'] = $username; include "index.php"; ?> any help would be appreciated!!!!!!!!!!! Similar TutorialsHi guys, I have a simple INSERT code. It does not throw any errors and all seems ok but the data is just not appearing in the DB. I've spent ages looking over it but perhaps a 2nd set of eyes could help? Thanks! Code: [Select] $con = mysql_connect("localhost","posturep",""); $tablename = 'product'; if (!$con) { die('Could not connect: ' . mysql_error()); } //Form data sent $product_name = $_POST['product_name']; $product_active = $_POST['product_active']; $product_cat = $_POST['product_cat']; $product_desc = $_POST['product_desc']; $prod_inoutdoor = $_POST['prod_inoutdoor']; $prod_stackable = $_POST['prod_stackable']; $prod_discounted = $_POST['prod_discounted']; echo $product_name; $sql = "INSERT INTO $tablename (name) VALUES ($product_name)"; mysql_query($sql); echo "<p>Product Saved!</p>"; echo $sql; mysql_close($con); Wow, am I glad I found this forum! I spent the past few hours trying to modify a PHP/mySQL script in order to test it. What this script does is basically look up a mySQL database (based on ip2nation) to find out what country and currency the IP address belongs to. This is the code sample: Code: [Select] $sql = 'SELECT c.country, c.curr_code FROM ip2nationcountries c, ip2nation i WHERE i.ip < INET_ATON("24.24.24.24") AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1'; $countryName = $db->get_sql_row($sql); I tested the code in PHPmyAdmin and it returns 2 rows: country ------- curr_code (row names) United States ------- USD (actual values) So basically 2 variables, United States and USD. Now comes the problem, in order to test the script for several countries, I need to be able to "override" the result in the PHP script I tried to do that by commenting out the part that returns the result from the mySQL query and modifying it with the following style, but I think I'm doing something wrong: Code: [Select] ### $countryName = $db->get_sql_row($sql); ### $countryName = "United States USD"; Is there any way that I can temporarily override the result returned by mySQL and "fake it" so to say? I understand the mySQL query returns 2 rows, so how would I go about overriding 2 rows? I hope this makes sense ...you're all my last hope. So I know next to nothing about PHP so I need some help with something thats probably incredibly easy. I just need a function(hope I'm using that right) that checks if a div with a certain class exists in the same page. then based on whether that's true or not changes the class of an image. This is how I imagine it looks except I don't know what to put in the if brackets to make it find the div and evaluate if its there or not. <img if (){ echo(class=\"visible\"); } else{ echo(class=\"hidden\"); } } src=\"icon.png\" /> hi i am calling some text from a database with php and echoing it to flash. i have no idea the charset anything is in. all i can see is that calling the text from the database and placing into flash yields in some missing chars, but if echo the called text to the browser, copy it and echo that to flash, all characters appear. now, i kow this is not a flash forum, and im not going to ask for a flash solution because there's just too many different charsets and code i cannot control/ nor see so i was thinking of doing something along the line of having php creating a clone of the copied text that appears in the browser, and having it echo that text to flash. it there something php can do, similar to what i described? regards <?php query_posts('showposts=10'); ?> <!-- The 10 most recent post, the first one not included --> <h2>Other Recent Articles</h2> <ul> <?php while (have_posts()) : the_post(); ?> <li><span class="title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></span> <span class="meta"></span></li> <?php endwhile; ?> </ul> <br /> <p class="link"><a href="<?php echo get_option('home'); ?>/archives" title="View Archives">View Archives</a></p> The the first line in the code will display the last 10 posts from all categories. this one: <?php query_posts('showposts=10'); ?> But I want to display the last 10 posts from all categories EXCEPT for the newest post in category 12. so the formula should look something like this... <?php query_posts('showposts=10 BUT DO NOT INCLUDE THE NEWEST POST FROM CAT 12 '); ?> I'm not sure how to do this, can anyone help? This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=321319.0 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php //MySQL Database Connect include 'sqlconnect.php'; ?> <select name="aktivitet" id="aktivitet"> <?php //MySQL Database Connect include 'sqlconnect.php'; $sql = mysql_query("SELECT title FROM aktiviteter"); while ($row = mysql_fetch_array($sql)){ echo "<option value=\"owner1\">" . $row['title'] . "</option>"; } ?> </select> </body> </html>why dosnt this work?, if you cant see what i want to happen, ill post an explaination Hi, Im pretty new to php but im have trouble understanding why my script is doing this. Forgive me for silly mistakes! Im creating a login/register website and once the person has logged in they get a message saying "Successful login, welcome username!" The php checks against a database of users in an if statement to check if the password is correct and then prints out the message. But at the end of the message the echo is printing out a 1. I get that because the echo is in an if statement its return true or 1 but I cant get it to not print out the 1. code snippet is - if ($username==$dbusername&&$password==$dbpassword) { echo "Successful login, welcome!"; } Hope that makes sense. Thanks for the help. Neil I've been searching for a couple of days on google using keywords, trying to figure out why this form sends blank emails. I've found several different ways to write something like this, including what's below, but for the life of me I haven't figured it out. Can anyone help a brother out? <?php $email = $_REQUEST['email']; $message = $_REQUEST['date']; $message .= $_REQUEST['location']; $message .= $_REQUEST['quantitymodel']; mail( "name@email.com", "Email Contact Form", $message, "From: $email" ); header( "Location: thankyou.html" ); ?> I am learning PHP/MySQL and am modifying a tutorial to make a contact database. All I want is to be able to make a web page for each contact(record) and display one record on each webpage. I want to use the URL featu "http://www.mysite.com/script.php?=item1" type of thing Can any help me as I can't get it to work. I get no errors - it just doesnt display the info. I'm sure I cant be far off as I've only modified a working script ever so slightly. Code: [Select] mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); ?> <? $query="SELECT * FROM contacts WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif">Mobile</font></th> <th><font face="Arial, Helvetica, sans-serif">Fax</font></th> <th><font face="Arial, Helvetica, sans-serif">E-mail</font></th> <th><font face="Arial, Helvetica, sans-serif">Website</font></th> </tr> <? $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$phone"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$mobile"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$fax"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"; ?>">E-mail</a></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td> </tr> <? ++$i; } echo "</table>"; ?> I got this code
<?php // Check if session is not registered, redirect back to main page. // Put this code in first line of web page. session_start(); if (!isset($_COOKIE["user"])) { header("location:login.php"); } include 'connection.php'; ?> <html> <head> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="HandheldFriendly" content="true"> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>EBS Service Skjema</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <?php include 'menu.php'; echo "<div class=\"bluebox\">"; if (isset($_GET['sted'])) { require_once('graph/jpgraph.php'); require_once('graph/jpgraph_line.php'); include 'connection.php'; // data $sql = mysqli_query($con, "SELECT * FROM diesel WHERE sted = '".$_GET['sted']."' GROUP BY WEEK(dato)"); $ydata = array(); $ydate = array(); while($row = mysqli_fetch_array($sql)) { $ydata[]=$row['krl']; $ydate[]=$row['dato']; } // Create the graph. These two calls are always required $graph = new Graph(600,250); $graph->SetScale('textlin'); $graph->title->Set('Pris Historikk'); $graph->xaxis->title->Set("Dato"); $graph->yaxis->title->Set("Pris"); $graph->xaxis->SetTickLabels($ydate); // Create the linear plot $lineplot=new LinePlot($ydata); $lineplot->SetColor('blue'); //$lineplot->SetFillColor('orange@0.5'); // Add the plot to the graph $graph->Add($lineplot); // Display the graph $graph->Stroke(); } else { echo "Du får ikke tilgang på denne måten."; } echo "</div>"; ?> </body> </html>but I get headers allready sent. I was earlier told to learn and code or make my apps different, but I'm totaly stuck cause I need to make a page with those stats. Not sure how I can make all my code be processed first then put into the html area. Is a function the way to go here ? Thanks for reading and hope someone can enlighten me HI there, i'm using a flash and php form. The problem lie in the PHP I only seem to get the field titles (Name and telephone) coming through and not the data they contain. Could somebody tell me what i'm doing wrong? <?php $sendTo = "myemail@gmail.com"; $subject = "An enquiry"; $headers = "From: " . $_POST["firstName"] ." ". $_POST["lastname"] . "<" . $_POST["email"] .">\r\n"; $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; $headers .= "Return-path: " . $_POST["email"]; $message = "telephone: ".$strtelephone."\r\n"; $message .= "message: ".$strmessage."\r\n"; mail($sendTo, $subject, $message, $headers); ?> thank you Hello I've registered here last March and I'm just lurking around reading threads about php. Yesterday I've started to self studied php and today I've test some basic codes and I'm having difficulties on creating a table rows and columns. Here's my code. Code: [Select] <?php echo "<table width=\"100\" border=\"1\">"; $text = 'php'; $mac_var = 1; $mac_plus = 4; while ($mac_var < $mac_plus) { echo "<tr>"; { while ($mac_var < $mac_plus) { echo "<td>". $text . "</td>"; $mac_var++; } } echo "</tr>"; $mac_var++; } echo "</table>"; ?> what I want is, it should have 3 columns and 3 rows. But I'm getting only 3 columns and 1 row only. I wonder what is the problem? Sorry for my ignorance as I'm on the 1st basic phase of using php codes. TIA! Ok i have been working on this for a day+ now. here is my delema simple .ini text file. when a user makes a change (via html form) it makes the correct adjustments. problem is the newline issue 1. if i put a "\n" at the end (when using fputs) works great, except everytime they edit the file it keeps adding a new line (i.e. 10 edits there are now 10 blank lines!!!!) 2. if i leave off the "\n" it appends the next "fgets" to that lilne making a mess Code: [Select] ##-- Loop thruoght the ORIGINAL file while( ! feof($old)) { ##-- Get a line of text $aline = fgets($old); ##-- We only need to check for "=" if(strpos($aline,"=") > 0 ) { ##-- Write NEW data to tmp file fputs($tmp,$info[$i]." = ".$rslt[$i]."\n"); $i++; } ##-- No Match else { fputs($tmp,$aline."\n"); }//Checking for match }//while eof(old) what in the world is making this such a big deal. i dont remember having this issue in the past I tried opening with w+, and just w on the temp file a typical text line would be some fieldname = some value the scipt cycles through the file ignoring comments that are "#" ps the tmp file will overwrite the origianl once complete all i really want to know is WHY i cant get the newline to work, and what is the suggested fix EDIT: i just tried PHP_EOL and it still appends another newline SQL error2.Cannot add or update a child row: a foreign key constraint fails (`facility`.`fapplication`, CONSTRAINT `fapplication_ibfk_1` FOREIGN KEY (`fstaffid`) REFERENCES `fstaff` (`fstaffid`)) is there any solution for this problem cause my deadline is next week aaaaa... I'm really fond of your coding and need some help too I'm also trying to make a tree and save it in an xml file such that parent_id of one node is inserted in as pages key to the father node.By running this query $sql = "Select * from category order by parent_id ASC"; I'm getting the following result. Array ( => Array ( [category_id] => 2 [parent_id] => 0 [category_name] => Clothes ) [1] => Array ( [category_id] => 5 [parent_id] => 1 [category_name] => T-shirts ) [2] => Array ( [category_id] => 6 [parent_id] => 1 [category_name] => Cotton-Shirts ) [3] => Array ( [category_id] => 1 [parent_id] => 2 [category_name] => Upper ) [4] => Array ( [category_id] => 4 [parent_id] => 2 [category_name] => Lower ) [5] => Array ( [category_id] => 3 [parent_id] => 4 [category_name] => Pants ) ) My code is as follows but not executing correctly function searchTree($arr,$node,$i){ if(!in_array($node['parent_id'],$arr[$i])) { $stmt = '<pages_'.$i.'>'; $stmt .=$node; $stmt .='</pages_'.$i.'>'; return $stmt;} else{ //print_r($returnTree); print_r ($arr[$i]);//['category_id']; $returnTree = ($arr[$i]['category_id']==$node['parent_id'])? searchTree($arr,$node,$i++): searchTree($arr,'',$i++); } } $i=0; foreach($links as $link){ $myArr = searchTree($links,$link,$i);} The result should be as follows: <page_1> <label>Clothes</label> <uri>#</uri> <pages> <page_1_1> <label>Upper</label> <uri>#</uri> <pages> <label>T-Shirt</label> <uri>#</uri> <page_1_1> <page_1_1_1> <label>Short Sleaves</label> <uri>#</uri> </page_1_1_1> <page_1_1_2><label>Long Sleaves</label><uri>#</uri> </page_1_1_2></page_1_1></page_1> <page_1_2> <label>Lower</label> <uri>#</uri> <pages>....</page_1_2> Hopefully you can unsderstand this problem. Please help me. Hi, I am having trouble with some GIF, PNG images the error I am receiving these errors imagecreatefromgif() [function.imagecreatefromgif]: '/tmp/phpNAhLPI' is not a valid GIF and a similar one for PNG Is there a solution to this? and How can I hide these errors? So they never display to the user and Instead I echo a user friendly error. Please note again this is happening with some GIF and PNGs not all of them. Appreciate any help and thanks in advance! Ok I have a form that will include some text boxes and two sliders where numbers can be selected. When a user clicks submit I want it to take them to a solutions page based on what numbers they have selected. I'm finding it hard to explain what I'm trying to do so heres an example of what I would like. http://www.cleardebt.co.uk/#help It will be a form like that which links to a solution. If someone could please tell me what I need to do or have a tutorial of something similar it would be a great help for me to start. |