PHP form (mysql database) not working on some computers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swarnpalsingh89
Forum Newbie
Posts: 7
Joined: Tue Jul 07, 2009 4:37 am

PHP form (mysql database) not working on some computers

Post by swarnpalsingh89 »

Hi , ive been struggling with a simple php form that i created , its not working on some computers, it displays a string of variable with their values in the URL, but im using $_POST , and not $_GET , its also working fine on wamp server

please help, here is the code ..


/*<<<<<<<<<<<<<<<<<<<<<<<<<register.php>>>>>>>>>>>>>>>>>>>>>>>>*/

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

if(isset($_POST['submit'])||!empty($_POST['submit']))
{
// MySql data (in case you want to save uploads log)
define('DB_HOST','localhost');
define('DB_USERNAME','xxx');
define('DB_PASSWORD','xxx');
define('DB_DATABASE','xxx');

$username = $_POST['username'];
$password = $_POST['password'];
$name = $_POST['name'];
$address = $_POST['address'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$no_of_people = $_POST['no_of_people'];
$name_people = $_POST['name_people'];

$link = @mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD);
if (!$link) {
$errors[] = "Could not connect to mysql.";
break;
}
$res = @mysql_select_db(DB_DATABASE, $link);
if (!$res) {
$errors[] = "Could not select database.";
break;
}

$sql = "insert into mailer (username,password,name,address,email,phone) values ('$username','$password','$name','$address','$email','$phone')";
$res = @mysql_query($sql);
if (!$res) {
$errors[] = "Could not run query.";
break;
}
@mysql_free_result($res);
@mysql_close($link);
}

?>







/*<<<<<<<<<<<<<<<<FORM>>>>>>>>>>>>>>>>>>>>*/

<?php if(!isset($_POST['submit'])||empty($_POST['submit']))
{?>
<p>
<form "method="post" name="myform" action="register.php">
<table width="94%" border="0" align="center" cellpadding="3" cellspacing="0">

<tr>
<td align="left" valign="top" class="lfthdr2">Username:</td>
</tr>
<tr>
<td align="left" valign="top"><input name="username" type="text" class="lbox2" id="name" /></td>
</tr>
<tr>
<td align="left" valign="top" class="lfthdr2">Set Password:</td>
</tr>
<tr>
<td align="left" valign="top"><input name="password" type="password" class="lbox2" id="name" /></td>
</tr>
<tr>
<td align="left" valign="top" class="lfthdr2"> Name:</td>
</tr>
<tr>
<td align="left" valign="top"><input name="name" type="text" class="lbox2" id="name" /></td>
</tr>
<tr>
<td align="left" valign="top" class="lfthdr2"> Address:</td>
</tr>
<tr>
<td align="left" valign="top"><textarea name="address" class="lbox3"></textarea></td>
</tr>
<tr>
<td align="left" valign="top" class="lfthdr2"> Email id:</td>
</tr>
<tr>
<td align="left" valign="top"><input name="email" type="text" class="lbox2" id="email"/></td>
</tr>
<tr>
<td align="left" valign="top" class="lfthdr2"> Phone:</td>
</tr>
<tr>
<td align="left" valign="top"><input name="phone" type="text" class="lbox2" id="email"/></td>
</tr>
<tr>
<td align="center" valign="top" class="login"><input name="reset" type="reset" class="linkbutton" value="Reset" />
&nbsp;&nbsp; I &nbsp;&nbsp;<a href="#" class="login"> </a>
<input name="submit" type="submit" class="linkbutton" id="submit" value="Submit" /></td>
</tr>
</table>
</form>



<?php } else echo"Congratulations we have sucessfully registered you !! "?>
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

Re: PHP form (mysql database) not working on some computers

Post by iijb »

Hi,
Try this

Code: Select all

if(!$_POST)


instead of

Code: Select all

if(!isset($_POST['submit'])||empty($_POST['submit']))
Regards
iijb
swarnpalsingh89
Forum Newbie
Posts: 7
Joined: Tue Jul 07, 2009 4:37 am

Re: PHP form (mysql database) not working on some computers

Post by swarnpalsingh89 »

nope it did'nt help !!!,
:(,

im not sure why is it not working on only some computers..
swarnpalsingh89
Forum Newbie
Posts: 7
Joined: Tue Jul 07, 2009 4:37 am

Re: PHP form (mysql database) not working on some computers

Post by swarnpalsingh89 »

i tried changing "$_POST" to "$_REQUEST", now its submitting but the result is not going to my database ........... :(
amargharat
Forum Commoner
Posts: 82
Joined: Wed Sep 16, 2009 2:43 am
Location: Mumbai, India
Contact:

Re: PHP form (mysql database) not working on some computers

Post by amargharat »

$res = @mysql_query($sql);

change above line as follows to check any error its giving.

$res = mysql_query($sql) or die(mysql_error());
swarnpalsingh89
Forum Newbie
Posts: 7
Joined: Tue Jul 07, 2009 4:37 am

Re: PHP form (mysql database) not working on some computers

Post by swarnpalsingh89 »

i'll do it the first thing when i get to my friends place tomorrow , cos its on his computer and some others the form is not working
Post Reply