Jump to content

can select to mysql but cannot insert even w/ static values


silencer07

Recommended Posts

Can you please scan my code i cannot find where is the culprit of my program. please help me i am working on a deadline and it really costing me ample amount of time.

 

The problem is in line 53,60,73 and 78. thank you

 

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="en-us" http-equiv="Content-Language" />
<link rel="stylesheet" type="text/css" href="3col_leftNav.css">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Register</title>
</head>
<body>
<?php
    if(isset($_POST['btn_Register']))
    {
        require('connection.php');
        $account_id = 'acc-001';
        $notification = '';
        $v = mysql_query("SELECT  account_id from pizzarific.account limit 1");
        $x = mysql_affected_rows();
        if($x > 0)
        {
            $row = mysql_fetch_array($v);
            $temp = $row['account_id'];
            $temp = substr($temp, 4);
            $temp = (int)$temp;
            $temp++;
            $temp = (string)$temp;
            if(strlen($temp) == 1)
                $account_id = 'acc-00' . $temp;
            else if(strlen($temp) == 2)
                $account_id = 'acc-0' . $temp;
            else
                $account_id = 'acc-' . $temp;
        }   
                
        $v = mysql_query("SELECT  * FROM pizzarific.gift_cheque" . 
            " WHERE gift_cheque_code = '". $giftChequeCode ."'");   
        $giftChequeCode = $_POST['txt_GiftCheque'];
        $v = mysql_query("SELECT  * FROM pizzarific.gift_cheque" . 
            " WHERE gift_cheque_code = '". $giftChequeCode ."'");
        $x = mysql_affected_rows();
        
        $name = $_POST['txt_Name']; $address = $_POST['txt_Address'];
        $telno = $_POST['txt_TelNo']; $username = $_POST['txt_UserName'];
        $pass =$_POST['txt_Pass'];
        if($x > 0)
        {
            try {
                $row = mysql_fetch_array($v);
                $amount = $row['gift_cheque_amount'];


//this is the part hat is not working 
                //mysql_query("INSERT INTO `pizzarific`.`account`(`account_id` " . 
                //  ",`name`,`address`,`telno`,`username`,`pass`,`gift_cheque_amount`) VALUES ('"
                    //. $account_id . "','". $name ."','" . $address ."','" 
                    //. $telno ."','" . $username . "','" . $pass ."'," 
                    //. $amount . ");");

//i tried to insert static contents but no luck
                mysql_query("INSERT INTO `pizzarific`.`account`(`account_id`,`name`,`address`,".
                "`telno`,`username`,`pass`,`gift_cheque_amount`) VALUES ('acc-003','marina tingson','manunggal','781-0550','marina','password',0);" );  
            } catch (Exception $e) {
                echo 'Caught exception: ',  $e->getMessage(), "\n";
            }   
            $notification = '<BR/><BR/>Gift Cheque Accepted. Registration Successful. Please Login to your Account Now';
        }
        else
        {
            if(empty($giftChequeCode))
            {

//same as here not working 
                //$v = mysql_query("INSERT INTO `pizzarific`.`account`(`account_id`,`name`,`address`,".
                //"`telno`,`username`,`pass`,`gift_cheque_amount`) VALUES ('" . $account_id . "','" . $name ."','" . 
                //$address ."','" . $telno ."','" . $username . "','" . $pass ."',0);" );   

//again the same as above but not working 
                mysql_query("INSERT INTO `pizzarific`.`account`(`account_id`,`name`,`address`,".
                "`telno`,`username`,`pass`,`gift_cheque_amount`) VALUES ('acc-003','marina tingson','manunggal','781-0550','marina','password',0);" );          
                }
            else 
                $notification = '<BR/><BR/>Invalid Gift Cheque Code';
        }
    }
    
?>
<form  id="form1" method="post" target="content">
<label id="Label" >Register Now<br />
  </label>
 <table style="width: 550px; height: 85px">
    <tr>
        <td style="width: 189px">Username:</td>
        <td style="width: 216px"><input name="txt_UserName" value="<?= $username ?>" type="text" style="height: 20px; width: 128px" /></td>
        <td style="width: 119px">Password:</td>
        <td><input name="txt_Pass" type="password" value="<?= $password ?>" style="height: 20px; width: 128px" /></td>
    </tr>
    <tr>
        <td style="width: 189px; height: 23px;">Name:</td>
        <td style="width: 216px; height: 23px"><input name="txt_Name" value="<?= $name ?>" type="text" style="height: 20px; width: 128px" /></td>
        <td style="height: 23px; width: 119px;">Address:</td>
        <td style="height: 23px"><input name="txt_Address" value="<?= $address ?>" type="text" style="height: 20px; width: 128px" /></td>
    </tr>
    <tr>
        <td style="width: 189px">Gift Cheque Code:</td>
        <td style="width: 216px"><input name="txt_GiftCheque" value="<?= $giftChequeCode ?>" type="text" style="height: 20px; width: 128px"/>*optional</td>
        <td style="width: 119px">Telephone No</td>
        <td><input name="txt_TelNo" type="text" value="<?= $telno ?>" style="height: 20px; width: 128px" /></td>
    </tr>
</table>
            
            
            
           &nbsp
;         
<input name="btn_Register" type="submit" value="Register Now" />
</body>
<label id="Label1"><?= $notification ?></label>
</html>

Link to comment
Share on other sites

Use this on the end of your query:

 

or die("Error: ".mysql_error());

 

Example:

mysql_query("INSERT INTO `table` (`field`,`field2`) VALUES ('foo','bar')") or die("Error: ".mysql_error());

 

It'll tell you if there is an error in your query. Post the results here if there is any.

Link to comment
Share on other sites

I would say that the problem is in the GRANT tables on your database and the user you are trying to insert the values with, doesn't have permission.

 

I think the syntax is as follows, if not, just google GRANT statement.

 

GRANT ALL PRIVILEGES TO 'mysqluser'@'yourdomain' IDENTIFIED BY 'some password'

 

You also may want to flush the tables after you run this query.

 

Hope you work it out.

Link to comment
Share on other sites

It helps to post your table structure, if your "account_id" column is an auto-inc INT then inserting something like "acc-003" will throw errors, you can't supply too much info when you're asking people to diagnose a problem, the query itself unless blatently obvious in its error is pretty useless for diagnostic purposes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.