
1acid
Members-
Posts
14 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
1acid's Achievements

Newbie (1/5)
0
Reputation
-
You sir are my hero!!! IT WORKS!!!
-
Hi I am making a sign in page for a simple web app. I have user data entered into my DB already that you could use to sign in. here is my code <?php session_start(); include("functions.php"); include("config.php"); include("connect.php"); $error=array(); if(isset($_POST['signin'])) { if(empty($_POST['username'])) { $error['username'] = "Username PLZ!"; } if(empty($_POST['password'])) { $error['password'] = "PSWD PLEASE!"; } if(count($error)==0) { $cleanData =sanitize_array($_POST); $pswd = md5($cleanData['password']); $sqlStr = "SELECT id FROM calcuser WHERE username='{$cleanData['username']}'AND password='{$pswd}'"; $result = mysql_fetch_array(mysql_query($sqlStr)); if($result) { $_SESSION['$user_id']= $result['id']; redirect("index.php"); } else { $error['combi'] ="Password/username do not match records"; } } } ?> and this is my code on the redirect page that should be getting the userid from the DB and matching it with the session id user_id session_start(); include("functions.php"); include("config.php"); include("connect.php"); if(!isset($_SESSION['user_id'])) { redirect("signin.php"); } $sqlStr = "SELECT id, name, username FROM calcuser WHERE id='{$_SESSION['user_id']}'"; $row =(mysql_fetch_assoc(mysql_query($sqlStr))); its not taking me to the index page, which to me means there is something wrong with either the sql query to get the user id from the DB Any help would be greatly appreciated. Im pretty newb at all this. Thanks(Man i hope these code brackets worked!!)
-
newb needs help please -trying to make a calculator
1acid replied to 1acid's topic in PHP Coding Help
Thanks for the help guys, it was the fact that i never set up a DB connection anywhere. It inserted a user into the DB now, so getting kinda late here, will call it a night and work on my sign in page tomorw. Thanks again for all the help!! Peace -
newb needs help please -trying to make a calculator
1acid replied to 1acid's topic in PHP Coding Help
I think i just realise imnot connecting to my DB anywhere more facepalm sorry -
newb needs help please -trying to make a calculator
1acid replied to 1acid's topic in PHP Coding Help
faepalm -
newb needs help please -trying to make a calculator
1acid replied to 1acid's topic in PHP Coding Help
ok sorry about the thing will try do better from here on in heres what it said when i echo'd the sqlStr out: INSERT INTO calcuser(name, surname, username, password)VALUES('xyz','abc','user1','c53e479b03b3220d3d56da88c4cace20') That looks correct to me? am i missing something? Thanks -
newb needs help please -trying to make a calculator
1acid replied to 1acid's topic in PHP Coding Help
BTW sanitize is another function i created thats just cleaning the input: looks like this, also tried and tested without issues. function sanitize($value){ //this will take in a string clean it using the mysql_real_escape_String and return the cleaned string return mysql_real_escape_string($value); } function sanitize_array($array)//this cleans an array { foreach($array as $key=>$value) { $array[$key] = sanitize($value); } return $array; } I jsut realised i wasnt using the array one, and changed it in my code... -
newb needs help please -trying to make a calculator
1acid replied to 1acid's topic in PHP Coding Help
ok so i need to be using this sessions thing to hold the data when the pge reoads? okim gonna try fiddle with that abit. I have written a insert qry that is meant to let a user sign up, but the data is not being inserted into the database ,could you guys perhaps look at my query and let me know where its going wrong. The table is called calcuser the fields are name, surname, username and password here is the code, 1st im validating that the fields are complete and that the passwords match and then it should insert it into my DB but it not, its getting into the final if statement as it is unsetting the data and redirecting to my index page but the user data is not in the DB. Any hep again would be greatly appreaciated. Thanks here's the code [ $error=array(); if(isset($_POST['submit'])) { if(empty($_POST['name'])) { $error['name'] = "Please enter a name"; } if(empty($_POST['surname'])) { $error['surname'] = "Do you have a surname?"; } if(empty($_POST['username'])) { $error['username'] = "Please enter a username"; } if(empty($_POST['password'])) { $error['password'] = "Please enter a password"; } else if(!preg_match("/^.*(?=.{6,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=).*$/", $_POST['password'])){ $error['password'] = "Password not valid!"; } if(empty($_POST['password2'])) { $error['password2'] = "Please confirm your password"; } elseif($_POST['password']!=$_POST['password2']) { $error['password'] = "Your Passwords do not match"; } if(count($error)==0) { $cleanData = sanitize($_POST); $encrypted = md5($_POST['password']); $sqlStr = "INSERT INTO calcuser(name, surname, username, password)". "VALUES('{$cleanData['name']}','{$cleanData['surname']}','{$cleanData['username']}','{$encrypted}')"; mysql_query($sqlStr); unset($_POST); redirect("index.php"); } } ] error() is a function i made to display the errors : it looks like this and works on other pages i made: function error($name){ //this is checking if any value was assinged to the error global $error; if(isset($error[$name])){//checks if there is a value set in the array of error echo $error[$name]; //if there is a value set in the array it will display the error msg } } Thanks again -
newb needs help please -trying to make a calculator
1acid replied to 1acid's topic in PHP Coding Help
ok so when u say the page needs to reload thats fine, this is just a test and im tryna just practise some stuff and just now ill be adding a sign up page and log in page just for practise. So.. How would I make it add to my string when i push a number for the second time? Thanks again -
newb needs help please -trying to make a calculator
1acid replied to 1acid's topic in PHP Coding Help
Ummm is there anyway to do this with just normal HTML or is Javascript the only option? Surely with PHP each time a button is pushed it can update the textbox and remeber the value? I really havnt studied any javascript and ive just finished a PHP course so I was just trying to practice some of the simpler stuff I had learn't and implement it in a basic calculator... anyways thanks for the help guys, any other tips would be greatly appreciated. Thanks again! -
Ok so Im trying to make a calculator and IM kinda stuck. I have a standard keypad with buttons 0-9 and then +-/* plus a few other things i will figure out later I want to be able to let the user enter in a string of numbers and display that in the text box which I will later let the user input a number into, but for now im trying to get the the value from the button that was pushed and add it to a string which would have been stored with any previous numbers that the user pushed. So at the moment it will display a single digit in the textbox but it wont remeber that digit and then display the next digit pushed ie if the user wants to enter 12 he first pushes 1 then it needs to hold one and display the second value entered on the right hand side of that digit, and so forth. LEt me know what im doing wrong. I was thinking of maybe writing a function to check what was pushed but im not 100% sure how to do that and dont just want to get lost, so if someone could maybe with the theory of behind how im going to store the digits, I dont want it to be super calulated just able to maybe do like 134 + 26 = 160 simple math for now. Thanks for any help, just let me know where im making mistakes, and how i can do things better. thanks again So i have my basic HTML layout like this: <html> <head> <title>My Calcâ„¢</title> <link type="text/css" rel="stylesheet" href="styles.css"/> <?php ?> </head> <body> <div id=wrapper> <h2>Craigs Calculaterâ„¢</h2> <h3>Go on, make a calculation</h3> <form method="POST" id="form1"> <table name="table1" id="table"> <tr> <td><input type="submit" name="value" value="1"/></td> <td><input type="submit" name="value" value="2"/></td> <td><input type="submit" name="value" value="3"/></td> <td><input type="submit" name="calc" value=" +/- "/></td> </tr> <tr> <td><input type="submit" name="value" value="4"/></td> <td><input type="submit" name="value" value="5"/></td> <td><input type="submit" name="value" value="6"/></td> <td><input type="submit" name="value" value="0"/></td> </tr> <tr> <td><input type="submit" name="value" value="7"/></td> <td><input type="submit" name="value" value="8"/></td> <td><input type="submit" name="value" value="9"/></td> <td><input type="submit" name="calc" value=" clr "/></td> </tr> <tr> <td><input type="submit" name="calc" value="+"/></td> <td><input type="submit" name="calc" value="-"/></td> <td><input type="submit" name="calc" value="X"/></td> <td><input type="submit" name="calc" value="/"/></td> </tr> </table> <input type="text" name="box" value="<?php global $storeNum; echo $storeNum;?>" placeholder=" Wazzup Homie?"/> <br/> <br/> <input type="submit" name="calc" value="Calculate"/> <br/> <br/> </form> <div> </body> </html> -------------- OK and here's the stylesheet: #form1{background:#ccccff;width:400px;margin-left:270px;border: solid #3366ff;border-radius:15px;box-shadow:3px 3px 1px #333;} body{background:#99ccff;} h2{text-shadow: black 0.1em 0.1em 0.2em; color:#330033} h3{text-shadow: 0 0 0.2em #87F, 0 0 0.2em #00ccff;, 0 0 0.2em #ffff00; color:#330033;} #wrapper{width:960px; background:#9999ff;text-align:center; float:center; margin-left:150px; padding:10px;margin-top:5px;border: solid 2px #6600cc;height:600px;border-radius:15px;box-shadow:3px 3px 1px #333;} #table{float:center;border:#6600cc;padding:5px;margin-left:125px; } input{background:#6699cc; color:#000;border-radius:7px;box-shadow:2px 2px 1px #666;} input:hover{background:#660066; color:#fff;} --------- and then this is the switch statement i was using to get the value of the submitted button. switch($_POST['value']) { case '1': global $storeNum; $temp = $storeNum; $newNum = $temp.'1'; $storeNum = $newNum; break; case '2': global $storeNum; $temp = $storeNum; $newNum = $temp.'2'; $storeNum = $newNum; break; case '3': global $storeNum; $temp = $storeNum; $newNum = $temp.'3'; $storeNum = $newNum; break; case '4': global $storeNum; $temp = $storeNum; $newNum = "$temp".'4'; $storeNum = $newNum; break; case '5': global $storeNum; $temp = $storeNum; $newNum = "$temp".'5'; $storeNum = $newNum; break; case '6': global $storeNum; $temp = $storeNum; $newNum = "$temp".'6'; $storeNum = $newNum; break; case '7': global $storeNum; $temp = $storeNum; $newNum = "$temp".'7'; $storeNum = $newNum; break; case '8': global $storeNum; $temp = $storeNum; $newNum = "$temp".'8'; $storeNum = $newNum; break; case '9': global $storeNum; $temp = $storeNum; $newNum = "$temp".'9'; $storeNum = $newNum; break; case '0': global $storeNum; $temp = $storeNum; $newNum = "$temp".'0'; $storeNum = $newNum; break; }
-
ok, so where i have this <form method ="post" action=""> should i be naming this form post? Im sorry im kinda new and tryna wrap my head around all of this. thanks for the reply again. OTherwise how would I make post exist in my $_POST array? Thanks
-
Thanks for the reply, that has removed the connect error message but now when i click the submit button it doesnt actually dd the data to the data base? Could you or anyone assist me with that maybe? Thanks again
-
Hi there, I am new, like fresh meat new if anyone minds helping me, Id really appreciate it. I had a look around for a few similar thread i pinged my localhost through command promt and everything was fine(as far as Im aware) so the error im getting is : Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\Program Files\EasyPHP-12.0\www\init.php on line 5 Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in D:\Program Files\EasyPHP-12.0\www\init.php on line 5 The file init.php contains the following code: <?php include_once('config.php'); mysql_connect('DB_HOST', 'DB_USER', 'DB_PASS'); mysql_select_db('DB_NAME'); ?> the file config.php contains the following code: <?php $config["DB_HOST"] = 'localhost'; $config["DB_HOST"] = 'root'; $config["DB_PASS"] = ''; $config["db_NAME"] = 'craig'; ?> This is my actual file that is meant to add data to my database: <?php include_once('init.php'); if(isset($_POST['title'],$_POST['post'])){ mysql_query("INSERT INTO posts SET title = '{$_POST['title']}', contents = '{$_POST['post']}'"); } ?> <!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> <style type="text/css"> label{display:black;} </style> </head> <body> <div id ="main"> <form method ="post" action=""> <div> <label for="title"><br/>Title</lable> <input type ="text" name="title" id="title"/> </div> <div> <lable for="post"><br/>Post</label> <textarea name ="text" id="post" rows="15" cols="50"></textarea> </div> <div> <input type="submit" value="Post"/> </div> </form> </div> </body> </html> Am i being stupid? Im not very experienced with this stuff and im trying to follow along to a youtube series and learn a bit more. please any help is greatly appreaciated. Thanks 1acid