|
MT
|
dEAR Gurus,
I just installed mysql, Php and Apache into my system using WAMP CD. I just started learning PHP and Mysql. I was just trying to add 3 fields in my html (namely name , address and Sex)into Mysql database. After running the program, I went to check mysql if those items were actually added, but it was actually added with everything blank out ie. the table in the database increased in row, but there's nothing inside despite filling out the forms in my html.
I have been on this for the past 3 days and couldnt figure out the problem. I'm getting so discouraged now, please help ,
I have this code in my PHP :
<?php $conn = mysql_connect("localhost", "root","") or die("unable to connect first phase"); mysql_select_db("england",$conn) or die("select error"); $nko = "insert into uk(name,address,sex) values('$oruko','$addr','$se')"; mysql_query($nko) or die (mysql_error()); echo "ADDED"; ?>
This in my html Code <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>, Latest, </title> </head>
<body> <center> <b> <font color="blue">This Is My Experiment, </font></b> </center>
<form id="form1" name="form1" method="post" action="wapa.php"> <p> <table width="500" border="0" cellpadding="1"> <tr> <td width="70">Name : </td> <td width="48"><input type = "text" name = "oruko" /></td> </tr> <tr> <td>Address :</td> <td><input type = "text" name = "addr" /></td> </tr> <tr> <td>Sex :</td> <td><input type = "text" name = "se" size = "3"/></td> </tr> <tr> <td></td> <td><input type = "submit" value = "OLUGBON" name = "submit" /> </table>
</p> <p> <label>I hope u will love this, </label> </p> </form> <p> </p> </body>
</html>
|
|
|
|
|
|
Cactus (m)
|
u wrote
$nko = "insert into uk(name,address,sex) values('$oruko','$addr','$se')";
it ought to be
$nko = "insert into uk(name,address,sex) values($oruko,$addr,$se)";
|
|
|
|
|
|
MT
|
Still not working 
|
|
|
|
|
|
Cactus (m)
|
and hope u named the file for the php script wapa.php
|
|
|
|
|
|
IronFist (m)
|
could you put up your wapa.php code. I believe wapa.php should handle your query. try instantiating the html form variables first in your wapa.php e.g. <? $oruko = $_POST["oruko"]; $addr = $_POST["addr"]; $se = $_POST["sex"]; ?> then your mysql query can then follow to handle your form.
|
|
|
|
|
|
smartsoft (m)
|
Wapa.php ==================================================================================== <? php
include ("dbinfo.php"); //Declare your variables man ! dude
$name = addslashes($_POST['name']); $address = addslashes($_POST['address']); $sex = addslashes($_POST['sex']);
// if i hit the submit button, it should insert my records if($wapa){ $sql = " INSERT INTO uk (name,address,sex)VALUES("$name", "$address", "$sex")"; echo " Your information inserted successfully"; }else { echo " Sorry you entry can not be registerd at this time "; } ?>
db.php ===================================================================================== Copy into your db information i mean in a notepad and save it as dbinfo.php change the details oo
<?php
$database = "dbname"; $host = " localhost"; $username = "smartsoft"; $password = " nairaland";
$conn = mysql_connect ("locahost", "root", "")or die ("cannot connect at this time"); $db = mysql_select_db ("dbname",$conn)or die (mysql_error()); ?>
Note : remember that i don't need to put my password because i'm using XAMPPS, it's when i want to upload i can now put in my password.
=====================================================================================
I didn't test it ooo just try and test it, any problem just let me know i will fix and it will work got to run to church now see ya.
Hey is (uk) your table or Database huh ? Check that well ooooooo
|
|
|
|
|
|
MT
|
@ironfist Thanks. It worked. It got submitted into the database. However, I need to get cleared. Is it anytime I try to submit a form that I have to instantiate the variable form or is it peculiar to my example alone. I asked this question because the textbook that I followed word for word didnt even ask me to instantiate. please get me clarified on this. @All Thanks for being your brother's keeper. One day u will be remembered when i create a webiste more powerful than nairaland 
|
|
|
|
|
|
opensource (m)
|
you can also try place it in a if {} statement , then go for customs errors will help you will building more complex application , Also you need to do Object oriented programming and have security in mind when coding .
Always have a file called "conect.php" which makes the db connection placed somewhere else on the host
the reuse it by call
require_once('conect.php');
register then the sections and continue
well that complex , its really a good start we were ones there
|
|
|
|
|
|
Ka (m)
|
Is it anytime I try to submit a form that I have to instantiate the variable form or is it peculiar to my example alone. I asked this question because the textbook that I followed word for word didnt even ask me to instantiate. As you probably know, when you send the information in a form to a script (like wapa.php in your case), the values that have been entered or selected in each of the form elements are sent in a $_POST array. Again, in your case, people would have entered a value in your oruko, addr and se text fields. These values will be put in the $_POST array. So if you want to insert these values that have been entered into your database, you have to first get them from the $_POST array, and that's what IronFist was doing when he wrote this: $oruko = $_POST["oruko"]; $addr = $_POST["addr"]; $se = $_POST["sex"]; In other words, he declared variables to hold the values entered into these form elements, and then used the values that were now in these variables in the query. Of course, you could just write a query like this: $nko = "insert into uk(name,address,sex) values($_POST["oruko"],$_POST["addr"],$_POST["se"])";
but I think this wouldn't be very readable.
|
|
|
|
|
|
bakenda (m)
|
@MT (and others who can be of help).
I'm hearing about the WAMP Cd for the first time here. Ive been looking for something like that. I used to test run my codes directly on the server, I downloaded the WINLAMP package but there was download error. How can I get a copy of the WAMP Cd? Thanks.
|
|
|
|
|
|
opensource (m)
|
get easyPhp its better and good
if you need i can assist but don't flood me with pm just post here i will upload to an FTP
|
|
|
|
|
|
bakenda (m)
|
@opensource OK.I need,can you just supply the download URL. Thanks
|
|
|
|
|
|
|
|
cheavroi (m)
|
Kindly help me with this code ,problem is its not returning any value and the databse is well set up.if i don't put a where clause it works but once i put the where clause it doesnt return a value html code is
<form name="form2" method="post" action="parishlist3.php"> <select name="parish"> <option>ABARANJE </option> <option>ABORU</option> <option>AJEGUNLE</option> <option>ALAGBADO</option> <option>ALAPERE</option> <option>AMAZING GRACE</option> <option>IKOTUN</option> <option>KETU</option> <option>MAFOLUKU</option> <option>OWODE-ELEDE</option> <option>OWORONSOKI</option> <option>GREAT GRACE</option> <option>LEKKI</option> <option>IJERE</option> <option>ORIGANRIGAN</option> </select> <input type="submit" name="Submit2" value="Submit"> </form>
and the php code is
<?php // Connects to your Database mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("upperroo_parishes") or die(mysql_error()); $data = "SELECT * FROM address WHERE name ='$parish'" or die(mysql_error()); Print "<table border cellpadding=3>"; while($info = mysql_fetch_array( $data )) { Print "<tr>"; Print "<th>Name:</th> <td>".$info['Name'] . "</td> "; Print "<th>Address:</th> <td>".$info['Address'] . " </td></tr>"; Print "<th>Pastor-In-Charge:</th> <td>".$info['Head'] . "</td> "; Print "<th>Phone No:</th> <td>".$info['Contact'] . " </td></tr>"; } Print "</table>"; ?>
|
|
|
|
|
|
segebee (m)
|
$data = "SELECT * FROM address WHERE name ='$parish'"
remove the '' around parish and try it '' converts variable to value and u have 2 already plus d one at the beginning
|
|
|
|
|
|
xanadu
|
$data = "SELECT * FROM address WHERE name ='$parish'" The issue here is: You MUST declare your variables. $parish has no value, because you have not declared it as a variable containing the user's selection - so your query simply is saying 'where $parish =NOTHING'. Put this code above your select statement: $parish=$_POST['parish'];That should work now, because you have basically said: '$parish now contains whatever the user selected'. Hope it works out for you. Nb: Nothing wrong with your select statement - the apostrophes are in order. Just declare the $parish variable as above.
|
|
|
|
|
|
cheavroi (m)
|
Hi thanks for ur assistance but its still returning an error on
while($info = mysql_fetch_array( $data ))
any idea!
|
|
|
|
|
|
xanadu
|
no worries - can u paste the actual error thrown up on your screen? Also, did u change the select statement from the one in your earlier post?
|
|
|
|
|
|
cheavroi (m)
|
thats is the error receieved : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/upperroo/public_html/parishlist2.php on line 123
and on checking line 123,it contains
while($info = mysql_fetch_array( $data ))
still beats me thanks
|
|
|
|
|
|
xanadu
|
Right, thanks for posting the error. Go back to your select statement, and change: $data = "SELECT * FROM address WHERE name ='$parish'" or die(mysql_error()); to: $data = mysql_query("SELECT * FROM address WHERE name ='$parish'") or die(mysql_error()); That should fix it - goodluck!
|
|
|
|
|
|
ade2kay (m)
|
That still won't work. The $parish variable still won't work 'because the variable won't be substituted.
use
$data = mysql_query("SELECT * FROM address WHERE name ='{$_POST['parish']}'") or die(mysql_error());
instead of
$data = mysql_query("SELECT * FROM address WHERE name ='$parish'") or die(mysql_error());
that way, u won't need the $parish variable again and your code will work fine.
That error is too small to spend days on.
Hope this helps
|
|
|
|
|
|
|
|
cheavroi (m)
|
hi guys it worked like mad.I'm very greatful for u guys assistance.can u give me a link where i can get to read php tutorials online.
|
|
|
|
|
|
ade2kay (m)
|
 Congrats, and keep practising. But i want to know which code worked, because there were many suggestions.
