-
Posts
397 -
Joined
-
Last visited
Posts posted by Nodral
-
-
Really straightforward.
Set up your db table (data) with a column called ip_addresses
Then retrieve them all and populate array
$sql="SELECT ip_addresses FROM data"; $sql=mysql_query($sql); while($row=mysql_fetch_array($sql)){ $ip_array[]=$row['ip_addresses']; }
You now have an array containing all allowed ip addresses. ($ip_array)
Now if you run a test
if(in_array($user_ip)){ echo"IP is fine"; } else { echo"get lost!!!" }
-
Hi
In php ' ' and " " do have a very subtle difference.
if you were to use the following
$output="Hello World"; echo "I want to say $output";
You would see
I want to say Hello World
However if you put
$output="Hello World"; echo 'I want to say $output';
You would see
I want to say $output
Also you can mix and match to output SQL or HTML
eg
$output='<div class="test">Hello World</div>";
or
$sql="INSERT INTO table SET VALUES column1='data'";
Hope this helps!!
-
echo"</br>Your Average is $average";
Don't worry AkKay47, I won't get him to put that in an array!!! lol
-
should work but is more work than needs to be done here
There's no "should" should about it.
It does work lol
-
Try this
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Week 1 Lab</title> </head> <body> <?php if (isset($_POST['btn_submit'])) { $number_of_rows = $_POST['number_of_rows']; echo "<table cellpadding='10' cellspacing='10' border='1'"; echo "<tr>"; for($ii = 0; $ii < $number_of_rows; $ii++) { echo "<tr>"; for ($i=0; $i<$number_of_rows; $i++) { $my_no = mt_rand(1, 100); $average_calc[]=$my_no; if (($my_no%2==0)&&($my_no%3==0)) { $color="#FF00FF"; } else if ($my_no%2==0) { $color="#0000FF"; } else if ($my_no%3==0) { $color="#FF0000"; } else { $color ="#FFFFFF"; } echo "<td style=\"background: {$color};\">$my_no</td>"; } echo "</tr>"; } echo "</table>"; } $total=array_sum($average_calc); $count=count($average_calc); $average=$total/$count; ?> <form name="lab1" method="post" action=""> <input type="textbox" name="number_of_rows" value="5" /> <input type="submit" name="btn_submit" value="Generate Grid" /> <?php echo $average; ?> </form> </body> </html>
I've added in
line 16 to create an array
Lines 37 - 39 to calculate the average
Lines 45 - 47 to print on screen
-
Hi
Every time your script generates a number, get it to allocate into an array (eg $average_calc), then use the following.
$total=array_sum($average_calc);
$count=array_count($average_calc);
$average=$total/$count;
-
You could try
$username = mysqli_real_escape_string($dbc, $_POST['username']); $password = mysqli_real_escape_string($dbc, $_POST['password']);
In the php manual, there is no requirement for the set of brackets around the string you are converting.
Sorry if this is wrong, but I'm not really that experienced with mysqli
-
Using mysql
Set up a file called connect.php with the following.
<?php $link = mysql_connect('localhost', 'username', 'password'); if (!$link) { echo'1Unable to connect to the database server.'; exit(); } if (!mysql_set_charset('utf8', $link)) { echo'2Unable to connect to the database server.'; exit(); } if(!mysql_select_db('db-name', $link)) { echo'3Unable to connect to the database server.'; exit(); } ?>
Then use include_once('connect.php'); at the start of every script requiring a DB connection.
Then when using try using $username=mysql_real_escape_string($_POST['username'];
Note there is no link or connection identifyer in the brackets.
-
I was in a similar situation where I was using mysqli in dev and mysql in prod and this caused me no end of issues as the commands are different, sometimes subtly and sometimes quite obviously.
I'd ask your host to use whatever you are using n dev as this will save you loads of time in debugging, alternatively you use the same in dev as you are using in live.
What error did you get in prod when you used mysql_real_escape_string?
-
My advice is to save yourself hours of dev work and look for a pre-built mail script.
I use Rmail which can be found from Google and this lets you send all sorts of emails simply by setting a few variables and then using an include.
-
Hi
In your first bit of info about yourself, you quote you are using MySQL in dev and then mysql in prod.
You then point out an error with mysqli. Which are you using and have you changed at all?
Does your connect statement work ok? Have you tested that?
-
All you do is put a line in submitAction.php which would process the variable and assign it.
eg. if your $_POST variable was called test. you do the following.
$_SESSION['test']=$_POST['test'];
Then provided you have declared session_start(); at the beginning of every script, you can use $_SESSION['test'] in every script after it has been set.
-
Generally I use long tags anyway. It was the way I was taught
This was probably just a typo
-
Someone else may want to jump in on this now, I'm not that hot on the echo vs print situation
-
Sorted
I had a short opening tag earlier in the code.
Php 5.3 hates these!!! lol
-
Hi all
I had this working in a dev environment with php 5.2.13, however I have moved it into live which used php 5.3.6 and I'm having issues with my elseif statement.
<?php //has user agreed to have admin account? If confirm has not yet been set........... if(!isset($_POST['confirm'])){ include('header.php'); unset($_SESSION['dbsecure']); echo'<div class="pagetext">You are the first to use this application.<br>Would you like to be set up as the main admin user?<br></div> <form method="POST" action=""> <input type="submit" name="confirm" value="Yes"><input type="submit" name="confirm" value="No"> </form>'; //if confirm is set, has form been completed? } elseif(isset($_POST['change'])){ //if form is completed are all variables set? if(isset($ED, $password, $firstname, $lastname, $email, $dept, $workplace, $home, $role)){ //create table $sql="CREATE TABLE pfp_user (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, ed VARCHAR(255) NOT NULL, firstname VARCHAR(255) NOT NULL, lastname VARCHAR(255) NOT NULL, dept VARCHAR(255), workplace VARCHAR(255), home VARCHAR(255), password VARCHAR(255), email VARCHAR(255), role VARCHAR(255) NOT NULL, complete VARCHAR(255) NOT NULL, type VARCHAR(255)) DEFAULT CHARACTER SET utf8"; mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); //hash password $password=md5($password); //insert data $sql="INSERT INTO pfp_user (ED, firstname, lastname, dept, workplace, home, password, email, role, complete, type) VALUES ('$ED', '$firstname', '$lastname', '$dept', '$workplace', '$home', '$password', '$email', '$role', 'Yes', 'Allocated')"; mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); $_SESSION['output']="Admin User Successfully Registered. Please log in."; $extra = 'index.php'; header("Location: http://$host$uri/$extra"); } //missing data else{ $_SESSION['output']='<div class="pagetext">You have missed some information<br>Please try again</div>'; } }
I get the following error
PHP Parse error: syntax error, unexpected '}' in /home/httpd/vhosts/client9/web14/web/devsite/pfp/config.php on line 62
Line 62 is the elseif statement. Any ideas?
-
Change the echo back to a print if you like, I just used echo for testing on a basic level
-
Here's an update,
if I use D:/Documents/AI24/Web/tmp as $filename it works. However I need this to be a relative path for my production server as I don't know the full root path
-
Using Apache, Windows XP and PHP 5.2.13
My web host is the same except for they use php 5.3.
I'm unsure how to set up read/write access on the folder, but I've never had an issue with any other folders I've created through windows
-
Sorry to bump this, but I need to resolve this final issue then I can go live with my site.
Any ideas guys?
-
Here's a daft question, how do I get a lsit of all the discussion threads I have started?
I need to refer back to one and look at some replies but can't find a way to get this.
-
ok, once more
<?php $fp = fopen('test.csv','r'); if (!$fp) {echo 'ERROR: Unable to open file.</body></html>'; exit; } $row_count = 0; while (!feof($fp)) { // this is to exclude the first row if($row_count==0){fgets($fp, 2048); //use 2048 if very long lines $row_count++;continue; } $line = fgets($fp, 2048); //use 2048 if very long lines if (!empty($line)){list ($id, $offer, $subh, $desc, $promo, $notes ) = explode('\|', $line); $output[$id]=$offer.",". $subh.",". $desc.",". $promo.",". $notes; } $fp++; } fclose($fp); $output=array_reverse($output); //template start while(list($id, $values)=each($output)){ list ($offer, $subh, $desc, $promo, $notes ) = explode (',', $values); echo"$id<center><h3>$offer</h3><h4>$subh</h4></center><p align='left'>$desc</p>Please quote Promo Code:<div align center> <b>$promo</b></div><hr>"; //template end } ?>
You should really replace split with explode for this as split is now deprecated
-
Ignore that last post!!! It's a load of rubbish!!! lol That's what happens when a phone rings 7 times while trying to write a script!!
-
try
<?php $fp = fopen('bbs.txt','r'); if (!$fp) {echo 'ERROR: Unable to open file.</body></html>'; exit;} $row_count = 0; while (!feof($fp)) { // this is to exclude the first row if($row_count==0){ fgets($fp, 2048); //use 2048 if very long lines $row_count++; continue; } $line = fgets($fp, 2048); //use 2048 if very long lines if (!empty($line)){ list ($id, $offer, $subh, $desc, $promo, $notes ) = split ('\|', $line); $output[$id]=$offer. $subh. $desc. $promo. $notes; } $fp++; } fclose($fp); $output=array_reverse($output); //template start while(list($id, $values)=each($output)){ list ($offer, $subh, $desc, $promo, $notes ) = split (',', $values); aprint"$id <center><h3>$offer</h3> <h4>$subh</h4></center> <p align='left'>$desc</p> Please quote Promo Code:<div align center> <b>$promo</b></div><hr>"; //template end } ?>
Effectively this will load the file and close it, reverse the array then output each value.
No connection, No error
in PHP Coding Help
Posted
Hi
I have just set up a hosted site and cannot connect to the MySQL DB.
I have set up the correct DB and User but it just keeps failing at the 1st attempt
My code is
All I get output is
But no error message. Any ideas?