I need a little help with a sniplet of code as im very new to PHP development

Ok since posting my last post i put the below 2 lines of code in as i was getting the errors listed above in my last post.

$con = mysql_connect(localhost,username,password); $db = mysql_select_db(databasename);

I put those 2 lines of code above the below line of code, and the errors went but it still not updating the table in the database.

$rs1 = mysql_query("update wp_mngl_custom_field_values set value='".$user."@domain.com' where userid=".$userid);

Ops! we was posting at the same time lol great minds think alike. Did you want me to post the entire file in here so you can see where i am going wrong?

Here is the full file of code.

[php]

<?php include("./xmlapi.php"); //XMLAPI cpanel client class // Default whm/cpanel account info $ip = "localhost"; // should be WHM ip address $account = "username"; // cpanel user account name $passwd ="password"; // cpanel user password $port =2083; // cpanel secure authentication port unsecure port# 2082 $email_domain = 'domain.com'; // email domain (usually same as cPanel domain) $email_quota = 10; // default amount of space in megabytes /*************End of Setting***********************/ $userinput = $_POST['user']; $user = array('user', 'admin', 'administrator', 'shit', 'fucker', 'marketing', 'sales', 'newsletter', 'shit', 'bollox', 'dean', 'deanjackson', 'dean.jackson', 'jasper', 'jasper.jackson', 'service', 'services', 'cunt'); if (in_array($userinput, $user, true)) { echo '
Sorry you are using a banned username
'; } else { function getVar($name, $def = '') { if (isset($_REQUEST[$name])) return $_REQUEST[$name]; else return $def; } // check if overrides passed $email_user = getVar('user', ''); $email_pass = getVar('pass', $passwd); $email_vpass = getVar('vpass', $vpasswd); $email_domain = getVar('domain', $email_domain); $email_quota = getVar('quota', $email_quota); $msg = ''; if (!empty($email_user)) while(true) { if ($email_pass !== $email_vpass){ //check password $msg = '
Email password does not match'; break; } $xmlapi = new xmlapi($ip); $xmlapi->set_port($port); //set port number. cpanel client class allow you to access WHM as well using WHM port. $xmlapi->password_auth($account, $passwd); // authorization with password. not as secure as hash. // cpanel email addpop function Parameters $call = array(domain=>$email_domain, email=>$email_user, password=>$email_pass, quota=>$email_quota); $xmlapi->set_debug(0); //output to error file set to 1 to see error_log. $result = $xmlapi->api2_query($account, "Email", "addpop", $call ); // making call to cpanel api //for debugging purposes. uncomment to see output //echo 'Result\n
';
//print_r($result);  
//echo '
'; if ($result->data->result == 1){ $msg = $email_user.'@'.$email_domain.' account created'; $con = mysql_connect(localhost,username,password); $db = mysql_select_db(databasename); $rs1 = mysql_query("update wp_mngl_custom_field_values set value='".$user."@domain.com' where userid=".$userid); } else { $msg = $result->data->reason; break; } break; } ?> <?php echo '
'.$msg.'
'; ?> <?php $con = mysql_connect(localhost,username,password); $db = mysql_select_db(database); $rs = mysql_query("select * from wp_mngl_custom_field_values"); if(mysql_num_rows($rs)>0) { $row = mysql_fetch_assoc($rs); if($row['value']=='') { ?>
Username: @myebox.info
Password:
Verify Password:

<?php } else // display the css div with message { ?>
Sorry, you already have reached your quota for this account. Due to high demand for the service we carnt issue you with another mailbox on this account at this stage. From our records we can see you have already registered <?= $row['value']; ?> on <?= $row['created_at']; ?>. <?php } } else echo 'Failed to retrieve records'; } ?>[/php]

See if you can see where i am going wrong! :smiley:

i found two problems in the line below.

$rs1 = mysql_query(“update wp_mngl_custom_field_values set value=’”.$userinput."@domain.com’ where userid=".$userid);

1st is that the user input is stored in the variable $userinput not in $user. i changed it.

2nd is that the user id $userid doesnt hold any value. i gave it as sample so that i thought u would change it accordingly…

in place of $userid u should use the variable that holds the record unique id.

hope it makes sense.

Another error now lol and that is

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /home/user/public_html/portal/dir/index.php on line 97 Failed to retrieve records

And line 97 in the file i have this end is

if(mysql_num_rows($rs)>0)

lol…

first tell me if the previous problem is fixed or not?

and is this all new error? :slight_smile:

okie, that error means, there is something wrong with this line

$rs = mysql_query(“select * from wp_mngl_custom_field_values”);

check the table name if it has any spell mistakes or something…

This is what i have in that bit of the file and all the correct usernames and password datbase names and table names.

[php]<?php

$con = mysql_connect(localhost,username,password);
$db = mysql_select_db(databasename);
$rs = mysql_query(“select * from tablename”)

