PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Dec 16, 2017 3:53 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Jun 14, 2017 12:15 pm 
Offline
Forum Newbie

Joined: Wed Jun 14, 2017 12:07 pm
Posts: 1
I am trying to push the data from this simple html grid into mysql but I can't do it. in the beginning, I got the error that there was no index for the var impressions. I fixed that. when I use just the advertiser value I can push the data into mysql while with the second value, I can't succeed. can you explain me what I am doing wrong? here you can find my html code and as well the query i used to create the db. sorry if the questions is dumb, just a beginner


<?php

include_once 'con_ui.php';
if(isset($_POST['btn-save']))
{

$advertiser = $_POST["advertiser"];
$impressions = (isset($POST["impressions"])?
$_POST["impressions"]:'');



$sql_query = "INSERT INTO data(adv, imp) VALUES('$advertiser', '$impressions')";
mysql_query($sql_query);

// sql query for inserting data into database

}
?>


<html>
<head>
</head>
<body>
<form method="post">
<table id="myTable" align='center' cellspacing=0 cellpadding=5 border=1>

<tr>
<th>advertiser</th>
<th>impressions</th>
</tr>
<td>

<select name="advertiser" id="advertiser">
<option value="">Select advertiser</option>
<option value = "Brita ">Brita</option>
<option value = "Sammontana">Sammontana</option>
</select>

</td>

<td name= "impressions" id="impressions" >1000000</td>

<td>
<button type="submit" name="btn-save"><strong>SAVE</strong></button>
</td>
</form>
</body>
</html>
---------------------
creating db here:
CREATE DATABASE `shaa` ;
CREATE TABLE `shaa`.`data` (
`user_id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`adv` VARCHAR( 25 ) NOT NULL ,
`imp` INT( 10 ) NOT NULL

) ENGINE = InnoDB;


Top
 Profile  
 
PostPosted: Sun Nov 12, 2017 1:30 am 
Offline
Forum Newbie

Joined: Sun Nov 15, 2015 12:57 pm
Posts: 12
Hopefully you have learned what you need to know by now.

For others running across this post, the OP has pretty much done everything you could possibly do wrong in this code. Problems include using dangerous, obsolete mysql code that has been completely removed from PHP, depending in the name of a button for the script to work instead of checking the REQUEST METHOD, creating variables for nothing, not using prepared statements, putting variables in the query, missing closing table tag, giving a name to a TD tag and expecting it to work like an input tag and submit a value, using a table for non-tabular layout instead of CSS, using deprecated HTML...........


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group