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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
silencer07
Forum Newbie
Posts: 2
Joined: Fri Aug 22, 2008 12:46 am

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

Post by silencer07 »

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

Code: Select all

 
<!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>
&nbsp;<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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="btn_Register" type="submit" value="Register Now" />
</body>
<label id="Label1"><?= $notification ?></label>
</html>
 
 
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

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

Post by Apollo »

What does mysql_error() say?

Code: Select all

mysql_query("INSERT INTO `pizzarific`.`account`(`account_id`,etc..
Exactly what is your table's name, and what is the first column you're inserting?
silencer07
Forum Newbie
Posts: 2
Joined: Fri Aug 22, 2008 12:46 am

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

Post by silencer07 »

sorry for being moronic but i found out that 'telno' column is 'tel_no'. thanks by the way. the error by the way is "unkown column telno" and when i checked it up it was supposed to be 'tel_no'
Post Reply