Jump to content

mydownfall00

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by mydownfall00

  1. I am attempting to setup a profile page based on the information that the user signs up with. (I am following a video online, the code matches but he is on a local server i am using a hosted server idk if issue) On my profile.php page I am receiving the warning : Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 5 in /home/content/80/11355280/html/core/function/users.php on line 88 On my profile page I am trying to use function : user_id_from_username. This function is currently working with my login. However on profile.php <?php include 'include/widgets/tabletop.php'; if (isset($_GET['username']) === true && empty($_GET['username']) === false) { $username = $_GET['username']; $user_id = user_id_from_username($username); echo $user_id; } else { header('Location: index.php'); exit(); } include 'include/widgets/tablebot.php'; ?> On line 14 I am calling the function I created and attempting to echo out the user id. When I attempt this I receive the warning. The function is held in users.php and is included on the page. users.php 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'); } if I would put a or die at the end of the return mysql_result I get the same error but a different index. Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 12 in /home/content/80/11355280/html/core/function/users.php on line 88 Would an if ( something > 0 ) fix this and how?
  2. Hello, the problem I am having is on my register.php file. I have a file included that holds three files for me which is connect.php, users.php and general.php. If anyone is familiar with phpacademy i am following alex on video 20. In users.php is where I am having my trouble. The users.php contains a function that will INSERT INTO my database table. I have the connection included at the top of the page in init.php. The code was working 100% fine until I entered in this line of code : mysql_query("INSERT INTO `users` ($fields) VALUES ($data)"); When I attempt to echo out the data : echo "INSERT INTO `users` ($fields) VALUES ($data)"; die(); mysql_query("INSERT INTO `users` ($fields) VALUES ($data)"); It cuts out the bottom half of my webpage which is my footer. This is the full function that I am using in users.php function register_user($register_data) { array_walk($register_data, 'array_sanitize'); $register_data['pword'] = md5($register_data['pword']); $fields = '`' . implode('`, `', array_keys($register_data)) . '`'; $data = '\'' . implode('\', \'', $register_data) . '\''; mysql_query("INSERT INTO `users` ($fields) VALUES ($data)"); } I placed the echo in above mysql_query and thats when it cut my webpage out. But I dont need the echo and with this as my present code nothing is inserted into my database table. I tried `users` users and 'users' which is my table name. If there is maybe a different INSERT INTO command that I could attempt? It was working prior to me using mysql_query. As in if i echoed $fields below fields it would give me my field names and $data will show the data in the fields in the array. Array sanitize is another function from my general.php file which looks like this function array_sanitize(&$item) { $item = mysql_real_escape_string($item); } register code is on the register page. here is my php on register.php <?php if (empty($_POST) == false && empty($errors) == true) { $register_data = array( 'username' => $_POST['username'], 'pword' => $_POST['pword'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'], 'phone' => $_POST['phone'] ); register_user($register_data); // redirect // exit } else if (empty($errors) == false) { echo output_errors($errors); } ?> If you could help me try and figure this out that would be excellent. I have spent a lot of time on this so far and have learned a lot but I am stuck at the moment.
  3. I can't seem to get the session array to work. I am using a if count to make sure the password matches on the username and password. This is my login script. This page executes after typing in your username and password. $db_name="wcdmembers"; $tbl_name="members"; mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); $wcdname=mysql_real_escape_string($_POST['wcdname']); $pword=mysql_real_escape_string($_POST['pword']); $sql="SELECT * FROM $tbl_name WHERE wcdname='$wcdname' and pword='$pword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $_SESSION['wcdname'] = 'wcdname'; $_SESSION['pword'] = 'pword'; } else { echo "Wrong Username or Password. <a href=index.html>Try Again</a>"; } $sql="SELECT * FROM $tbl_name"; $result1=mysql_query($sql); while ($row = mysql_fetch_array($result)) { $fname= $row["fname"]; echo "Welcome <a href=myaccount.php style=color:#000000 onMouseover=showmenu(event,linkset[6]) onMouseout=delayhidemenu()>$wcdname!</a>"; } ?> <?php session_start(); $_SESSION["wcdname"] = $wcdvalue; ?> <?php echo "Today is "; echo date('l \t\h\e jS \o\f F Y') ; ?> In the code above you also see a select * from before it displays the Welcome $wcdname. I had to use the select * because I wanted to show the first name and not the username. Now im not sure on how or what to do because I want to use the username on the comments table because people can have the same first name. Unless I want to go by ID? I do have an ID auto inc set on each user in wcdmembers. ----- EDIT I created the session array after the welcome display. I attempted to put it all in the same php block but it would give me an error. Right now it will display the wcdname(username) but now the date wont appear with the 2nd php block session. I am attempting to have the user leave a comment and carrying over information to the next page. This way when they leave a comment it will recognize the username and store it in a new table. This is my current comment.php page code. Its not much because I cant get the session to start. <?php session_start() $wcdvalue = $_SESSION['wcdname']; (line 156) echo "Welcome $wcdname"; ?> This is where I get the error : Parse error: syntax error, unexpected T_VARIABLE in /home/content/80/11355280/html/comment.php on line 156
  4. Wow, I missed that. I have a good checklist of stuff now to look out for. After that I have gotten it to work. Although the header tag didnt work. It gave me an error so I took it out and put in an echo to display the wcdname. Once I did that it worked and displayed the wcdname that I have in my database and works with other users. I need to look into security in my php.
  5. Thank you again for your help. I think i did this correct as you said : $sql="SELECT * FROM $tbl_name WHERE wcdname='$wcdname' and pword='$pword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $_SESSION['wcdname'] = '$wcdname' $_SESSION['pword'] = '$pword' (line 30) header("location:login_success.php"); but im still getting an error Parse error: syntax error, unexpected T_VARIABLE in /home/content/80/11355280/html/login.php on line 30 Its been awhile since I have done php so this is why im having a hard time. I can tell already that a lot is different. Im taking many notes along the way haha.
  6. the table i have in the db is members with these rows : id primary key auto_inc wcdname pword fname lname email phone
  7. Im pretty sure that on this line of code $sql="SELECT * FROM $tbl_name WHERE username='$wcdname' and password='$pword'"; it should read $sql="SELECT * FROM $tbl_name WHERE wcdname='$wcdname' and pword='$pword'"; because I didnt have a username or password defined anywhere. when i load this script these are the errors I get : Deprecated: Function session_register() is deprecated in /home/content/80/11355280/html/login.php on line 29 Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at /home/content/80/11355280/html/login.php:10) in/home/content/80/11355280/html/login.php on line 29 Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/content/80/11355280/html/login.php:10) in/home/content/80/11355280/html/login.php on line 29 Deprecated: Function session_register() is deprecated in /home/content/80/11355280/html/login.php on line 30 Warning: Cannot modify header information - headers already sent by (output started at /home/content/80/11355280/html/login.php:10) in /home/content/80/11355280/html/login.php on line 31
  8. Hey, thanks for the quick response. Okay for the tbl_name it was a variable defined before the code I put on here. Here let me re-show it $db_name="wcdmembers"; $tbl_name="members"; mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); $wcdname=mysql_real_escape_string($_POST['wcdname']); $pword=mysql_real_escape_string($_POST['pword']); $sql="SELECT * FROM $tbl_name WHERE username='$wcdname' and password='$pword'"; $result=mysql_query($sql) or die(mysql_error()); $count=mysql_num_rows($result); if($count==1){ session_register("wcdname"); session_register("pword"); (line 30) header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> I have my connection before the dbname. This is with the code you just told me to add which is giving me a this error : Unknown column 'username' in 'where clause' On my login.html file for the form I have the username text form name as wcdname and for the password its pword.
  9. I keep running into this problem on a few of my scripts now. I am putting together a signup and login form. (i know basic stuff). I have managed to create the signup and it is inserting and displaying information from my database and table. I can successfully connect as well. The warning that I am getting is : Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/content/80/11355280/html/login.php on line 30 Line 30 is BOLD mysql_connect("$host", "$username", "$password");mysql_select_db("$db_name"); $wcdname=mysql_real_escape_string($_POST['wcdname']); $pword=mysql_real_escape_string($_POST['pword']); $sql="SELECT * FROM $tbl_name WHERE username='$wcdname' and password='$pword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("wcdname"); session_register("pword"); (line 30) header("location:login_complete.html"); } else { echo "Wrong Username or Password"; } ?> If I change anything on line 30 It gives me the same warning but jumps back to line 26. It is displaying the ELSE echo for Wrong Username and Password. However the username and password is correct. I am having the same problem on a few other scripts I am trying. I have also had a problem with the way I was connecting. Im not sure if its best to define the variables or to just make a connection without them. I dont know if that could be the reason I am getting an error as well. I am registered through godaddy. Thank you if you can help me, sorry for being a noob.
  10. Hello, My name is Brian and I am attempting to get setup and connected to mysql database. I am a little ignorant on a few things so try and bare with me. I have just purchased my domain and hosting online. I also have installed mysql server 5.0 . I am kind of lost between the difference. It's been awhile since I have worked with PHP and I purchased a book from Julie C. Meloni (Sams teach yourself PHP, MySQL and Apache). I am simply just trying to connect to my database and I cannot connect due to this issue : Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/80/11355280/html/connect.phpon line 10 Connect failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) The thing is I am not sure which host to connect to and how I would go about it. On my domains mysql I have a database and table created. I attempt to connect to it with this code : (this is line 10) <?php $mysqli = mysqli_connect("localhost", "username", "password", "databasename"); The username I am using is the username I log in with through a browser. I am not sure if this is correct or if I have to create a user on the database in order to connect. I am also not sure if I would user localhost or my domain url. I created a connect.php file and uploaded it on my server and this is the error it gives me. I use dreamweaver mx for all my hard coding. I am just not really sure on how I get started on all this so I can connect to the database. If anyone could just give me some pointers on what I am doing wrong. I don't mind helping out the person who helps me as well. I know people hate newbie's and I totally sound like a newbie. Im not that bad of a guy and I have a pretty good idea on this im just having issues right now. This is my fully php code : <?php $mysqli = mysqli_connect("localhost", "username", "password", "databasename"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }else{ printf("Host information: %s\n", mysqli_get_host_info($mysqli)); } ?> I have attempted to connect to mysql that I installed on my computer and im not able to access that as well. The only thing I attempted to change in the code is localhost to my domain url but that didnt help anything. Just a different error which is : Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2003): Can't connect to MySQL server on 'www.DOMAIN.com' (111) in /home/content/80/11355280/html/connect.php on line 10 Connect failed: Can't connect to MySQL server on 'www.DOMAIN.com' (111) Any help will be much appreciated and I am willing to help someone else anyway I can for there time and effort.
  11. I know, but it's more for the layout of my site. I try to please myself more than anybody. And yeah, I know there are tons of scripts.. i guess I just can't find one that appeals to me. And Maq, I just wasn't sure.. thanks though.
  12. Okay I guess this is where I ask them.. Lets say for my webpage I am using frames.. a top and a bottom frame. I log in through the top, and I know how to continue over a connection but would I be able to have it remember someone who logged in, to the bottom frame? Also, I need a descent tutorial where I can have someone log in with a username and password. I've found a few but I didn't like them.
  13. Wait a second.. In the table it doesnt want to store the password.. its giving me aha.. i got it..
  14. Wow, nevermind.. the comma was the problem.. :-\ i wasted time for that.. thanks anyway..
  15. myDownfall Error with query: Duplicate entry '0' for key 1 I've had this error before, i was playing with my script and trying different thigns and what i missed and i will go into the table and delete the only entry.. but it still doesn't want to work.
  16. Not sure what this is telling me : myDownfall (this is showing the connection Error with query: Column count doesn't match value count at row 1 Here is my php script.. $username=$_POST['username']; $password=$_POST['password']; $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $email=$_POST['email']; $age=$_POST['age']; $band=$_POST['band']; $description=$_POST['description']; $query = "INSERT INTO `users`(`username`, `password`, `firstname`, `lastname`, `email`, `age`, `band`, `description`) VALUES ('$username', '$password', '$firstname', '$lastname', '$email', '$age' '$band', '$descriprion')"; $result = mysql_query($query); if (!$result) { $errormessage = mysql_error(); echo "Error with query: " . $errormessage; exit(); } printf ("These values were inserted into the database - %s %s %s", $username, $firstname, $lastname); ?> here is the html side <table border="0" cellpadding="3" cellspacing="3"> <tr> <td valign="top"> <form action="add2.php" method="POST"> Username : </td> <td> <input type="text" class="forms" name="username" size="40" length="40" value="Username"><BR><BR /> </td> </tr> <tr> <td valign="top"> Password : </td> <td><input type="password" class="forms" name="password" size="40" length="40" value=""><BR> <BR> </td> </tr> <tr> <td valign="top"> First Name : </td> <td><input type="text" class="forms" name="firstname" size="40" length="40" value="First Name"><BR> <BR> </td> </tr> <tr> <td valign="top"> Lastname : </td> <td><input type="text" class="forms" name="lastname" size="40" length="40" value="Last Name"><BR> <BR> </td> </tr> <tr> <td valign="top"> Email :</td> <td><input type="text" name="email" size="40" length="40" class="forms" value="Email"><BR> <BR></td></tr> <tr> <td valign="top"> Age : </td> <td><input type="text" class="forms" name="age" size="40" length="40" value="Age"><BR> <BR> </td> </tr> <tr> <td valign="top"> Favorite Band : </td> <td><input type="text" class="forms" name="band" size="40" length="40" value="Favorite Band"><BR> <BR> </td> </tr> <tr> <td valign="top"> Description : </td> <td> <textarea cols="50" rows="8" name="description" class="forms"></textarea> <BR> <BR> </td> </tr> <tr> <td> <input type="submit" name="submit" value="Submit" class="forms"> </form> </td> </tr> </table> and just because.. here is how i have my table setup.. id int( No auto_increment primary key username varchar(25) No password int(10) No firstname varchar(20) No lastname varchar(20) No email varchar(30) No age int(3) No band varchar(20) No description varchar(250) No No is Not Null Any help with what it's doing would be cool..
  17. okay i gave it a shot with your code and I have some errors. I probably have this all wrong.. xD here are my errors Warning: fread(): supplied argument is not a valid stream resource in /home/shopceme/public_html/mydownfall/add2.php on line 46 Warning: fread(): supplied argument is not a valid stream resource in /home/shopceme/public_html/mydownfall/add2.php on line 49 Warning: fclose(): supplied argument is not a valid stream resource in /home/shopceme/public_html/mydownfall/add2.php on line 51 Error with query: Duplicate entry '0' for key 1 and here is my add2.php code.. above this is my connection which i know is working.. and the rest is how I have my table setup.. except i have an id at th beginning auto_increment.. $username=$_POST['username']; $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $email=$_POST['email']; $age=$_POST['age']; $picture=$_POST['picture']; $band=$_POST['band']; $description=$_POST['description']; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $File = preg_replace("/[&'_ ]/","",$fileName); // strip whitespace and special characters LINE 46 $data = addslashes(fread(fopen($File, "r"), filesize($File))); $fp = fopen($tmpName, 'r'); LINE 49 $content = fread($fp, filesize($tmpName)); $content = addslashes($content); LINE 51fclose($fp); $ClientID = $_POST['clientid']; $description = $_POST['description']; $query = "INSERT INTO users(username, firstname, lastname, email, age, picture, band, description) ". "VALUES ('$username', '$firstname', '$lastname', '$email', '$age', '$picture', 'band', 'description')"; $result = mysql_query($query) or die(mysql_error()); $result = mysql_query($query); if (!$result) { $errormessage = mysql_error(); echo "Error with query: " . $errormessage; exit(); } printf ("<center>These values were inserted into the database<BR><BR> <table border='0'> <tr> <td> username </td> <td>%s </td> </tr> <tr> <td> first name </td> <td>%s </td> </tr> <tr> <td> last name </td> <td>%s </td> </tr> </table>", $username, $firstname, $lastname); ?> $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; this is what im confused by, are you assinging these in the script??
  18. for the script you gave me to upload a file, is that just the script just for the upload file..? reading through the script, it seems that $file is the field for the file, in my table I named it $picture, so I would go through your code and replace the two...??? also for the query (insert into), that's going to add the rest of the values into the table correct?
  19. okay, so this may be a dumb question but i looked through previous threads and couldn't find the answer so this is why i am asking.. the other day i got my sign up form to work, now since i have it working i want to expand it and add more for the user so I want them to be able to upload a picture, however I am in the process of making the table and im not exactly sure what I should set the type for the field picture.. does it have to be a varchar and it's all done in the script? any help would be appreciated.
  20. I appreciate it but I got it to work, with the help of everyone else. thanks a lot guys, i'll be back with more questions.. don't worry.
  21. Just wondering if there is still anyone there that can help me..
  22. Man im sorry that this is so hard and i dont freakin know what's wrong because now Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'admin'@'localhost' (using password: YES) in /home/shopceme/public_html/mydownfall/add2.php on line 20 Could not connect: Access denied for user 'admin'@'localhost' (using password: YES) i think since it's saying yes that the password is working but the user I don't know why it's not working. When I just created this table.. it asked me to setup a username and a password.. which I believe would be the reason to connect to the database.. unless it's something else but there aren't that many choices especially since i think the password is right.. sorry im trying guys.. EDIT!!! also I just went and changed the password so password = yes must not mean that I have my password correct.
  23. this is how i have my connection setup.. $host="localhost"; $username="myusername"; // $password="password"; // $db_name="shopceme_mydownfall"; now the database I have created is called shopceme_mydownfall and then the table I have created inside shopceme_mydownfall is called user... so... $query = "INSERT INTO `user` i changed that.. but it wont let me connect. im not sure if i have to change anything in the settings of my server or not. (btw i made a new table so there is only username firstname lastname and email.) EDIT!!!! Okay, I get the error message on line 34: this is what line 34 consists of... $result = mysql_query($query);
  24. Okay, so the code im pretty sure is going to work except now I am having a problem with my connection and it's saying that Warning: mysql_query() [function.mysql-query]: Access denied for user 'shopceme'@'localhost' (using password: NO) in /home/shopceme/public_html/mydownfall/add2.php on line 35 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/shopceme/public_html/mydownfall/add2.php on line 35 Error with query: Access denied for user 'shopceme'@'localhost' (using password: NO) and im not exactly sure which username and password I have to use, when I create a new database through phpmyadmin it makes me create a user to login and access it. im thinking that is the one that you would have to use but it doesnt seem to be trying. im going to attempt to make a new table really quick and see what I can do incase I have the password wrong. One question though, how do I set up an auto_increment to give as a user id so say each time someone signs up they will each be given a number such as #1, #2, #3 and so on.. and how do I set that up with the html form.. or dont I even have to include it because of the auto_increment.. just checking.. i really appreciate all this help.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.