Why Is My Code Not Working - Webmasters - Nairaland
Nairaland Forum › Science/Technology › Webmasters › Why Is My Code Not Working (908 Views)
| Why Is My Code Not Working by ford705(op): 12:10pm On Jul 30, 2011 |
<?php //1. create a database connection $connection = mysql_connect("localhost", "root", "" ;if (!$connection) { die("Database connection failed:" . mysql_error()); } //2. Select a database to use $db_select = mysql_select_db("ectforu",$connection); if (!$db_select) { die("Database Selection failed: " . mysql_error()); } ?> <?php $id=$_POST['id']; $surrname=$_POST['username']; $othernames=$_POST['othernames']; $sex=$_POST['sex']; $phone=$_POST['phone']; $contactadd=$_POST['contactadd']; $emailadd=$_POST['emailadd']; $birthday=$_POST['birthday']; $philosophy=$_POST['philosophy']; $worstday=$_POST['worstday']; ?> <?php $query="INSERT INTO details (id, surname, othernames, sex, phone, contactadd, emailadd, birthday, philosophy, worstday) VALUES('{$id}', '{$surname}', '{$othernames}', '{$sex}', '{$phone}', '{$contactadd}', '{$emailadd}', '{$birthday}', '{$philosophy}', '{$worstday}')"; if(mysql_query($query, $connection)) { //sucess header("location: success.html" ;exit; } else { //error message echo "<p> insertion failed. </p>"; echo "<p> .mysql_error(). </p>"; } ?> <?php mysql_close($connection); ?> |
| Re: Why Is My Code Not Working by ford705(op): 12:11pm On Jul 30, 2011 |
This is the HTML <?php //1. create a database connection $connection = mysql_connect("localhost", "root", "" ;if (!$connection) { die("Database connection failed:" . mysql_error()); } //2. Select a database to use $db_select = mysql_select_db("ectforu",$connection); if (!$db_select) { die("Database Selection failed: " . mysql_error()); } ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <style> #container{ margin: 0 auto; width: 800px; height:800px; background-color:#CF9; } h1{ text-shadow:#333; text-align:center; } p{ /*padding-left: 300px;*/ text-align:center; } </style> </head> <body> <br> <div id="container"> <h1>ECT final year forum</h1> <h1>Insert Your Details Accordingly</h1> <form action="insert.php" method="post" > <p><label for="textfield">Surname </label> <input type="text" name="surname" id="surname"> </p> <p> <label for="textfield2">OtherNames</label> <input type="text" name="othernames" id="othernames"> </p> <p> <label for="textfield2">Sex </label> <input type="text" name="sex" id="sex"> </p> <p> <label for="textfield2">Phone </label> <input type="text" name="phone" id="phone"> </p> <p> <label for="textfield2">Contact Address</label> <input type="text" name="contactadd" id="contactadd"> </p> <p> <label for="textfield2">Email Address </label> <input type="text" name="emailadd" id="emailadd"> </p> <p> <label for="textfield2">Birthday </label> <input type="text" name="birthday" id="birthday"> </p> <p> <textarea name="philosophy" cols="35" rows="7">Philosophy in Life</textarea> </p> <p> <textarea name="worstday" cols="35" rows="7">Worst Day in School</textarea> </p> <p> <input name="Click to Submit" type="button" value="submit"></p> </form> </div> </body> </html> <?php mysql_close($connection); ?> |
| Re: Why Is My Code Not Working by Nobody: 12:20pm On Jul 30, 2011 |
This your code - she is too long. You should also post error message, so we know where to start looking. |
| Re: Why Is My Code Not Working by yawatide(f): 12:25pm On Jul 30, 2011 |
DHTML, you beat me to it. OP, you need to tell us the exact problem. Having said that, I do see other (security) issues: 1) Use REQUEST, as opposed to POST 2) Don't use DIE in your code Also: 1) I see stuff like this: {$phone}. Not to say it won't work but I have never seen it coded like this 2) You need to work on your HTML and CSS Post your error |
| Re: Why Is My Code Not Working by DualCore1: 12:31pm On Jul 30, 2011 |
![]() |
| Re: Why Is My Code Not Working by Nobody: 12:56pm On Jul 30, 2011 |
@dualcore, what is the meaning of all that? you just spaced out like that yakata?? |
| Re: Why Is My Code Not Working by dellnet: 1:24pm On Jul 30, 2011 |
I see <input name="Click to Submit" type="button" value="submit"> change to <input name="Click to Submit" type="submit" value="submit"> see if you get anywhere. |
| Re: Why Is My Code Not Working by ford705(op): 2:50pm On Jul 30, 2011 |
Thanks a lot dell_net, to others, dont laugh at a beginner encourage Him to be the best |
| Re: Why Is My Code Not Working by Nobody: 3:21pm On Jul 30, 2011 |
Nobody is laughing at him. It is just that i was trying to teach him to be clear in asking questions. If he has said that the form is not submitting, it would have helped us a lot. Than it is not working. You must try to clarify the problem, because it is not everyone that has time to read all the posted codes. |
| Re: Why Is My Code Not Working by DualCore1: 4:18pm On Jul 30, 2011 |
ford705:This couldn't have been more disappointing. |
| Re: Why Is My Code Not Working by ford705(op): 5:21pm On Jul 30, 2011 |
ddual core: what is disapointing? Istead of telling a brother what to do, you were having fun |
| Re: Why Is My Code Not Working by Nobody: 5:22pm On Jul 30, 2011 |
[size=4pt]*Peeps inside*[/size] |
| Re: Why Is My Code Not Working by ford705(op): 5:38pm On Jul 30, 2011 |
Ok fellas. Another little question How do i restrict access to a particular page using PHP and allowing access from the Login page. Thanks |
| Re: Why Is My Code Not Working by DualCore1: 5:43pm On Jul 30, 2011 |
ford705:Not like I am keen about helping you but for the benefit of all, read up on php session management. Psuedocode //login page if login successful set sessions //other pages if session does not exist redirect to login page using something like header('Location: ?action=login'); or header('Location: login.php'); the redirect page all depends on your coding patterns and if you use php includes. None of these will make sense if you don't spend some 5 minutes reading up on php sessions. Someone will be kind enough to translate this into a full working php code if my psuedocode isnt clear. No one is here to laugh at you, everyone is here to learn and learn we shall. |
| Re: Why Is My Code Not Working by ford705(op): 5:45pm On Jul 30, 2011 |
Thanks! I'm keen on you helping me, lol, |
| Re: Why Is My Code Not Working by Nobody: 5:45pm On Jul 30, 2011 |
You do that by setting a session. money.php - a client that accesses this place directly gets redirected to the login page <?php session_start(); if($_SESSION['user_hash_access']==false) {header("Location: login.php" ;} //login before you chop moneyecho "You have won 1000 million usds"; ?> login.php <?php session_start(); //after your validation routine if($_POST[password]=="correct guy" {$_SESSION['user_hash_access']=true; //now you can the money header("Location:money.php" ; //now you have correct session, so you can login} ?> |
Please I Need A Help In My Code • Again Fellas, What's Wrong With My Code: It Keeps Giving Me The Error Message • Phpmailer Not Working • 2 • 3 • 4
[video] Yvs Image Gallery –sql Injection Tutorial [/video] • Dislike Button Added • Custom Wordpress Theme For Sale
;