Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,740 members, 7,817,042 topics. Date: Saturday, 04 May 2024 at 12:35 AM

Php/mysql Programmers, Please Help Me Out ! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Php/mysql Programmers, Please Help Me Out ! (1974 Views)

Programmers. Please Explain To Me The Concepts Of API. / How To Make a DESKTOP Executable Software Using PHP,MYSQL,SQLITE / programmers Please Help A Friend on visual basic. (2) (3) (4)

(1) (Reply) (Go Down)

Php/mysql Programmers, Please Help Me Out ! by MT: 10:59pm On Jul 20, 2007
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",""wink or die("unable to connect first phase"wink;
mysql_select_db("england",$conn) or die("select error"wink;
$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>&nbsp;</p>
</body>

</html>
Re: Php/mysql Programmers, Please Help Me Out ! by Cactus(m): 5:18am On Jul 21, 2007
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)";
Re: Php/mysql Programmers, Please Help Me Out ! by MT: 3:39pm On Jul 21, 2007
Still not working angry
Re: Php/mysql Programmers, Please Help Me Out ! by Cactus(m): 4:46pm On Jul 21, 2007
and hope u named the file for the php script wapa.php
Re: Php/mysql Programmers, Please Help Me Out ! by IronFist(m): 4:47pm On Jul 21, 2007
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.
Re: Php/mysql Programmers, Please Help Me Out ! by smartsoft(m): 5:05pm On Jul 21, 2007
Wapa.php
====================================================================================
<? php

include ("dbinfo.php"wink;
//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"wink";
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", ""winkor die ("cannot connect at this time"wink;
$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
Re: Php/mysql Programmers, Please Help Me Out ! by MT: 7:28pm On Jul 21, 2007
@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 cos the textbook that I followed word for word didnt even ask me to instantiate.

Pls 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 cheesy
Re: Php/mysql Programmers, Please Help Me Out ! by opensource(m): 12:08am On Aug 05, 2007
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
Re: Php/mysql Programmers, Please Help Me Out ! by Ka: 2:03pm On Aug 05, 2007
MT: 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.
Re: Php/mysql Programmers, Please Help Me Out ! by bakenda(m): 6:20pm On Aug 06, 2007
@MT (and others who can be of help).

Im 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.
Re: Php/mysql Programmers, Please Help Me Out ! by opensource(m): 11:18pm On Aug 06, 2007
get easyPhp its better and good

if you need i can assist but dont flood me with pm just post here i will upload to an FTP
Re: Php/mysql Programmers, Please Help Me Out ! by bakenda(m): 5:55pm On Aug 09, 2007
@opensource
OK.I need,can you just supply the download URL.
Thanks
Re: Php/mysql Programmers, Please Help Me Out ! by krs1(m): 8:23pm On Aug 17, 2007
@ bakenda
Here is the link to a free download of WAMP

http://www.wampserver.com/en/download.php

enjoy!
Re: Php/mysql Programmers, Please Help Me Out ! by cheavroi(m): 12:46pm On Aug 22, 2007
Kindly help me with this code ,problem is its not returning any value and the databse is well set up.if i dont 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"wink or die(mysql_error());
mysql_select_db("upperroo_parishes"wink 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>";
?>
Re: Php/mysql Programmers, Please Help Me Out ! by segebee(m): 4:14pm On Aug 22, 2007
$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
Re: Php/mysql Programmers, Please Help Me Out ! by xanadu: 5:14pm On Aug 22, 2007
$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.
Re: Php/mysql Programmers, Please Help Me Out ! by cheavroi(m): 12:21pm On Aug 24, 2007
Hi thanks for ur assistance but its still returning an error on

while($info = mysql_fetch_array( $data ))

any idea!
Re: Php/mysql Programmers, Please Help Me Out ! by xanadu: 7:52pm On Aug 25, 2007
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?
Re: Php/mysql Programmers, Please Help Me Out ! by cheavroi(m): 10:30am On Aug 27, 2007
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
Re: Php/mysql Programmers, Please Help Me Out ! by xanadu: 12:32am On Aug 28, 2007
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'"wink or die(mysql_error());

That should fix it - goodluck!
Re: Php/mysql Programmers, Please Help Me Out ! by ade2kay(m): 9:35am On Aug 28, 2007
That still won't work.
The $parish variable still won't work 'cos the variable won't be substituted.

use

$data = mysql_query("SELECT * FROM address WHERE name ='{$_POST['parish']}'"wink or die(mysql_error());

instead of

$data = mysql_query("SELECT * FROM address WHERE name ='$parish'"wink 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
Re: Php/mysql Programmers, Please Help Me Out ! by xanadu: 9:55am On Aug 28, 2007
??
Re: Php/mysql Programmers, Please Help Me Out ! by cheavroi(m): 10:16am On Aug 28, 2007
hi guys it worked like mad.im very greatful for u guys assistance.can u give me a link where i can get to read php tutorials online.
Re: Php/mysql Programmers, Please Help Me Out ! by ade2kay(m): 11:47am On Aug 28, 2007
cool Congrats, and keep practising. But i want to know which code worked, cos there were many suggestions.
Re: Php/mysql Programmers, Please Help Me Out ! by cheavroi(m): 1:34pm On Aug 28, 2007
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
Re: Php/mysql Programmers, Please Help Me Out ! by cheavroi(m): 4:18pm On Aug 30, 2007
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 im 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
Re: Php/mysql Programmers, Please Help Me Out ! by smartsoft(m): 8:30pm On Aug 31, 2007
still looking for solutions ?
Re: Php/mysql Programmers, Please Help Me Out ! by cheavroi(m): 12:36pm On Sep 04, 2007
yeah any idea
Re: Php/mysql Programmers, Please Help Me Out ! by jitguide: 3:49pm On Sep 04, 2007
can i see your code



Think World class Think Teng pro
Re: Php/mysql Programmers, Please Help Me Out ! by cheavroi(m): 4:28pm On Sep 04, 2007
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";
}
?>
Re: Php/mysql Programmers, Please Help Me Out ! by cheavroi(m): 10:00am On Sep 07, 2007
Hi found the solution,it was in the way the database was created.thanks for all your contributions
Re: Php/mysql Programmers, Please Help Me Out ! by cdeveloper(m): 4:04pm On Sep 17, 2007
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

(1) (Reply)

Functional Programming. The Future? / PHP Developers, How True Is This Statements. / Do You Want To Be A Java Geek?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 55
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.