yogibear
Members-
Posts
58 -
Joined
-
Last visited
Never
Everything posted by yogibear
-
Hi I have been trying to backup one of my tables using this code and it works however when i tried restoring the table using phpmyadmin i got an error on line 1. i believe the problem is lines terminated is ; and so is fields terminated when i export using phpmyadmin i can set what i what them to be how can i change lines terminated in the code to be : rather than ; without changing field terminated. $out = ''; // Get all fields names in table "name_list" in database "tutorial". $fields = mysql_list_fields($database,$table); // Count the table fields and put the value into $columns. $columns = mysql_num_fields($fields); // Add all values in the table to $out. while ($l = mysql_fetch_array($result)) { for ($i = 0; $i < $columns; $i++) { $out .='"'.$l["$i"].'";'; } $out .="\n"; } this is the export uing phpmyadmin "test";"test";"test";"test";"test";"test";"test";"2007-10-07";"2007-11-07";"0";"0";"2007-12-09";"0";"testt";"t";"test": this is the export using the code on my website "test";"test";"test";"test";"test";"test";"test";"2007-10-07";"2007-11-07";"0";"0";"2007-12-09";"0";"testt";"t";"test";
-
Hi thanks for your help works perfectly now many thanks yogi
-
Hi everyone quick question about adding the date to a file name this is what i have so far $date = date("Y/m/d"); // Open file 'backup.csv'. $f = fopen ('backup.csv','w'); // Put all values from $out to backup.csv. fputs($f, $out); fclose($f); header('Content-type: application/csv'); header('Content-Disposition: attachment; filename="backup.csv"'); readfile('backup.csv'); ?> I have tried a few things but got so many errors I thought I would remove them and ask for help before the whole thing stopped working. Many thanks yogi
-
Hi thank you so much, its so simple when you know how
-
Hi all I’m not total new to php but I still don’t understand a lot of php things so please go easy. I have 3 fields from a database going into a table. username, car and credits and a rank column the table is ordered by the total of 3 different fields in the database. I want the rank column to start at 1 for row 1, and 2 for row 2 and so on. I have tried some things that i found in another post but couldnt get them to work so I removed it. Rank Username Car Credits 1 qwert ford 100 2 test renault 50 this is the code i have <?php $con = mysql_connect("localhost","***","***"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM userinformation ORDER by credits + original + totalspent DESC"); echo "<table border='1'> <tr> <th>Rank</th> <th>Username</th> <th>Car</th> <th>Credits</th> </tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>". $row['rank'] . "</td>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['car'] . "</td>"; echo "<td>" . $row['credits'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> I hope someone can help thanks in advanced yogi
-
Hi everyone I wasn’t sure were to put this post so please move if necessary. I have just finished the first half of my site when I thought if a user could change cookies or the contents cookies this would be a huge hack the cookies don’t contain any passwords or anything like that but a user being able to change cookies could give this user and advantage over other users. I know that cookies are client side but is the client able to change cookies some how and would using sessions solve the problem if there is one. Many thanks Yogi
-
works great thanks for your help
-
Hi now im getting an error Parse error: syntax error, unexpected $end in /home/sites/bf2c.co.uk/public_html/orderexhaust.php on line 27 This is all the code <? // You may copy this PHP section to the top of file which needs to access after login. session_start(); // Use session variable on this page. This function must put on the top of page. if(!session_is_registered("username")){ // if session variable "username" does not exist. header("location:index.php"); // Re-direct to index.php } $con = mysql_connect('localhost','***','***'); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM userinformation WHERE username='yogibear'"); while($row = mysql_fetch_array($result)) $a = $row['credits']; $b = 5000; $c = $a + $b; mysql_query("UPDATE userinformation SET credits = $c WHERE username = '". $_SESSION['username']."'); mysql_close($con); ?> Thanks for your help
-
Hi thanks for your fast reply, I thought everything was working when I got no error but then I noticed that it has stopped the calculation from working. This is all my work in progress code <? // You may copy this PHP section to the top of file which needs to access after login. session_start(); // Use session variable on this page. This function must put on the top of page. if(!session_is_registered("username")){ // if session variable "username" does not exist. header("location:index.php"); // Re-direct to index.php } $con = mysql_connect('localhost','***','***'); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM userinformation WHERE username='yogibear'"); while($row = mysql_fetch_array($result)) $a = $row['credits']; $b = 5000; $c = $a + $b; mysql_query("UPDATE userinformation SET credits = $c WHERE username = ". $_SESSION['username']"); mysql_close($con); ?> [code] The code is meant to take credits and add 5000 to it and then replace the original amount of credits with the total, but it doesn’t, it does when ". $_SESSION['username']"); is replaced with 'yogibear'"); Any ideas Thanks [/code]
-
Hi all I am quite new to php and am having a little problem with sessions. when a user logs in there username becomes a session and every page checks this session this all works fine, which is great but I would like it to search the database for this username this is part of the code that i have. this is the error I am getting sorry if i have not been clear, I hope you can help, thanks in advanced yogi
-
I was hoping it would be something different, cause im getting the same problem
-
do i just replace addslashes with mysql_real_escape_string
-
Hi i cant get your code to work it keeps saying "Unknown column 'test' in 'where clause'" the test is what i typed into the username textbox this is my code <?php if(isset($_POST['submit'])){ $dbHost = "localhost"; //Location Of Database usually its localhost $dbUser = "***"; //Database User Name $dbPass = "***"; //Database Password $dbDatabase = "***"; //Database Name $db = mysql_connect("$dbHost","$dbUser","$dbPass")or die("Error connecting to database."); //Connect to the databasse mysql_select_db("$dbDatabase", $db)or die("Couldn't select the database."); //Selects the database /* The Above code can be in a different file, then you can place include'filename.php'; instead. */ //Lets search the databse for the user name and password $sql = mysql_query("SELECT * FROM userinformation WHERE username=".addslashes($_POST['username'])." AND password=".addslashes($_POST['password'])." LIMIT 1")or die(mysql_error()); //Search for a row $row = mysql_fetch_array($sql); if($row){ //If there is a row start a session with values, then transfer to the users page session_start(); $_SESSION['username'] = $row['username']; $_SESSION['fname'] = $row['first_name']; $_SESSION['lname'] = $row['last_name']; $_SESSION['logged'] = 1; header("Location: users_page.php"); }else{ //If there isn't a row return the user to a login page header("Location: login_page.php"); } }else{ //If the form button wasn't submitted go to the index page header("Location: index.php"); } ?> any ideas whats wrong many thanks yogi
-
Hi still getting the same <?php // Connects to your Database mysql_connect("localhost", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM userinformation WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } // now we insert it into the database $insert="INSERT INTO userinformation (username, password) VALUES ('$_POST[username]','$_POST[pass]')"; $add_member = mysql_query($insert); ?> <!-- Now we let them know if their registration was successful --> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> <?php } else { ?> <!-- This is what they see before they have registered --> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="60"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>Confirm Password:</td><td> <input type="password" name="pass2" maxlength="10"> </td></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form> <?php } ?> This all seems to work fine but i am still get the Incorrect password, please try again. when i try to login thanks for your help yogi
-
well that sounds very complicated I think this login may be more than I need. Can any one recommend more simple version. many thanks
-
Hi all I found this login and thought it would be perfect for my site http://php.about.com/od/finishedphp1/ss/php_login_code_5.htm however its a little more advanced than i am used to and its not working right it keeps saying Incorrect password, please try again. when the password is correct all the validation works and it checks the username fine. <?php $host="localhost"; // Host name $username="***"; // Mysql username $password="***"; // Mysql password $db_name="***"; // Database name $tbl_name="userinformation"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM userinformation WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM userinformation WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: members.php"); } } } else { // if they are not logged in ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> any ideas what the problem many thanks yogi
-
[quote author=jesirose link=topic=124160.msg514101#msg514101 date=1169830799] instead of echo, use header('Location: '.$newURL); [/quote] Works perfectly Many thanks
-
Hi my php is all working and everything is going well thanks to everyone that has helped me. ;D Just to make things look better how would i change an if statement so rather than displaying text it goes to a new page on the site. this is the current if statement [code] if ($num_rows > 0) { echo "ALREADY IN DATABASE"; } else { echo "Working!"; } [/code] many thanks yogi
-
[quote author=jesirose link=topic=123684.msg511617#msg511617 date=1169580331] [quote author=yogibear link=topic=123684.msg511611#msg511611 date=1169579981] [quote author=jesirose link=topic=123684.msg511609#msg511609 date=1169579762] if ($num_rows => 0) { => is syntax for assigning array values. You want >= [/quote] I'm still getting the same error thanks yogi [/quote] Actually, I think you'd just want > - you don't want it to go if it's 0, just if it's > 0 [/quote] IT WORKS THANK YOU ;D simcoweb got it going but it always said it was in the database. jesirose fixed the last problem many thanks everyone
-
[quote author=jesirose link=topic=123684.msg511609#msg511609 date=1169579762] if ($num_rows => 0) { => is syntax for assigning array values. You want >= [/quote] I'm still getting the same error thanks yogi
-
Hi this is my code i have no idea about it i have changed removed and added bits and now im lost with it. [code]<?php $con = mysql_connect('localhost','***','***'); mysql_select_db("web22-james"); if (!$con) { die("Connection failed."); }else{ $username = $_POST['username']; $email = $_POST['email']; $pword1 = $_POST['pword1']; $pword2 = $_POST['pword2']; $query = "SELECT * FROM usersinformation WHERE username='$username' LIMIT 1"; $result = mysql_query($query) or die("Problem with the query:<pre>$query</pre><br>" . mysql_error()); $num_rows = mysql_num_rows($result); if ($num_rows => 0) { echo "Our database shows this username has already been registered. Please choose another username."; } else { echo "$results"; } mysql_close(); ?>[/code] this is the html form [code]<form action="registerconfirm.php" method="POST"> Username: <input type="text" name="username" maxlength="16" /><br> E-mail: <input type="text" name="email" /><br> Password: <input type="text" name="pword1"><br> Password (again): <input type="text" name="pword2"><br> <input type="submit" value="Register"> </form>[/code] when i click submit it says Parse error: syntax error, unexpected $end in /home/sites/***/public_html/registerconfirm.php on line 25
-
This is the code [code]<?php $con = mysql_connect('localhost','***','***'); if (!$con) { die("Connection failed."); }else{ $username = $_POST['username']; $email = $_POST['email']; $pword1 = $_POST['pword1']; $pword2 = $_POST['pword2']; $query = "SELECT * FROM usersinformation WHERE username='$username' LIMIT 1"; // check if username already $result = mysql_query($query); if(0 != mysql_num_rows($result)) { echo "Our database shows this username has already been registered. Please choose another username."; } else { echo "WORKING!"; } mysql_close(); } ?> [/code] Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/sites/***/public_html/registerconfirm.php on line 14 Many thanks yogi
-
[quote author=jesirose link=topic=123684.msg511547#msg511547 date=1169576103] This is why you don't just copy and paste code without understanding it. [b] isn't php, that's a bold tag. Take that stuff out, and in the future POST the error, not just that you got one. [/quote] hi i did post the error it was in my second post and i also tried it with and without the bold tag i didnt just Copy and Paste but that is why people get help because they dont understand thanks for help
-
hi im getting a error on line 14 now [code] <?php $con = mysql_connect('localhost','***','***'); if (!$con) { die("Connection failed."); }else{ $username = $_POST['username']; $email = $_POST['email']; $pword1 = $_POST['pword1']; $pword2 = $_POST['pword2']; $query = "SELECT * FROM usersinformation WHERE username='$username' LIMIT 1"; // check if username already $result = mysql_query($query); if(0 != mysql_num_rows($result)) [b]{[/b] echo "Our database shows this username has already been registered. Please choose another username."; } else { echo "WORKING!"; } mysql_close(); } ?> [/code]
-
Hi this is the error Parse error: syntax error, unexpected T_ELSE in /home/sites/***/public_html/registerconfirm.php on line 16 many thanks yogibear