Jump to content

mydownfall00

Members
  • Posts

    29
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

mydownfall00's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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..
×
×
  • 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.