if(mysql_num_rows($rs)>0)
{
$row = mysql_fetch_assoc($rs);
if($row[‘value’]==’’)
{ ?>

Username: @myebox.info
Password:
Verify Password:

<?php } else // display the css div with message { ?>
Sorry, you already have reached your quota for this account. Due to high demand for the service we carnt issue you with another mailbox on this account at this stage. From our records we can see you have already registered <?= $row['value']; ?> on <?= $row['created_at']; ?>. <?php } } else echo 'Failed to retrieve records'; } ?> [/php]

And when i upload that file to the server it returns the below error.

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /home/user/public_html/portal/dir/index.php on line 97 Failed to retrieve records

Just doubled checked all the usernames passwords, database and table names etc and they are all present and correct. But its still coming up with an error of:

Parse error: syntax error, unexpected T_IF in /home/user/public_html/portal/dir/index.php on line 97

And line 97 is…

if(mysql_num_rows($rs)>0)

Should there be and curly thingys in between this line

$rs = mysql_query("select * from wp_mngl_custom_field_values")

and this line?

if(mysql_num_rows($rs)>0)

u didnt give me what is there in line 96 i wonder !!

i guess u r missing a semi colon ‘;’ in line 96 at the end.

check it…

Well its line 97 the error is on i changed

if(mysql_num_rows($rs)>0)

with

if(mysql_num_rows($rs)>0);

And i still have that error coming up

Parse error: syntax error, unexpected T_IF in /home/user/public_html/dir/dir/index.php on line 97

it may also be worth pointing out that the below code (line 95) has no ; on the end of it

Should it be like this?

$rs = mysql_query("select * from wp_mngl_custom_field_values")

Or?

$rs = mysql_query("select * from wp_mngl_custom_field_values");

it should be like this

$rs = mysql_query(“select * from wp_mngl_custom_field_values”);

this line should have semicolon at the end. assuming that this is the line which is before that line 97 (if condition line)

and line 97 should not have semi colon coz, it is ‘if condition’

Ok the error has now vanished :-* lol

But it still isnt posting this line

$rs1 = mysql_query("update wp_mngl_custom_field_values set value='".$userinput."@domain.com' where userid=".$userid);

into the table of the database upon submission of the form.

Just so you know there are no errors when you land on the page or when its submitted its just the line below

$rs1 = mysql_query("update wp_mngl_custom_field_values set value='".$userinput."@domain.com' where userid=".$userid);

Doesnt seam to be processing into the ‘value’ feild of table wp_mngl_custom_field_values

Are you sure that its ment to be

$rs1 = mysql_query(“update wp_mngl_custom_field_values set value=’”.$userinput."@domain.com’ where userid=".$userid);

As i think it may well be

$rs1 = mysql_query(“update wp_mngl_custom_field_values set value=’”.$email_user."@domain.com’ where userid=".$userid);

Let me know, see what you think? ::slight_smile: ???

hey, its night here… thats why the delay in my reply :slight_smile:

yeah… i think second one is okie, coz, the user mail is stored in $email_user. but the problem is with the variable ‘$userid’ at the end of the statament. when i gave u this line, i assumed that there would be a variable ‘$userid’ and there is no such variable in ur code. So, i guess u have to replace ‘$userid’ with the variable that stores unique Id of that record.

anyway, give me the whole page code and database table structure (no need of database password, just the table fields list), i will finish it off for u.

Ok here below is an export from phpmyadmin of the table in the database in question

[code]-- phpMyAdmin SQL Dump
– version 3.3.9
http://www.phpmyadmin.net

– Host: localhost
– Generation Time: Feb 19, 2011 at 06:18 AM
– Server version: 5.1.54
– PHP Version: 5.2.6

SET SQL_MODE=“NO_AUTO_VALUE_ON_ZERO”;

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/
!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/
!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/
!40101 SET NAMES utf8 */;


– Database: dbusername_wp2



– Table structure for table wp_mngl_custom_field_values

CREATE TABLE IF NOT EXISTS wp_mngl_custom_field_values (
id int(11) NOT NULL AUTO_INCREMENT,
field_id int(11) NOT NULL,
user_id int(11) NOT NULL,
value varchar(255) NOT NULL,
created_at datetime NOT NULL,
PRIMARY KEY (id),
KEY field_id (field_id),
KEY user_id (user_id),
KEY created_at (created_at)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;


– Dumping data for table wp_mngl_custom_field_values

INSERT INTO wp_mngl_custom_field_values (id, field_id, user_id, value, created_at) VALUES
(1, 1, 1, ‘’, ‘2011-02-16 09:23:03’),
(3, 2, 1, ‘’, ‘2011-02-16 10:43:00’);[/code]

So that should help you understand ezactly what is in the table of the database.

If you look at this part of the table code above

take this line for example

(1, 1, 1, '', '2011-02-16 09:23:03'),

I want the form to make it so it submits the value of username entered @domain.com so in effect when you look at the table after submission it would look like this.

(1, 1, 1, '[email protected]', '2011-02-16 09:23:03'),

Hope this helps. :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service