|
|
|
|
|
|
cheavroi (m)
|
Ade,unfortuntately i didnt use ur suggestion,i just edited it as suggested by xandu but i quite appreciate ur contirbution infact i have it written out and put in my collection of php scripts thou rite now i want to include polls on my web page and looking for the material .thanks a lot guys
|
|
|
|
|
|
cheavroi (m)
|
Hi guys,ive got this little challenge again.i created an online poll on my site.ive got two challenges,i want the form for voting to open on a small window while the main page i e the index page remains there ,a thing i want to look into later but right now when I'm running the scripts for the view results page,it returns an error
warning:division by zero on line 59,62,65.any way out.thanks
|
|
|
|
|
|
smartsoft (m)
|
still looking for solutions ?
|
|
|
|
|
|
cheavroi (m)
|
yeah any idea
|
|
|
|
|
|
jitguide
|
can i see your code
Think World class Think Teng pro
|
|
|
|
|
|
cheavroi (m)
|
here is the code,it is for viewing the results of the polls
<?PHP $question = ''; $answerA = ''; $answerB = ''; $answerC = '';
$imgTagA = ''; $imgWidthA = '0';
$imgTagB = ''; $imgWidthB = '0';
$imgTagC = ''; $imgWidthC = '0';
$imgHeight = '10'; $totalP = ''; $percentA = ''; $percentB = ''; $percentC = '';
$qA = ''; $qB = ''; $qC = '';
if (isset($_GET['Submit2'])) {
$qNum = $_GET['h1'];
$user_name = "upperroo_users"; $password = "preacher"; $database = "upperroo_surveytest"; $server = "localhost";
$db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "SELECT * FROM tblquestions, answers WHERE tblquestions.QID = answers.QID AND answers.QID = '$qNum'"; $result = mysql_query($SQL); $db_field = mysql_fetch_assoc($result);
$question = $db_field['Question']; $answerA = $db_field['A']; $answerB = $db_field['B']; $answerC = $db_field['C'];
$qA = $db_field['qA']; $qB = $db_field['qB']; $qC = $db_field['qC'];
$imgWidthA = $answerA; $imgWidthB = $answerB; $imgWidthC = $answerC;
$totalP = $answerA + $answerB + $answerC;
$percentA = (($answerA * 100) / $totalP); $percentA = floor($percentA);
$percentB = (($answerB * 100) / $totalP); $percentB = floor($percentB);
$percentC = (($answerC * 100) / $totalP); $percentC = floor($percentC);
$imgWidthA = $percentA * 2; $imgWidthB = $percentB * 2; $imgWidthC = $percentC * 2;
$imgTagA = "<IMG SRC = 'red.jpg' Height = " . $imgHeight . " WIDTH = " . $imgWidthA. ">"; $imgTagB = "<IMG SRC = 'red.jpg' Height = " . $imgHeight . " WIDTH = " . $imgWidthB . ">"; $imgTagC = "<IMG SRC = 'red.jpg' Height = " . $imgHeight . " WIDTH = " . $imgWidthC . ">";
mysql_close($db_handle);
} else { print "database error"; }
} else { print "no results to display"; } ?>
|
|
|
|
|
|
cheavroi (m)
|
Hi found the solution,it was in the way the database was created.thanks for all your contributions
|
|
|
|
|
|
cdeveloper (m)
|
You seem to forget that you are using post as the method of your post and as such you must have to capture the variables at the server like this
$sex=$_POST['sex']; $var2=$_POST['var2']; $var3=$_POST['var3'];
then you clean it for safe storage like this
$sex=strip_tags(trim($sex)); $var2=strip_tags(trim($var2)); $var3=strip_tags(trim($var3));
then you are on your way to storing it in the database
|
|
|
|
|
|